Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// Based on:
@define('MISSED_SCHEDULE_OPTION', 'wp_missed_schedule');
function fix_missed_schedule() {
global $wpdb;
// check to see if the publishing window is up again...
$last = get_option(MISSED_SCHEDULE_OPTION, false);
if ($last && $last > ( time() - ( MISSED_SCHEDULE_DELAY * 60 ))) {
update_option(MISSED_SCHEDULE_OPTION, time());
// remove this so that we don't publish twice...
remove_action('publish_future_post', 'check_and_publish_future_post');
// locate any posts that should have been published but haven't been...
$post_ids = $wpdb->get_col("
SELECT `ID` FROM `{$wpdb->posts}`
`post_status` = 'future'
AND `post_date_gmt` > 0
AND `post_date_gmt` <= UTC_TIMESTAMP()
if ($post_ids) {
$permalinks = array_map('get_permalink', $post_ids);
foreach($post_ids as $post_id) {
if (!$post_id) {
wp_mail(get_option('admin_email'), "Oops! Schedule Missed on {$_SERVER['HTTP_HOST']}", "These posts were published late...\n\n".implode("\n", $permalinks));
} else {
// wp_mail(get_option('admin_email'), "w00t! No schedules missed on {$_SERVER['HTTP_HOST']}", "These aren't the droids you're looking for.");
add_action('init', 'fix_missed_schedule');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment