1

If I set DISABLE_WP_CRON to true in my wp-config.php file, then will it block plugins from registering new cron events (eg with calls to wp_schedule_event())

define( 'DISABLE_WP_CRON', true );

I've added the above line to my wp-config.php. I think the general assumption is that DISABLE_WP_CRON doesn't actually block your cron jobs from running (and block plugins from registering new events), but that it just prevents wordpress itself from initiating your crons when a visitor loads your website in their web browser.

And, instead, you can just set DISABLE_WP_CRON to true and then execute your cron jobs outside of the web server (eg with wp-cli and the actual, system cron).

Is this assumption valid? Or does DISABLE_WP_CRON actually block crons from running, and block plugins from registering new cron events?

I ask because I'm writing a plugin that tries to register a new cron event with wp_schedule_event(). The function returns True, but the new cron job does not appear in my event list, so I don't think it will ever be executed by my system's cron.

wp cron event list

How can I prevent wordpress from executing its own cron via the webserver when my visitors load the website through their web browsers, but still permit [a] crons to be executed by tools like wp-cli and [b] plugins to register new cron events?

1
  • Yes, that's right.
    – leymannx
    Oct 31, 2022 at 5:58

1 Answer 1

1

Is this assumption valid? Or does DISABLE_WP_CRON actually block crons from running, and block plugins from registering new cron events?

Yes, setting DISABLE_WP_CRON to true doesn't actually block Wordpress' crons from running; it just prevents wordpress itself from initiating the events to run when your backend is triggered by a customer viewing your website.

I'm writing a plugin that tries to register a new cron event with wp_schedule_event(). The function returns True, but the new cron job does not appear in my event list, so I don't think it will ever be executed by my system's cron.

wp cron event list will not list all of your crons if you're using wordpress multisite.

I don't know of a built-in way to get wp-cli to just dump all of the crons for all of your sites, but here's a simple bash loop that will iterate through each of your sites and list all scheduled cron events for each site.

urls=$(wp site list --field=url)
for url in $urls; do
    echo ${url}
    sudo cron --url=${url} event list
    echo
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.