Skip to content

Instantly share code, notes, and snippets.

@stephenh1988
Forked from franz-josef-kaiser/cron-list.php
Created October 19, 2012 18:53
Show Gist options
  • Save stephenh1988/3919989 to your computer and use it in GitHub Desktop.
Save stephenh1988/3919989 to your computer and use it in GitHub Desktop.
Plugin: List wp cron jobs in wp_footer
<?php
! defined( 'ABSPATH' ) AND exit;
/*
Plugin Name: WP Cron Jobs List
Plugin URI: https://github.com/franz-josef-kaiser
Description: List WordPress internal cron jobs (array data) after the footer. Based on Kaiser's original plug-in https://gist.github.com/987128
Author: Franz Josef Kaiser, Stephen Harris
Author URI: https://github.com/franz-josef-kaiser
Version: 0.3
License: MIT
*/
/*
* Primary difference between this plug-in and the original, is that this displays each seperate cron-job even when two or more share the same hook (and arguments).
*/
/**
* Builds a table to list current wp internal cron job data
*/
function wpse18017_list_cron()
{
//Available cron schedules
$schedules = wp_get_schedules();
//Go through each stored timestamp,
$results ='';
foreach ( _get_cron_array() as $timestamp => $jobs)
{
if ( is_int( $timestamp ) )
{
//For this timestamp, if it has jobs - loop through them.
if ( 1 <= count( $jobs ) )
{
//For each hooked job, harvest and print the details.
foreach ( $jobs as $hook => $details )
{
$args = array_values( current( $details ) );
$interval = $args[0];
$args = var_export( $args[1], true );
$schedule = $schedules[$interval]['display'];
$interval = ( $schedules[$interval]['interval']/60/60 );
$time = date_i18n( 'jS M G:ia', $timestamp );
$results .= "<tr><td>{$hook}</td><td>{$args}</td><td>{$schedule}</td><td>{$interval}</td><td>{$time}</td></tr>";
}
}
}
}
echo <<< EOF
<div class="clear"></div>
<div class="wrap">
<table class="wp-list-table widefat" style="margin: 10px;">
<caption>Dump of the cron/sheduled events:</caption>
<tr><th>Function</th><th>Arguments</th><th>Shedule</th><th>Time (h)</th><th>Next Schedule For</th></tr>
$results
</table>
</div>
EOF;
}
add_action ( 'shutdown', 'wpse18017_list_cron' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment