Created
March 30, 2012 07:42
-
-
Save sercomi/2248949 to your computer and use it in GitHub Desktop.
WP: List Cronjobs in the footer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WP Cron Jobs | |
Plugin URI: https://github.com/franz-josef-kaiser | |
Description: List WordPress internal cron jobs (array data) in the footer. The hook 'wp_footer()' must be present in your theme. | |
Author: Franz Josef Kaiser | |
Author URI: https://github.com/franz-josef-kaiser | |
Version: 0.1 | |
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
(c) Copyright 2011 - 2011 by Franz Josef Kaiser | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
// Secure: doesn't allow to load this file directly | |
if( ! class_exists('WP') ) | |
{ | |
header( 'Status: 403 Forbidden' ); | |
header( 'HTTP/1.1 403 Forbidden' ); | |
exit; | |
} | |
/** | |
* Builds a table to list current wp internal cron job data | |
* | |
* @param (mixed) array $cron_arr | |
*/ | |
function wpse18017_list_cron( $cron_arr ) | |
{ | |
$cron_arr = ( _get_cron_array() ); | |
$schedules_arr = wp_get_schedules(); | |
echo '<br><pre>'; # print_r($schedules_arr); print_r($cron_arr); | |
echo '<table>'; | |
echo '<caption>Dump of the cron/sheduled events:</caption>'; | |
echo '<tr><th>Function</th><th>Arguments</th><th>Shedule</th><th>Time (h)</th></tr>'; | |
foreach ( $cron_arr as $fn => $cron_data ) | |
{ | |
$output = '<tr>'; | |
if ( is_array( $cron_data ) ) | |
{ | |
foreach ( $cron_data as $fn => $data ) | |
{ | |
if ( is_array( $data ) ) | |
{ | |
echo "<td>{$fn}</td>"; | |
foreach ( $data as $fn => $d ) | |
{ | |
$interval = isset( $d['interval'] ) ? ( $d['interval']/60/60 ) : ' - '; | |
foreach ( $schedules_arr as $s ) | |
if ( $d['interval'] = $s['interval'] ) | |
$schedule = $d['schedule'] ? $d['schedule'] : '<em>not set</em>'; | |
echo '<td>'; | |
$num_args = count( $d['args'] ); | |
$i = 0; | |
foreach ( $d['args'] as $a ) | |
{ | |
if ( $i < $num_args && $i > 0 ) | |
{ | |
echo " {$a}, "; | |
} | |
else | |
{ | |
echo $a; | |
} | |
$i++; | |
} | |
echo '</td>'; | |
echo "<td>{$schedule}</td><td>{$interval}</td></tr><tr>"; | |
} | |
} | |
else | |
{ | |
$interval = isset( $data['interval'] ) ? ( $data['interval']/60/60 ) : ' - '; | |
foreach ( $schedules_arr as $s ) | |
if ( $data['interval'] = $s['interval'] ) | |
$schedule = $data['schedule'] ? $data['schedule'] : '<em>not set</em>'; | |
echo '<td>'.$fn.'</td>'; | |
echo '<td>'; | |
$num_args = count( $data['args'] ); | |
$i = 0; | |
foreach ( $data['args'] as $args ) | |
{ | |
if ( $i < $num_args && $i > 0 ) | |
{ | |
echo " {$args}, "; | |
} | |
else | |
{ | |
echo $args; | |
} | |
$i++; | |
} | |
echo '</td>'; | |
echo "<td>{$schedule}</td><td>{$interval}</td></tr><tr>"; | |
} | |
} | |
} | |
echo '</tr>'; | |
} | |
echo '</table>'; | |
echo '</pre>'; | |
} | |
add_action ( 'wp_footer', 'wpse18017_list_cron' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment