Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.