diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 4156ec4f65..cb0355df7a 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -160,7 +160,7 @@ add_filter('atom_service_url','atom_service_url_filter'); add_action('wp_head', 'rsd_link'); add_action('wp_head', 'wlwmanifest_link'); add_action('wp_head', 'locale_stylesheet'); -add_action('publish_future_post', 'wp_publish_post', 10, 1); +add_action('publish_future_post', 'check_and_publish_future_post', 10, 1); add_action('wp_head', 'noindex', 1); add_action('wp_head', 'wp_print_scripts'); add_action('wp_head', 'wp_generator'); diff --git a/wp-includes/post.php b/wp-includes/post.php index d1dbc5adba..d47a1053c1 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1393,6 +1393,34 @@ function wp_publish_post($post_id) { do_action('wp_insert_post', $post_id, $post); } +/** + * check_and_publish_future_post() - check to make sure post has correct status before + * passing it on to be published. Invoked by cron 'publish_future_post' event + * This safeguard prevents cron from publishing drafts, etc. + * + * {@internal Missing Long Description}} + * + * @package WordPress + * @subpackage Post + * @since 2.5 + * @uses $wpdb + * + * @param int $post_id Post ID + * @return int|null {@internal Missing Description}} + */ +function check_and_publish_future_post($post_id) { + + $post = get_post($post_id); + + if ( empty($post) ) + return; + + if ( 'future' != $post->post_status ) + return; + + return wp_publish_post($post_id); +} + function wp_add_post_tags($post_id = 0, $tags = '') { return wp_set_post_tags($post_id, $tags, true); }