wp_doing_cron()
Determines whether the current request is a WordPress cron request.
1 time — 0.000021 sec (very fast) | 50000 times — 0.12 sec (very fast) | PHP 7.1.2, WP 4.8
Hooks from the function
Return
true|false
. True if it's a WordPress cron request, false otherwise.
Usage
wp_doing_cron();
Examples
#1 Do anything when a cron request is in progress only.
For example, let's remove my_schedule_hook
event from the schedule cron, when the next cron request is triggered.
add_action( 'shutdown', function(){ if( wp_doing_cron() ){ // delete cron task $timestamp = wp_next_scheduled( 'my_schedule_hook' ); wp_unschedule_event( $timestamp, 'my_schedule_hook' ); } } );
Changelog
Since 4.8.0 | Introduced. |
wp_doing_cron() wp doing cron code WP 6.1.1
function wp_doing_cron() { /** * Filters whether the current request is a WordPress cron request. * * @since 4.8.0 * * @param bool $wp_doing_cron Whether the current request is a WordPress cron request. */ return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); }