From 7966b89e291addd56d0d85d8e4e480561faad106 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 20 Apr 2017 00:26:30 +0000 Subject: [PATCH] Multisite: Add `$network_id` parameter to `wp_update_network_counts()`. After the `$network_id` parameter has been introduced for `wp_update_network_site_counts()` in [40484] and `wp_update_network_user_counts()` in [40485], the new parameter can now also be used on the wrapping function. Fixes #40386. See #38699. git-svn-id: https://develop.svn.wordpress.org/trunk@40486 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 9 ++++--- tests/phpunit/tests/multisite/network.php | 30 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) 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;