mirror of
https://github.com/felixfoertsch/wordpress-dev-env.git
synced 2026-04-18 07:18:43 +02:00
Initial commit
This commit is contained in:
303
wordpress_plugins/debug-bar-cron/class-debug-bar-cron.php
Normal file
303
wordpress_plugins/debug-bar-cron/class-debug-bar-cron.php
Normal file
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Add a new Debug Bar Panel.
|
||||
*/
|
||||
class ZT_Debug_Bar_Cron extends Debug_Bar_Panel {
|
||||
|
||||
/**
|
||||
* Holds all of the cron events.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_crons;
|
||||
|
||||
/**
|
||||
* Holds only the cron events initiated by WP core.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_core_crons;
|
||||
|
||||
/**
|
||||
* Holds the cron events created by plugins or themes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_user_crons;
|
||||
|
||||
/**
|
||||
* Total number of cron events
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_total_crons = 0;
|
||||
|
||||
/**
|
||||
* Whether cron is being executed or not.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_doing_cron = 'No';
|
||||
|
||||
/**
|
||||
* Give the panel a title and set the enqueues.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
$this->title( __( 'Cron', 'debug-bar' ) );
|
||||
add_action( 'wp_print_styles', array( $this, 'print_styles' ) );
|
||||
add_action( 'admin_print_styles', array( $this, 'print_styles' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function print_styles() {
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
|
||||
wp_enqueue_style( 'zt-debug-bar-cron', plugins_url( "css/debug-bar-cron$suffix.css", __FILE__ ), array(), '20131228' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the menu item in Debug Bar.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prerender() {
|
||||
$this->set_visible( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the contents of the page.
|
||||
|
||||
* @return void
|
||||
*/
|
||||
public function render() {
|
||||
$this->get_crons();
|
||||
|
||||
$this->_doing_cron = get_transient( 'doing_cron' ) ? __( 'Yes', 'zt-debug-bar-cron' ) : __( 'No', 'zt-debug-bar-cron' );
|
||||
|
||||
// Get the time of the next event
|
||||
$cron_times = array_keys( $this->_crons );
|
||||
$unix_time_next_cron = $cron_times[0];
|
||||
$time_next_cron = date( 'Y-m-d H:i:s', $unix_time_next_cron );
|
||||
|
||||
$human_time_next_cron = human_time_diff( $unix_time_next_cron );
|
||||
|
||||
// Add a class if past current time and doing cron is not running
|
||||
$times_class = time() > $unix_time_next_cron && 'No' == $this->_doing_cron ? ' past' : '';
|
||||
|
||||
echo '<div class="debug-bar-cron">';
|
||||
echo '<h2><span>' . __( 'Total Events', 'zt-debug-bar-cron' ) . ':</span>' . (int) $this->_total_crons . '</h2>';
|
||||
echo '<h2><span>' . __( 'Doing Cron', 'zt-debug-bar-cron' ) . ':</span>' . $this->_doing_cron . '</h2>';
|
||||
echo '<h2 class="times' . esc_attr( $times_class ) . '"><span>' . __( 'Next Event', 'zt-debug-bar-cron' ) . ':</span>' . $time_next_cron . '<br />' . $unix_time_next_cron . '<br />' . $human_time_next_cron . $this->display_past_time( $unix_time_next_cron ) . '</h2>';
|
||||
echo '<h2><span>' . __( 'Current Time', 'zt-debug-bar-cron' ) . ':</span>' . date( 'H:i:s' ) . '</h2>';
|
||||
echo '<div class="clear"></div>';
|
||||
|
||||
echo '<h3>' . __( 'Custom Events', 'zt-debug-bar-cron' ) . '</h3>';
|
||||
|
||||
if ( ! is_null( $this->_user_crons ) )
|
||||
$this->display_events( $this->_user_crons );
|
||||
else
|
||||
echo '<p>' . __( 'No Custom Events scheduled.', 'zt-debug-bar-cron' ) . '</p>';
|
||||
|
||||
echo '<h3>' . __( 'Schedules', 'zt-debug-bar-cron' ) . '</h3>';
|
||||
|
||||
$this->display_schedules();
|
||||
|
||||
echo '<h3>' . __( 'Core Events', 'zt-debug-bar-cron' ) . '</h3>';
|
||||
|
||||
if ( ! is_null( $this->_core_crons ) )
|
||||
$this->display_events( $this->_core_crons );
|
||||
else
|
||||
echo '<p>' . __( 'No Core Events scheduled.', 'zt-debug-bar-cron' ) . '</p>';
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all of the cron jobs.
|
||||
*
|
||||
* This function sorts the cron jobs into core crons, and custom crons. It also tallies
|
||||
* a total count for the crons as this number is otherwise tough to get.
|
||||
*
|
||||
* @return array Array of crons.
|
||||
*/
|
||||
private function get_crons() {
|
||||
if ( ! is_null( $this->_crons ) )
|
||||
return $this->_crons;
|
||||
|
||||
if ( ! $crons = _get_cron_array() )
|
||||
return $this->_crons;
|
||||
|
||||
$this->_crons = $crons;
|
||||
|
||||
// Lists all crons that are defined in WP Core
|
||||
$core_cron_hooks = array(
|
||||
'wp_scheduled_delete',
|
||||
'upgrader_scheduled_cleanup',
|
||||
'importer_scheduled_cleanup',
|
||||
'publish_future_post',
|
||||
'akismet_schedule_cron_recheck',
|
||||
'akismet_scheduled_delete',
|
||||
'do_pings',
|
||||
'wp_version_check',
|
||||
'wp_update_plugins',
|
||||
'wp_update_themes'
|
||||
);
|
||||
|
||||
// Sort and count crons
|
||||
foreach ( $this->_crons as $time => $time_cron_array ) {
|
||||
foreach ( $time_cron_array as $hook => $data ) {
|
||||
$this->_total_crons++;
|
||||
|
||||
if ( in_array( $hook, $core_cron_hooks ) )
|
||||
$this->_core_crons[ $time ][ $hook ] = $data;
|
||||
else
|
||||
$this->_user_crons[ $time ][ $hook ] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_crons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the events in an easy to read table.
|
||||
*
|
||||
* @param array $events Array of events.
|
||||
* @return void|string Void on failure; table display of events on success.
|
||||
*/
|
||||
private function display_events( $events ) {
|
||||
if ( is_null( $events ) || empty( $events ) )
|
||||
return;
|
||||
|
||||
echo '<table class="zt-debug-bar-cron-event-table" cellspacing="0">';
|
||||
echo '<thead><tr>';
|
||||
echo '<th class="col1">' . __( 'Next Execution', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col2">' . __( 'Hook', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col3">' . __( 'Interval Hook', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col4">' . __( 'Interval Value', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col5">' . __( 'Args', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '</tr></thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
foreach ( $events as $time => $time_cron_array ) {
|
||||
foreach ( $time_cron_array as $hook => $data ) {
|
||||
// Add a class if past current time
|
||||
$times_class = time() > $time && 'No' == $this->_doing_cron ? ' class="past"' : '';
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td' . $times_class . '>' . date( 'Y-m-d H:i:s', $time ) . '<br />' . $time . '<br />' . human_time_diff( $time ) . $this->display_past_time( $time ) . '</td>';
|
||||
echo '<td>' . wp_strip_all_tags( $hook ) . '</td>';
|
||||
|
||||
foreach ( $data as $hash => $info ) {
|
||||
// Report the schedule
|
||||
echo '<td>';
|
||||
if ( $info['schedule'] )
|
||||
echo wp_strip_all_tags( $info['schedule'] );
|
||||
else
|
||||
echo 'Single Event';
|
||||
echo '</td>';
|
||||
|
||||
// Report the interval
|
||||
echo '<td>';
|
||||
if ( isset( $info['interval'] ) ) {
|
||||
echo wp_strip_all_tags( $info['interval'] ) . 's<br />';
|
||||
echo $info['interval'] / 60 . 'm<br />';
|
||||
echo $info['interval'] / ( 60 * 60 ). 'h';
|
||||
} else {
|
||||
echo 'Single Event';
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
// Report the args
|
||||
echo '<td>';
|
||||
if ( is_array( $info['args'] ) && ! empty( $info['args'] ) ) {
|
||||
foreach ( $info['args'] as $key => $value ) {
|
||||
$this->display_cron_arguments( $key, $value );
|
||||
}
|
||||
} else if ( is_string( $info['args'] ) && $info['args'] !== '' ) {
|
||||
echo esc_html( $info['args'] );
|
||||
} else {
|
||||
echo 'No Args';
|
||||
}
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</tbody>';
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Displays the cron arguments in a readable format.
|
||||
*
|
||||
* @param int|string $key Key of the array element.
|
||||
* @param mixed $value Cron argument(s).
|
||||
* @param int $depth Current recursion depth.
|
||||
* @return void
|
||||
*/
|
||||
function display_cron_arguments( $key, $value, $depth = 0 ) {
|
||||
if ( is_string( $value ) ) {
|
||||
echo str_repeat( ' ', ( $depth * 2 ) ) . wp_strip_all_tags( $key ) . ' => ' . esc_html( $value ) . '<br />';
|
||||
} else if ( is_array( $value ) ) {
|
||||
if ( count( $value ) > 0 ) {
|
||||
echo str_repeat( ' ', ( $depth * 2 ) ) . wp_strip_all_tags( $key ) . ' => array(<br />';
|
||||
$depth++;
|
||||
foreach ( $value as $k => $v ) {
|
||||
$this->display_cron_arguments( $k, $v, $depth );
|
||||
}
|
||||
echo str_repeat( ' ', ( ( $depth - 1 ) * 2 ) ) . ')';
|
||||
} else {
|
||||
echo 'Empty Array';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all of the schedules defined.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function display_schedules() {
|
||||
echo '<table class="zt-debug-bar-cron-event-table" cellspacing="0">';
|
||||
echo '<thead><tr>';
|
||||
echo '<th class="col1">' . __( 'Interval Hook', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col2">' . __( 'Interval (S)', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col3">' . __( 'Interval (M)', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col4">' . __( 'Interval (H)', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '<th class="col5">' . __( 'Display Name', 'zt-debug-bar-cron' ) . '</th>';
|
||||
echo '</tr></thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
foreach ( wp_get_schedules() as $interval_hook => $data ) {
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html( $interval_hook ) . '</td>';
|
||||
echo '<td>' . wp_strip_all_tags( $data['interval'] ) . '</td>';
|
||||
echo '<td>' . wp_strip_all_tags( $data['interval'] ) / 60 . '</td>';
|
||||
echo '<td>' . wp_strip_all_tags( $data['interval'] ) / ( 60 * 60 ). '</td>';
|
||||
echo '<td>' . esc_html( $data['display'] ) . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
echo '</tbody>';
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares time with current time and outputs 'ago' if current time is greater that even time.
|
||||
*
|
||||
* @param int $time Unix time of event.
|
||||
* @return string
|
||||
*/
|
||||
private function display_past_time( $time ) {
|
||||
return time() > $time ? ' ' . __( 'ago', 'zt-debug-bar-cron' ) : '';
|
||||
}
|
||||
}
|
||||
1
wordpress_plugins/debug-bar-cron/css/debug-bar-cron.css
Normal file
1
wordpress_plugins/debug-bar-cron/css/debug-bar-cron.css
Normal file
@@ -0,0 +1 @@
|
||||
.debug-bar-cron h2.times{font-size:1.7em;line-height:1.1}.debug-bar-cron h2.times span{line-height:150%}.debug-bar-cron .past{color:red}.debug-bar-cron h2.times.past span{color:#888}.debug-bar-cron h3{font-family:georgia,times,serif;font-size:22px}.zt-debug-bar-cron-event-table{width:100%;border-top:1px solid #dfdfdf;border-bottom:1px solid #fcfcfc}.zt-debug-bar-cron-event-table th,.zt-debug-bar-cron-event-table td{padding:.3em 2.5em .3em .3em;border-top:1px solid #fcfcfc;border-bottom:1px solid #dfdfdf}.zt-debug-bar-cron-event-table tbody td{vertical-align:top}.zt-debug-bar-cron-event-table thead,.zt-debug-bar-cron-event-table tr:nth-child(2n+1){background:#fcfcfc}.zt-debug-bar-cron-event-table td.past{font-weight:bold}.zt-debug-bar-cron-event-table thead th.col1{width:180px}.zt-debug-bar-cron-event-table thead th.col2,.zt-debug-bar-cron-event-table thead th.col5{width:25%}.zt-debug-bar-cron-event-table thead th.col3{width:20%}.zt-debug-bar-cron-event-table thead th.col4{width:120px}
|
||||
52
wordpress_plugins/debug-bar-cron/css/debug-bar-cron.dev.css
Normal file
52
wordpress_plugins/debug-bar-cron/css/debug-bar-cron.dev.css
Normal file
@@ -0,0 +1,52 @@
|
||||
.debug-bar-cron h2.times {
|
||||
font-size: 1.7em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
.debug-bar-cron h2.times span {
|
||||
line-height: 150%;
|
||||
}
|
||||
.debug-bar-cron .past {
|
||||
color: red;
|
||||
}
|
||||
.debug-bar-cron h2.times.past span {
|
||||
color: #888;
|
||||
}
|
||||
.debug-bar-cron h3 {
|
||||
font-family: georgia, times, serif;
|
||||
font-size: 22px;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table {
|
||||
width: 100%;
|
||||
border-top: 1px solid #dfdfdf;
|
||||
border-bottom: 1px solid #fcfcfc;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table th,
|
||||
.zt-debug-bar-cron-event-table td {
|
||||
padding: .3em 2.5em .3em .3em;
|
||||
border-top: 1px solid #fcfcfc;
|
||||
border-bottom: 1px solid #dfdfdf;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table tbody td {
|
||||
vertical-align: top;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table thead,
|
||||
.zt-debug-bar-cron-event-table tr:nth-child(2n) {
|
||||
background: #fcfcfc;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table td.past {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.zt-debug-bar-cron-event-table thead th.col1 {
|
||||
width: 180px;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table thead th.col2,
|
||||
.zt-debug-bar-cron-event-table thead th.col5 {
|
||||
width: 25%;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table thead th.col3 {
|
||||
width: 20%;
|
||||
}
|
||||
.zt-debug-bar-cron-event-table thead th.col4 {
|
||||
width: 120px;
|
||||
}
|
||||
24
wordpress_plugins/debug-bar-cron/debug-bar-cron.php
Normal file
24
wordpress_plugins/debug-bar-cron/debug-bar-cron.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Debug Bar Cron
|
||||
Plugin URI: http://github.com/tollmanz/
|
||||
Description: Adds information about WP scheduled events to Debug Bar.
|
||||
Author: Zack Tollman, Helen Hou-Sandi
|
||||
Version: 0.1.2
|
||||
Author URI: http://github.com/tollmanz
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds panel, as defined in the included class, to Debug Bar.
|
||||
*
|
||||
* @param $panels array
|
||||
* @return array
|
||||
*/
|
||||
function zt_add_debug_bar_cron_panel( $panels ) {
|
||||
if ( ! class_exists( 'ZT_Debug_Bar_Cron' ) ) {
|
||||
include ( 'class-debug-bar-cron.php' );
|
||||
$panels[] = new ZT_Debug_Bar_Cron();
|
||||
}
|
||||
return $panels;
|
||||
}
|
||||
add_filter( 'debug_bar_panels', 'zt_add_debug_bar_cron_panel' );
|
||||
66
wordpress_plugins/debug-bar-cron/readme.txt
Normal file
66
wordpress_plugins/debug-bar-cron/readme.txt
Normal file
@@ -0,0 +1,66 @@
|
||||
=== Debug Bar Cron ===
|
||||
Contributors: tollmanz, helen, 10up
|
||||
Donate Link: http://wordpress.org
|
||||
Tags: debug bar, cron
|
||||
Requires at least: 3.3
|
||||
Tested up to: trunk
|
||||
Stable tag: 0.1.3
|
||||
|
||||
Debug Bar Cron adds a new panel to Debug Bar that displays information about WP scheduled events.
|
||||
|
||||
== Description ==
|
||||
|
||||
Debug Bar Cron adds information about WP scheduled events to a new panel in the Debug Bar. This plugin is an extension for
|
||||
Debug Bar and thus is dependent upon Debug Bar being installed for it to work properly.
|
||||
|
||||
Once installed, you will have access to the following information:
|
||||
|
||||
* Number of scheduled events
|
||||
* If cron is currently running
|
||||
* Time of next event
|
||||
* Current time
|
||||
* List of custom scheduled events
|
||||
* List of core scheduled events
|
||||
* List of schedules
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Install Debug Bar if not already installed (http://wordpress.org/extend/plugins/debug-bar/)
|
||||
2. Upload the `debug-bar-cron` folder to the `/wp-content/plugins/` directory
|
||||
3. Activate the plugin through the 'Plugins' menu in WordPress
|
||||
4. View the WP schedule events information in the "Cron" panel in Debug Bar
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Is debugging cron easier with this plugin? =
|
||||
|
||||
Yes
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. The Debug Bar Cron panel
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 0.1.3 =
|
||||
|
||||
* Fixed 'Array to string conversion' error when Cron job arguments are in a multi-dimensional array - props [Jrf](http://profiles.wordpress.org/jrf), [ethitter](http://profiles.wordpress.org/ethitter), and [mintindeed](http://profiles.wordpress.org/mintindeed).
|
||||
* Fixed a number of HTML validation errors - props [Jrf](http://profiles.wordpress.org/jrf).
|
||||
|
||||
= 0.1.2 =
|
||||
* Added indicators for missed events
|
||||
|
||||
= 0.1.1 =
|
||||
* Readme updates
|
||||
|
||||
= 0.1 =
|
||||
* Initial release
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 0.1.2 =
|
||||
Adds indicators for missed events
|
||||
|
||||
= 0.1 =
|
||||
Initial Release
|
||||
|
||||
BIN
wordpress_plugins/debug-bar-cron/screenshot-1.png
Normal file
BIN
wordpress_plugins/debug-bar-cron/screenshot-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 160 KiB |
Reference in New Issue
Block a user