From 9d2d5b536de7c8a959768367d2d18936d68824c5 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 10 May 2017 23:21:43 +0000 Subject: [PATCH] Multisite: Adjust site count of the correct network after having created a new site. Prior to this change, after creating a site, the network site count was always refreshed on the current network, regardless of whether the site was created on a different network. With the recent changes, particularly [40591], it is now possible to update the site count for a specific `$network_id`, so this changeset makes use of the new parameter. Fixes #38699. git-svn-id: https://develop.svn.wordpress.org/trunk@40612 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 2 +- tests/phpunit/tests/multisite/network.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 16cb294359..20a183d7da 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -1375,7 +1375,7 @@ function insert_blog($domain, $path, $site_id) { $blog_id = $wpdb->insert_id; refresh_blog_details( $blog_id ); - wp_maybe_update_network_site_counts(); + wp_maybe_update_network_site_counts( $site_id ); return $blog_id; } diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php index b1830d2329..6c6d51190b 100644 --- a/tests/phpunit/tests/multisite/network.php +++ b/tests/phpunit/tests/multisite/network.php @@ -585,6 +585,25 @@ class Tests_Multisite_Network extends WP_UnitTestCase { return $is_large_network; } + + /** + * @ticket 38699 + */ + public function test_wpmu_create_blog_updates_correct_network_site_count() { + $original_count = get_blog_count( self::$different_network_id ); + + $site_id = self::factory()->blog->create( array( + 'domain' => 'example.org', + 'path' => '/', + 'site_id' => self::$different_network_id, + ) ); + + $result = get_blog_count( self::$different_network_id ); + + wpmu_delete_blog( $site_id, true ); + + $this->assertEquals( $original_count + 1, $result ); + } } endif;