I have very simple file with one line:
echo file_get_contents( get_template_directory_uri().'/scheduler.php' );
This file is called by cpanel cron using php -q. When I put full link without get_template_directory_uri function everything works fine, with this function cron returns Call to undefined function
When you run things on the CLI (which is pretty much where Cronjob and runwhen jobs are running), then you don’t have access to some things like some server or request variable contents, etc. What you need to do is fire up WP Core. Else you won’t have access to the full WP API.
One method would be to use the wp-cron API from core, but disable WP internal (virtual/fake) Cron system by setting
define( 'DISABLE_WP_CRON', TRUE );
wp-config.php file. Then target [
~/wp-cron.php] directly – where
~ would be your domain. Keep in mind that you might need to set the proper subdomain or subdirectory when you are running things in a Multisite/Network setup.
WordPress loads the whole core from within this file and then runs every defined (virtual) cron job during the real cron job.
Where it won’t work (opening line inside
// No connection to the browser/client needed ignore_user_abort( TRUE ); if ( ! empty( $_POST ) OR defined( 'DOING_AJAX' ) OR defined( 'DOING_CRON' ) ) die();
Because you need to load WordPress first!