Skip to content

Commit

Permalink
Rework wp_publish_post() to use wp_update_post() again while turning …
Browse files Browse the repository at this point in the history
…off filters. Clear the cron schedule for a post when the post timestamp is updated. #2715 #2737

git-svn-id: http://svn.automattic.com/wordpress/trunk@4077 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ryan committed Aug 7, 2006
1 parent 033c07e commit 7bf42ee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
3 changes: 2 additions & 1 deletion wp-cron.php
Expand Up @@ -7,7 +7,8 @@
exit;

$crons = get_option('cron');
if (!is_array($crons) || array_shift(array_keys($crons)) > time())
$keys = array_keys($crons);
if (!is_array($crons) || $keys[0] > time())
return;
foreach ($crons as $timestamp => $cronhooks) {
if ($timestamp > time()) break;
Expand Down
16 changes: 11 additions & 5 deletions wp-includes/cron.php
Expand Up @@ -50,17 +50,23 @@ function wp_unschedule_event( $timestamp, $hook ) {
}

function wp_clear_scheduled_hook( $hook ) {
while ( $timestamp = wp_next_scheduled( $hook ) )
$args = array_slice( func_get_args(), 1 );

while ( $timestamp = wp_next_scheduled( $hook, $args ) )
wp_unschedule_event( $timestamp, $hook );
}

function wp_next_scheduled( $hook ) {
function wp_next_scheduled( $hook, $args = '' ) {
$crons = get_option( 'cron' );
if ( empty($crons) )
return false;
foreach ( $crons as $timestamp => $cron )
if ( isset( $cron[$hook] ) )
return $timestamp;
if ( isset( $cron[$hook] ) ) {
if ( empty($args) )
return $timestamp;
if ( $args == $cron[$hook]['args'] )
return $timestamp;
}
return false;
}

Expand Down Expand Up @@ -92,7 +98,7 @@ function wp_cron() {
return;

$keys = array_keys( $crons );
if ( array_shift( $keys ) > time() )
if ( $keys[0] > time() )
return;

$schedules = wp_get_schedules();
Expand Down
63 changes: 30 additions & 33 deletions wp-includes/post.php
Expand Up @@ -496,14 +496,16 @@ function wp_insert_post($postarr = array()) {
}

// Get the basics.
$post_content = apply_filters('content_save_pre', $post_content);
$post_excerpt = apply_filters('excerpt_save_pre', $post_excerpt);
$post_title = apply_filters('title_save_pre', $post_title);
$post_category = apply_filters('category_save_pre', $post_category);
$post_status = apply_filters('status_save_pre', $post_status);
$post_name = apply_filters('name_save_pre', $post_name);
$comment_status = apply_filters('comment_status_pre', $comment_status);
$ping_status = apply_filters('ping_status_pre', $ping_status);
if ( empty($no_filter) ) {
$post_content = apply_filters('content_save_pre', $post_content);
$post_excerpt = apply_filters('excerpt_save_pre', $post_excerpt);
$post_title = apply_filters('title_save_pre', $post_title);
$post_category = apply_filters('category_save_pre', $post_category);
$post_status = apply_filters('status_save_pre', $post_status);
$post_name = apply_filters('name_save_pre', $post_name);
$comment_status = apply_filters('comment_status_pre', $comment_status);
$ping_status = apply_filters('ping_status_pre', $ping_status);
}

// Make sure we set a valid category
if (0 == count($post_category) || !is_array($post_category)) {
Expand Down Expand Up @@ -544,7 +546,7 @@ function wp_insert_post($postarr = array()) {
if ( 'draft' != $post_status )
$post_date_gmt = get_gmt_from_date($post_date);
}

if ( 'publish' == $post_status ) {
$now = gmdate('Y-m-d H:i:59');
if ( mysql2date('U', $post_date_gmt) > mysql2date('U', $now) )
Expand Down Expand Up @@ -658,7 +660,22 @@ function wp_insert_post($postarr = array()) {
}

if ($post_status == 'publish' && $post_type == 'post') {
wp_publish_post($post_ID);
do_action('publish_post', $post_ID);

if ( !defined('WP_IMPORTING') ) {
if ( $post_pingback )
$result = $wpdb->query("
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','_pingme','1')
");
$result = $wpdb->query("
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','_encloseme','1')
");
wp_schedule_single_event(time(), 'do_pings');
}
} else if ($post_type == 'page') {
wp_cache_delete('all_page_ids', 'pages');
$wp_rewrite->flush_rules();
Expand All @@ -672,6 +689,7 @@ function wp_insert_post($postarr = array()) {
}

if ( 'future' == $post_status ) {
wp_clear_scheduled_hook('publish_future_post', $post_ID);
wp_schedule_single_event(mysql2date('U', $post_date), 'publish_future_post', $post_ID);
}

Expand Down Expand Up @@ -722,36 +740,15 @@ function wp_update_post($postarr = array()) {
}

function wp_publish_post($post_id) {
global $wpdb;

$post = get_post($post_id);

if ( empty($post) )
return;

if ( 'publish' != $post->post_status )
$wpdb->query("UPDATE IGNORE $wpdb->posts SET post_status = 'publish' WHERE ID = $post_id");

do_action('publish_post', $post_id);

if ( defined('WP_IMPORTING') )
if ( 'publish' == $post->post_status )
return;

$post_pingback = get_option('default_pingback_flag');
if ( $post_pingback )
$result = $wpdb->query("
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','_pingme','1')
");

$result = $wpdb->query("
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','_encloseme','1')
");

wp_schedule_single_event(time(), 'do_pings');
return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id, 'no_filter' => true));
}

function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
Expand Down

0 comments on commit 7bf42ee

Please sign in to comment.