diff options
Diffstat (limited to 'healthcheck.php')
| -rw-r--r-- | healthcheck.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/healthcheck.php b/healthcheck.php new file mode 100644 index 0000000..ed41916 --- /dev/null +++ b/healthcheck.php @@ -0,0 +1,38 @@ +<?php +function communievents_healthcheck() { + global $wpdb; + + $tablename = $wpdb->prefix . 'communievents_events'; + + $evcount = $wpdb->get_var("SELECT COUNT(id) FROM $tablename", 0, 0); + $lastsync = $wpdb->get_var("SELECT MAX(lastsync) FROM $tablename", 0, 0); + $nextsync = wp_next_scheduled('communievents_cron_hook'); + + if ($lastsync) { + $lastsync_dt = new DateTime("@$lastsync"); + $lastsync_str = $lastsync_dt->format('Y-m-d H:i:s'); + } else { + $lastsync_str = "NEVER"; + } + + if ($nextsync) { + $nextsync_dt = new DateTime("@$nextsync"); + $nextsync_str = $nextsync_dt->format('Y-m-d H:i:s'); + } else { + $nextsync_str = "NEVER"; + } + + $now_dt = new DateTime('now'); + $now_str = $now_dt->format('Y-m-d H:i:s'); + + return "<table border><caption>CommuniEvents Health</caption>" . + "<tr><td>Event Count:<td>$evcount" . + "<tr><td>Last Sync:<td>$lastsync_str" . + "<tr><td>Next Sync:<td>$nextsync_str" . + "<tr><td>Now:<td>$now_str" . + "</table>"; +} + +function communievents_setup_healthcheck() { + add_shortcode('communievents-healthcheck', 'communievents_healthcheck'); +} |
