From d271e5d3562c1cf51e5225a474b7f27d768824e6 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Mon, 2 Oct 2017 03:08:18 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@41665 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-blogs.php | 14 ++++++++++---- src/wp-includes/ms-default-filters.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index dc52292a3b..94c6bccf65 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -1285,7 +1285,7 @@ function _update_blog_date_on_post_delete( $post_id ) { function _update_posts_count_on_delete( $post_id ) { $post = get_post( $post_id ); - if ( ! $post || 'publish' !== $post->post_status ) { + if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { return; } @@ -1296,15 +1296,21 @@ function _update_posts_count_on_delete( $post_id ) { * Handler for updating the blog posts count date when a post status changes. * * @since 4.0.0 + * @since 4.9.0 Added the `$post` parameter. * - * @param string $new_status The status the post is changing to. - * @param string $old_status The status the post is changing from. + * @param string $new_status The status the post is changing to. + * @param string $old_status The status the post is changing from. + * @param WP_Post $post Post object */ -function _update_posts_count_on_transition_post_status( $new_status, $old_status ) { +function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) { if ( $new_status === $old_status ) { return; } + if ( 'post' !== get_post_type( $post ) ) { + return; + } + if ( 'publish' !== $new_status && 'publish' !== $old_status ) { return; } diff --git a/src/wp-includes/ms-default-filters.php b/src/wp-includes/ms-default-filters.php index 3d81e4cec7..fe66f0aa77 100644 --- a/src/wp-includes/ms-default-filters.php +++ b/src/wp-includes/ms-default-filters.php @@ -54,7 +54,7 @@ add_filter( 'term_id_filter', 'global_terms', 10, 2 ); add_action( 'delete_post', '_update_posts_count_on_delete' ); add_action( 'delete_post', '_update_blog_date_on_post_delete' ); add_action( 'transition_post_status', '_update_blog_date_on_post_publish', 10, 3 ); -add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 2 ); +add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 ); // Counts add_action( 'admin_init', 'wp_schedule_update_network_counts');