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
This commit is contained in:
Jeremy Felt
2017-10-02 03:08:18 +00:00
parent e7c17229df
commit d271e5d356
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -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;
}
+1 -1
View File
@@ -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');