From 78880a6a0b5dee02e3211e2c507f28c60b1acff8 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Mon, 2 Oct 2017 03:09:44 +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. Built from https://develop.svn.wordpress.org/trunk@41665 git-svn-id: http://core.svn.wordpress.org/trunk@41499 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/ms-blogs.php | 14 ++++++++++---- wp-includes/ms-default-filters.php | 2 +- wp-includes/version.php | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index dc52292a3b..94c6bccf65 100644 --- a/wp-includes/ms-blogs.php +++ b/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/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php index 3d81e4cec7..fe66f0aa77 100644 --- a/wp-includes/ms-default-filters.php +++ b/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'); diff --git a/wp-includes/version.php b/wp-includes/version.php index 6c9a9eb279..807300c3f4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-41664'; +$wp_version = '4.9-alpha-41665'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.