Search code examples
phpwordpresscron

How to init WordPress from a cronjob?


I used to initiate WordPress in my cronjobs by calling something like:

$file = dirname(__FILE__);
$file = substr($file,0,stripos($file,"wp-content"));

require($file."/wp-load.php");

But this isn't working anymore. If I use a test script in the same directory, for example:

require($file."/testscript.php");

It executes without a problem. I also have no problem running the script directly. It's only when it's run from the cronjob.

There are no errors being thrown to indicate a permission or path problem.

So what's happening? Is wp-load.php actively failing due to being called from a cronjob?


Solution

  • I was able to trace the issue back to the way I was handling WP login authentication during the init action hook. So, wasn't WordPress' or cronjob's fault.