Skip to content
Prev Previous commit
Next Next commit
Merge branch 'main' into add-all-flag-to-delete
  • Loading branch information
janw-me authored Nov 10, 2023
commit ae4f7143f7255aeeb46713bf88e8f092672a699b
36 changes: 33 additions & 3 deletions src/Cron_Event_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,32 @@ public function unschedule( $args, $assoc_args ) {
}
}

/**
* Executes an event immediately.
*
* @param stdClass $event The event
* @return bool Whether the event was successfully executed or not.
*/
protected static function run_event( stdClass $event ) {

if ( ! defined( 'DOING_CRON' ) ) {
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Using native WordPress constant.
define( 'DOING_CRON', true );
}

if ( false !== $event->schedule ) {
$new_args = array( $event->time, $event->schedule, $event->hook, $event->args );
call_user_func_array( 'wp_reschedule_event', $new_args );
}

wp_unschedule_event( $event->time, $event->hook, $event->args );

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Can't prefix dynamic hooks here, calling registered hooks.
do_action_ref_array( $event->hook, $event->args );

return true;
}

/**
* Deletes all scheduled cron events for the given hook.
*
Expand Down Expand Up @@ -319,9 +345,13 @@ public function delete( $args, $assoc_args ) {

$deleted = 0;
foreach ( $events as $event ) {
$result = self::delete_event( $event );
if ( $result ) {
$deleted++;
if ( $event->hook === $hook ) {
$result = self::delete_event( $event );
if ( $result ) {
++$deleted;
} else {
WP_CLI::warning( sprintf( "Failed to the delete the cron event '%s'.", $hook ) );
}
}
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.