Last active
January 26, 2018 15:32
-
-
Save adrianoGaspar/da5abd1025b96bb073e181a811a0c8a0 to your computer and use it in GitHub Desktop.
Solução para o agendamento perdido do WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Basta criar um arquivo no wp-content/mu-plugins do blog para garantir que, contanto que haja visitas ao blog, //os posts agendados não sejam mais deixados para trás. | |
//A sugestão é que se crie no local acima indicado um arquivo chamado fix-missed-schedule.php | |
//(ou qualquer coisa que faça sentido só de olhar para o nome dele), com o conteúdo abaixo. | |
// 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