WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/03/2017 11:31:33 PM (3 years ago)
Author:
flixos90
Message:

Multisite: Add $network_id parameter to get_user_count().

The get_user_count() function returns the number of active users on a network, which is stored in a user_count network option. Since get_network_option() supports retrieving options from other networks than the current one, get_user_count() can now make use of that feature.

Fixes #37866.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/network.php

    r40370 r40371  
    207207
    208208    /**
     209     * @ticket 37866
     210     */
     211    public function test_get_user_count_on_different_network() {
     212        global $current_site, $wpdb;
     213
     214        wp_update_network_user_counts();
     215        $current_network_user_count = get_user_count();
     216
     217        // switch_to_network()...
     218        $orig_network_id = $current_site->id;
     219        $orig_wpdb_network_id = $wpdb->siteid;
     220        $current_site->id = self::$different_network_id;
     221        $wpdb->siteid = self::$different_network_id;
     222
     223        // Add another user to fake the network user count to be different.
     224        wpmu_create_user( 'user', 'pass', 'email' );
     225
     226        wp_update_network_user_counts();
     227
     228        // restore_current_network()...
     229        $current_site->id = $orig_network_id;
     230        $wpdb->siteid = $orig_wpdb_network_id;
     231
     232        $user_count = get_user_count( self::$different_network_id );
     233
     234        $this->assertEquals( $current_network_user_count + 1, $user_count );
     235    }
     236
     237    /**
    209238     * @ticket 22917
    210239     */
Note: See TracChangeset for help on using the changeset viewer.