public
Last active

Plugin: List wp cron jobs in wp_footer

  • Download Gist
cron-list.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
<?php
defined( 'ABSPATH' ) OR 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.
Author: Franz Josef Kaiser
Author URI: https://github.com/franz-josef-kaiser
Version: 0.3.1
License: MIT
*/
 
add_action ( 'shutdown', 'wpse18017_list_cron' );
/**
* Builds a table to list current wp internal cron job data
*
* @param mixed array $cron_arr
* @return string
*/
function wpse18017_list_cron( $cron_arr )
{
// Load cron jobs and flatten array
foreach ( _get_cron_array() as $key => $data )
{
if ( is_int( $key ) )
{
if ( 1 <= count( $data ) )
{
foreach ( $data as $k => $d )
{
$v = array_values( current( $d ) );
$cron_jobs[ $k ] = $v;
}
continue;
}
$val = array_values( current( $data ) );
$cron_jobs[ key( $data ) ] = $val[0];
}
}
 
// Nothing to do
if ( empty( $cron_jobs ) )
return;
 
$results = '';
foreach ( $cron_jobs as $name => $data )
{
list ( $schedule, $args, $interval ) = wp_parse_args(
array_fill( 0, 3, 'not-set' ),
$data
);
$args = var_export( $args, true );
foreach ( wp_get_schedules() as $l10n )
{
if ( $interval === $l10n['interval'] )
{
$schedule = $l10n['display'];
$interval = ( $interval /60 /60 );
}
}
$results .= "<tr><td>{$name}</td><td>{$args}</td><td>{$schedule}</td><td>{$interval}</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></tr>
$results
</table>
</div>
EOF;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.