Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

See scheduled tasks (WP-Cron)

Adds Tools > Scheduled tasks for administrators: every WP-Cron event, when it runs next and how often. Handy for finding the plugin behind a slow site.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Developer tools
  • Tested with WordPress 7.1
PHP
<?php

add_action(
	'admin_menu',
	static function () {
		add_management_page(
			'Scheduled tasks',
			'Scheduled tasks',
			'manage_options',
			'cron-events',
			static function () {
				$schedules = wp_get_schedules();
				echo '<div class="wrap"><h1>Scheduled tasks</h1>';
				if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
					echo '<div class="notice notice-info"><p>DISABLE_WP_CRON is on: a server cron job must run wp-cron.php.</p></div>';
				}
				echo '<table class="widefat striped"><thead><tr><th>Hook</th><th>Next run</th><th>Repeats</th><th>Arguments</th></tr></thead><tbody>';
				foreach ( (array) _get_cron_array() as $time => $hooks ) {
					foreach ( (array) $hooks as $hook => $events ) {
						foreach ( (array) $events as $event ) {
							$repeat = empty( $event['schedule'] ) ? 'Once' : ( $schedules[ $event['schedule'] ]['display'] ?? $event['schedule'] );
							printf(
								'<tr><td><code>%s</code></td><td>%s <span class="description">(%s)</span></td><td>%s</td><td><code>%s</code></td></tr>',
								esc_html( $hook ),
								esc_html( wp_date( 'Y-m-d H:i:s', (int) $time ) ),
								esc_html( ( $time < time() ? '-' : '' ) . human_time_diff( (int) $time ) ),
								esc_html( $repeat ),
								esc_html( $event['args'] ? wp_json_encode( $event['args'] ) : '' )
							);
						}
					}
				}
				echo '</tbody></table></div>';
			}
		);
	}
);

In these packs

  • Developer tools: Maintenance mode, template names, page stats, environment labels and a WP-Cron viewer.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.