Scheduled Cron Events Viewer
Adds a Tools > Cron Events screen listing every scheduled WP-Cron event with its next run time, recurrence and hook name, to debug missed or duplicate tasks.
Opens WPIDE on
Code
add_action( 'admin_menu', function () {
add_management_page( 'Cron Events', 'Cron Events', 'manage_options', 'wpide-cron-events', function () {
$crons = _get_cron_array();
$schedules = wp_get_schedules();
echo '<div class="wrap"><h1>Cron Events</h1>';
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
echo '<div class="notice notice-info inline"><p>DISABLE_WP_CRON is set: events only run when a server cron job calls wp-cron.php.</p></div>';
}
echo '<table class="widefat striped"><thead><tr><th>Hook</th><th>Next run</th><th>Recurrence</th><th>Arguments</th></tr></thead><tbody>';
foreach ( (array) $crons as $timestamp => $hooks ) {
foreach ( (array) $hooks as $hook => $events ) {
foreach ( (array) $events as $event ) {
$when = $timestamp < time() ? 'overdue (' . human_time_diff( $timestamp ) . ')' : 'in ' . human_time_diff( $timestamp );
$rec = $event['schedule'] ? ( isset( $schedules[ $event['schedule'] ] ) ? $schedules[ $event['schedule'] ]['display'] : $event['schedule'] ) : 'once';
printf(
'<tr><td><code>%1$s</code></td><td>%2$s<br><small>%3$s</small></td><td>%4$s</td><td><code>%5$s</code></td></tr>',
esc_html( $hook ),
esc_html( $when ),
esc_html( wp_date( 'Y-m-d H:i:s', $timestamp ) ),
esc_html( $rec ),
esc_html( $event['args'] ? wp_json_encode( $event['args'] ) : '' )
);
}
}
}
echo '</tbody></table></div>';
} );
} );
Notes
Read-only: nothing can be deleted or run from this screen.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.