Make WordPress Core

Changeset 41665


Ignore:
Timestamp:
10/02/2017 03:08:18 AM (7 years ago)
Author:
jeremyfelt
Message:

Multisite: Only update a site's post count when post types of post are updated.

Previously, the query to update the count of published posts would run every time any post type transitioned between a publish/non-published status or was deleted.

Props sboisvert, JPry, spacedmonkey.
Fixes #42021.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-blogs.php

    r41661 r41665  
    12861286    $post = get_post( $post_id );
    12871287
    1288     if ( ! $post || 'publish' !== $post->post_status ) {
     1288    if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) {
    12891289        return;
    12901290    }
     
    12971297 *
    12981298 * @since 4.0.0
    1299  *
    1300  * @param string $new_status The status the post is changing to.
    1301  * @param string $old_status The status the post is changing from.
    1302  */
    1303 function _update_posts_count_on_transition_post_status( $new_status, $old_status ) {
     1299 * @since 4.9.0 Added the `$post` parameter.
     1300 *
     1301 * @param string  $new_status The status the post is changing to.
     1302 * @param string  $old_status The status the post is changing from.
     1303 * @param WP_Post $post       Post object
     1304 */
     1305function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) {
    13041306    if ( $new_status === $old_status ) {
    13051307        return;
    13061308    }
    13071309
     1310    if ( 'post' !== get_post_type( $post ) ) {
     1311        return;
     1312    }
     1313
    13081314    if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
    13091315        return;
  • trunk/src/wp-includes/ms-default-filters.php

    r41625 r41665  
    5555add_action( 'delete_post', '_update_blog_date_on_post_delete' );
    5656add_action( 'transition_post_status', '_update_blog_date_on_post_publish', 10, 3 );
    57 add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 2 );
     57add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
    5858
    5959// Counts
Note: See TracChangeset for help on using the changeset viewer.