diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index e024789052..d209435fd3 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -2274,10 +2274,13 @@ function wp_schedule_update_network_counts() { * Update the network-wide counts for the current network. * * @since 3.1.0 + * @since 4.8.0 The $network_id parameter has been added. + * + * @param int|null $network_id ID of the network. Default is the current network. */ -function wp_update_network_counts() { - wp_update_network_user_counts(); - wp_update_network_site_counts(); +function wp_update_network_counts( $network_id = null ) { + wp_update_network_user_counts( $network_id ); + wp_update_network_site_counts( $network_id ); } /** diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php index 50c15d0393..71e3ed8ff7 100644 --- a/tests/phpunit/tests/multisite/network.php +++ b/tests/phpunit/tests/multisite/network.php @@ -440,6 +440,36 @@ class Tests_Multisite_Network extends WP_UnitTestCase { $result = get_user_count( self::$different_network_id ); $this->assertEquals( $expected, $result ); } + + /** + * @ticket 40386 + */ + public function test_wp_update_network_counts() { + delete_network_option( null, 'site_count' ); + delete_network_option( null, 'user_count' ); + + wp_update_network_counts(); + + $site_count = (int) get_blog_count(); + $user_count = (int) get_user_count(); + + $this->assertTrue( $site_count > 0 && $user_count > 0 ); + } + + /** + * @ticket 40386 + */ + public function test_wp_update_network_counts_on_different_network() { + delete_network_option( self::$different_network_id, 'site_count' ); + delete_network_option( self::$different_network_id, 'user_count' ); + + wp_update_network_counts( self::$different_network_id ); + + $site_count = (int) get_blog_count( self::$different_network_id ); + $user_count = (int) get_user_count( self::$different_network_id ); + + $this->assertTrue( $site_count > 0 && $user_count > 0 ); + } } endif;