From b49ff57e63d34ca38f523b00cce0948f30425643 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 22 Feb 2008 19:59:12 +0000 Subject: [PATCH] Make sure post has future status before publishing from cron. Props hailin. fixes #5801 git-svn-id: http://svn.automattic.com/wordpress/trunk@6985 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 2 +- wp-includes/post.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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); }