Make WordPress Core


Ignore:
Timestamp:
04/20/2017 12:13:41 AM (9 years ago)
Author:
flixos90
Message:

Multisite: Add $network_id parameter to wp_update_network_user_counts().

Using the new parameter, it is now possible to update the user count on a network different from the current one. While the count itself is technically a global user count and not network-wide, it is stored on each individual network, and the new parameter provides more control about where to update the count.

Fixes #40349. See #38699.

File:
1 edited

Legend:

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

    r40484 r40485  
    409409                $this->assertEquals( 3, $result );
    410410        }
     411
     412        /**
     413         * @ticket 40349
     414         */
     415        public function test_wp_update_network_user_counts() {
     416                global $wpdb;
     417
     418                update_network_option( null, 'user_count', 40 );
     419
     420                $expected = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
     421
     422                wp_update_network_user_counts();
     423
     424                $result = get_user_count();
     425                $this->assertEquals( $expected, $result );
     426        }
     427
     428        /**
     429         * @ticket 40349
     430         */
     431        public function test_wp_update_network_user_counts_on_different_network() {
     432                global $wpdb;
     433
     434                update_network_option( self::$different_network_id, 'user_count', 40 );
     435
     436                $expected = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
     437
     438                wp_update_network_user_counts( self::$different_network_id );
     439
     440                $result = get_user_count( self::$different_network_id );
     441                $this->assertEquals( $expected, $result );
     442        }
    411443}
    412444
Note: See TracChangeset for help on using the changeset viewer.