Make WordPress Core

Ticket #27952: 27952.2.diff

File 27952.2.diff, 2.6 KB (added by strangerstudios, 10 years ago)

Fixing update_post_count for multisite.

  • wp-includes/ms-functions.php

     
    17611761 * WordPress MS stores a blog's post count as an option so as
    17621762 * to avoid extraneous COUNTs when a blog's details are fetched
    17631763 * with get_blog_details(). This function is called when posts
    1764  * are published to make sure the count stays current.
     1764 * are published or unpublished to make sure the count stays current.
    17651765 *
    17661766 * @since MU
    17671767 */
  • wp-includes/ms-default-filters.php

     
    3434
    3535// Administration
    3636add_filter( 'term_id_filter', 'global_terms', 10, 2 );
    37 add_action( 'publish_post', 'update_posts_count' );
     37add_action( 'delete_post', '_update_posts_count_on_delete' );
    3838add_action( 'delete_post', '_update_blog_date_on_post_delete' );
    3939add_action( 'transition_post_status', '_update_blog_date_on_post_publish', 10, 3 );
     40add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 2 );
    4041
    4142// Counts
    4243add_action( 'admin_init', 'wp_schedule_update_network_counts');
  • wp-includes/ms-blogs.php

     
    892892        wpmu_update_blogs_date();
    893893}
    894894
     895/**
     896 * Handler for updating the blog posts count date when a post is deleted.
     897 *
     898 * @since 4.0
     899 *
     900 * @param int $post_id Post ID
     901 */
     902function _update_posts_count_on_delete($post_id)
     903{
     904        //First check if this was a published post.
     905        $post = get_post($post_id);
     906        if($post->post_status != "publish")
     907                return;
     908
     909        //Must be pusblished. Update the posts count.
     910        update_posts_count();
     911}
     912
     913/**
     914 * Handler for updating the blog posts count date when a post status changes.
     915 *
     916 * @since 4.0
     917 *
     918 * @param string $new_status The status the post is changing to.
     919 * @param string $old_status The status the post is changing from.
     920 */
     921function _update_posts_count_on_transition_post_status($new_status, $old_status)
     922{
     923        //If the status isn't really changing, we don't need to update the count.
     924        if($new_status == $old_status)
     925                return;
     926
     927        //If neither the new or old status is publish, we don't need to update the count.
     928        if($new_status != "publish" && $old_status != "publish")
     929                return;
     930
     931        //Okay. Update the posts count.
     932        update_posts_count();
     933}
     934