Upcoming Scheduled Tasks Widget
Lists the next WP-Cron events and flags overdue ones, a quick way to spot a broken scheduler.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_cron_events', 'Scheduled Tasks', function () {
$crons = _get_cron_array();
if ( empty( $crons ) ) {
echo '<p>No scheduled tasks.</p>';
return;
}
$now = time();
$shown = 0;
echo '<table class="widefat striped"><tbody>';
foreach ( $crons as $timestamp => $hooks ) {
foreach ( $hooks as $hook => $events ) {
foreach ( $events as $event ) {
if ( ++$shown > 12 ) {
break 3;
}
$late = $timestamp < $now - 10 * MINUTE_IN_SECONDS;
printf(
'<tr><td><code>%1$s</code><br><small>%2$s</small></td><td style="text-align:right;%3$s">%4$s</td></tr>',
esc_html( $hook ),
esc_html( ! empty( $event['schedule'] ) ? $event['schedule'] : 'once' ),
$late ? 'color:#d63638;font-weight:600' : '',
esc_html( ( $timestamp < $now ? 'overdue by ' : 'in ' ) . human_time_diff( $timestamp, $now ) )
);
}
}
}
echo '</tbody></table>';
} );
} );
Notes
Many overdue tasks usually mean WP-Cron is disabled or the site gets too little traffic.
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.