Skip to content

Instantly share code, notes, and snippets.

@collegeman
Created April 16, 2012 02:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save collegeman/2395991 to your computer and use it in GitHub Desktop.
Save collegeman/2395991 to your computer and use it in GitHub Desktop.
A simple drop-in for fixing Missed Schedules in WordPress
<?php
// Based on: http://wordpress.org/extend/plugins/wp-missed-schedule/
@define('MISSED_SCHEDULE_DELAY', 5);
@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 ))) {
return;
}
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}`
WHERE
`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) {
continue;
}
wp_publish_post($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