diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index b0167ddae4..824cf30394 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -134,20 +134,24 @@ function wp_insert_post($postarr = array()) { } $result = $wpdb->query($postquery); - if ( $update ) - $rval = $wpdb->rows_affected; - else - $rval = $wpdb->insert_id; + + wp_set_post_cats('', $post_ID, $post_category); + + if ( 'static' == $post_status ) + clean_page_cache($post_ID); + else + clean_post_cache($post_ID); // Set GUID if ( ! $update ) $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'"); - - wp_set_post_cats('', $post_ID, $post_category); if ( $update) { - if ($previous_status != 'publish' && $post_status == 'publish') + if ($previous_status != 'publish' && $post_status == 'publish') { + // Reset GUID if transitioning to publish. + $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'"); do_action('private_to_published', $post_ID); + } do_action('edit_post', $post_ID); } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 47df6c389e..0076239414 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1167,6 +1167,13 @@ function update_post_cache(&$posts) { } } +function clean_post_cache($id) { + global $post_cache; + + if ( isset( $post_cache[$id] ) ) + unset( $post_cache[$id] ); +} + function update_page_cache(&$pages) { global $page_cache; @@ -1178,6 +1185,14 @@ function update_page_cache(&$pages) { } } + +function clean_page_cache($id) { + global $page_cache; + + if ( isset( $page_cache[$id] ) ) + unset( $page_cache[$id] ); +} + function update_post_category_cache($post_ids) { global $wpdb, $category_cache, $cache_categories; @@ -1264,6 +1279,8 @@ function update_category_cache() { } function clean_user_cache($id) { + global $cache_userdata; + if ( isset( $cache_userdata[$id] ) ) unset( $cache_userdata[$id] ); }