Make WordPress Core

Ticket #37528: 37528.diff

File 37528.diff, 2.2 KB (added by flixos90, 8 years ago)
  • src/wp-includes/ms-functions.php

     
    23292329 * Update the network-wide site count.
    23302330 *
    23312331 * @since 3.7.0
     2332 * @since 4.8.0 The $network_id parameter has been added.
    23322333 *
    2333  * @global wpdb $wpdb WordPress database abstraction object.
     2334 * @param int|null $network_id ID of the network. Default is the current network.
    23342335 */
    2335 function wp_update_network_site_counts() {
    2336         global $wpdb;
     2336function wp_update_network_site_counts( $network_id = null ) {
     2337        $network_id = (int) $network_id;
     2338        if ( ! $network_id ) {
     2339                $network_id = get_current_network_id();
     2340        }
    23372341
    23382342        $count = get_sites( array(
    2339                 'network_id' => $wpdb->siteid,
     2343                'network_id' => $network_id,
    23402344                'spam'       => 0,
    23412345                'deleted'    => 0,
    23422346                'archived'   => 0,
    23432347                'count'      => true,
    23442348        ) );
    23452349
    2346         update_site_option( 'blog_count', $count );
     2350        update_network_option( $network_id, 'blog_count', $count );
    23472351}
    23482352
    23492353/**
  • tests/phpunit/tests/multisite/network.php

     
    376376                $dashboard_blog = get_dashboard_blog();
    377377                $this->assertEquals( $blog_id, $dashboard_blog->blog_id );
    378378        }
     379
     380        /**
     381         * @ticket 37528
     382         */
     383        function test_wp_update_network_site_counts() {
     384                update_network_option( null, 'blog_count', 40 );
     385
     386                $expected = get_sites( array(
     387                        'network_id' => get_current_network_id(),
     388                        'spam'       => 0,
     389                        'deleted'    => 0,
     390                        'archived'   => 0,
     391                        'count'      => true,
     392                ) );
     393
     394                wp_update_network_site_counts();
     395
     396                $result = get_blog_count();
     397                $this->assertEquals( $expected, $result );
     398        }
     399
     400        /**
     401         * @ticket 37528
     402         */
     403        function test_wp_update_network_site_counts_on_different_network() {
     404                update_network_option( self::$different_network_id, 'blog_count', 40 );
     405
     406                wp_update_network_site_counts( self::$different_network_id );
     407
     408                $result = get_blog_count( self::$different_network_id );
     409                $this->assertEquals( 3, $result );
     410        }
    379411}
    380412
    381413endif;