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 '
'; } /** * 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 '| ' . __( 'Next Execution', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Hook', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Interval Hook', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Interval Value', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Args', 'zt-debug-bar-cron' ) . ' | '; echo '
|---|---|---|---|---|
| ' . date( 'Y-m-d H:i:s', $time ) . ' ' . $time . ' ' . human_time_diff( $time ) . $this->display_past_time( $time ) . ' | ';
echo '' . wp_strip_all_tags( $hook ) . ' | '; foreach ( $data as $hash => $info ) { // Report the schedule echo ''; if ( $info['schedule'] ) echo wp_strip_all_tags( $info['schedule'] ); else echo 'Single Event'; echo ' | '; // Report the interval echo '';
if ( isset( $info['interval'] ) ) {
echo wp_strip_all_tags( $info['interval'] ) . 's '; echo $info['interval'] / 60 . 'm '; echo $info['interval'] / ( 60 * 60 ). 'h'; } else { echo 'Single Event'; } echo ' | ';
// Report the args
echo ''; 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 ' | '; } echo '
| ' . __( 'Interval Hook', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Interval (S)', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Interval (M)', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Interval (H)', 'zt-debug-bar-cron' ) . ' | '; echo '' . __( 'Display Name', 'zt-debug-bar-cron' ) . ' | '; echo '
|---|---|---|---|---|
| ' . esc_html( $interval_hook ) . ' | '; echo '' . wp_strip_all_tags( $data['interval'] ) . ' | '; echo '' . wp_strip_all_tags( $data['interval'] ) / 60 . ' | '; echo '' . wp_strip_all_tags( $data['interval'] ) / ( 60 * 60 ). ' | '; echo '' . esc_html( $data['display'] ) . ' | '; echo '