Permalink
Browse files

Added indicators for missed events (issue #2).

When an events time is less than the current time, the human time diff gets the "ago" indicator. Additionally, if doing cron is "no" and the current time is greater than an event's time, the event is printed in red. This should allow for very easily seeing if a number of events have been missed.
  • Loading branch information...
Zack Tollman
Zack Tollman committed Jul 1, 2012
1 parent c5a15c3 commit c2c5a436435c14a080649a867b1988f963eee19e
Showing with 42 additions and 12 deletions.
  1. +32 −11 class-debug-bar-cron.php
  2. +1 −1 css/debug-bar-cron.css
  3. +9 −0 css/debug-bar-cron.dev.css
View
@@ -33,6 +33,13 @@ class ZT_Debug_Bar_Cron extends Debug_Bar_Panel {
*/
private $_total_crons = 0;
+ /**
+ * Whether cron is being executed or not.
+ *
+ * @var string Yes or No.
+ */
+ private $_doing_cron = 'No';
+
/**
* Give the panel a title and set the enqueues.
*/
@@ -63,41 +70,42 @@ public function prerender() {
public function render() {
$this->get_crons();
- $doing_cron = get_transient( 'doing_cron' ) ? 'Yes' : 'No';
+ $this->_doing_cron = get_transient( 'doing_cron' ) ? 'Yes' : 'No';
// 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 id="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>' . $doing_cron . '</h2>';
- echo '<h2 class="times"><span>' . __( 'Next Event', 'zt-debug-bar-cron' ) . ':</span>' . $time_next_cron . '<br />' . $unix_time_next_cron . '<br />' . $human_time_next_cron . '</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 ) ) {
+ if ( ! is_null( $this->_user_crons ) )
$this->display_events( $this->_user_crons );
- } else {
+ 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 ) ) {
+ if ( ! is_null( $this->_core_crons ) )
$this->display_events( $this->_core_crons );
- } else {
+ else
echo '<p>' . __( 'No Core Events scheduled.', 'zt-debug-bar-cron' ) . '</p>';
- }
echo '</div>';
}
@@ -171,8 +179,11 @@ private function display_events( $events ) {
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 class="' . $class . '">';
- echo '<td valign="top">' . date( 'Y-m-d H:i:s', $time ) . '<br />' . $time . '<br />' . human_time_diff( $time ) . '</td>';
+ echo '<td valign="top"' . $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 valign="top">' . wp_strip_all_tags( $hook ) . '</td>';
foreach ( $data as $hash => $info ) {
@@ -244,4 +255,14 @@ private function display_schedules() {
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' : '';
+ }
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -5,6 +5,12 @@
#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;
@@ -23,4 +29,7 @@
.zt-debug-bar-cron-event-table thead,
.zt-debug-bar-cron-event-table tr.even {
background: #fcfcfc;
+}
+.zt-debug-bar-cron-event-table td.past {
+ font-weight: bold;
}

0 comments on commit c2c5a43

Please sign in to comment.