Changeset 46251
- Timestamp:
- 09/23/2019 05:34:20 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/network/sites.php
r46211 r46251 370 370 <hr class="wp-header-end"> 371 371 372 <?php $wp_list_table->views(); ?> 373 372 374 <?php echo $msg; ?> 373 375 -
trunk/src/wp-includes/ms-blogs.php
r45794 r46251 854 854 update_posts_count(); 855 855 } 856 857 /** 858 * Count number of sites grouped by site status. 859 * 860 * @since 5.3.0 861 * 862 * @param int $network_id The network to get counts for. Default is the current network id. 863 * @return array Includes a grand total 'all' and an array of counts indexed by 864 * status strings: public, archived, mature, spam, deleted. 865 */ 866 function wp_count_sites( $network_id = null ) { 867 if ( empty( $network_id ) ) { 868 $network_id = get_current_network_id(); 869 } 870 871 $counts = array(); 872 $args = array( 873 'network_id' => $network_id, 874 'number' => 1, 875 'fields' => 'ids', 876 'no_found_rows' => false, 877 ); 878 879 $q = new WP_Site_Query( $args ); 880 $counts['all'] = $q->found_sites; 881 882 $_args = $args; 883 $statuses = array( 'public', 'archived', 'mature', 'spam', 'deleted' ); 884 885 foreach ( $statuses as $status ) { 886 $_args = $args; 887 $_args[ $status ] = 1; 888 889 $q = new WP_Site_Query( $_args ); 890 $counts[ $status ] = $q->found_sites; 891 } 892 893 return $counts; 894 } -
trunk/tests/phpunit/tests/multisite.php
r45607 r46251 35 35 $this->assertEquals( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] ); 36 36 } 37 38 /** 39 * @ticket 37392 40 */ 41 function test_wp_count_sites() { 42 // create a random number of sites with each status. 43 $site_ids = array( 44 'public' => self::factory()->blog->create_many( 45 random_int( 0, 5 ), 46 array( 'meta' => array( 'public' => 1 ) ) 47 ), 48 'archived' => self::factory()->blog->create_many( 49 random_int( 0, 5 ), 50 array( 'meta' => array( 'archived' => 1 ) ) 51 ), 52 'mature' => self::factory()->blog->create_many( 53 random_int( 0, 5 ), 54 array( 'meta' => array( 'mature' => 1 ) ) 55 ), 56 'spam' => self::factory()->blog->create_many( 57 random_int( 0, 5 ), 58 array( 'meta' => array( 'spam' => 1 ) ) 59 ), 60 'deleted' => self::factory()->blog->create_many( 61 random_int( 0, 5 ), 62 array( 'meta' => array( 'deleted' => 1 ) ) 63 ), 64 ); 65 66 $counts = wp_count_sites(); 67 68 $counts_by_status = array_map( 'count', $site_ids ); 69 $expected = array_merge( 70 array( 'all' => array_sum( $counts_by_status ) ), 71 $counts_by_status 72 ); 73 // add 1 to all & public for the main site. 74 $expected['all'] += 1; 75 $expected['public'] += 1; 76 77 $this->assertEquals( $expected, $counts ); 78 } 37 79 } 38 80
Note: See TracChangeset
for help on using the changeset viewer.