Changeset 40590
- Timestamp:
- 05/09/2017 03:50:04 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ms-functions.php
r40589 r40590 2491 2491 * 2492 2492 * @since 3.3.0 2493 * @param string $using 'sites or 'users'. Default is 'sites'. 2493 * @since 4.8.0 The $network_id parameter has been added. 2494 * 2495 * @param string $using 'sites or 'users'. Default is 'sites'. 2496 * @param int|null $network_id ID of the network. Default is the current network. 2494 2497 * @return bool True if the network meets the criteria for large. False otherwise. 2495 2498 */ 2496 function wp_is_large_network( $using = 'sites' ) { 2499 function wp_is_large_network( $using = 'sites', $network_id = null ) { 2500 $network_id = (int) $network_id; 2501 if ( ! $network_id ) { 2502 $network_id = get_current_network_id(); 2503 } 2504 2497 2505 if ( 'users' == $using ) { 2498 $count = get_user_count( );2506 $count = get_user_count( $network_id ); 2499 2507 /** 2500 2508 * Filters whether the network is considered large. 2501 2509 * 2502 2510 * @since 3.3.0 2511 * @since 4.8.0 The $network_id parameter has been added. 2503 2512 * 2504 2513 * @param bool $is_large_network Whether the network has more than 10000 users or sites. 2505 2514 * @param string $component The component to count. Accepts 'users', or 'sites'. 2506 2515 * @param int $count The count of items for the component. 2516 * @param int $network_id The ID of the network being checked. 2507 2517 */ 2508 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count );2509 } 2510 2511 $count = get_blog_count( );2518 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id ); 2519 } 2520 2521 $count = get_blog_count( $network_id ); 2512 2522 /** This filter is documented in wp-includes/ms-functions.php */ 2513 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );2523 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id ); 2514 2524 } 2515 2525 -
trunk/tests/phpunit/tests/multisite/network.php
r40486 r40590 471 471 $this->assertTrue( $site_count > 0 && $user_count > 0 ); 472 472 } 473 474 /** 475 * @ticket 40489 476 * @dataProvider data_wp_is_large_network 477 */ 478 public function test_wp_is_large_network( $using, $count, $expected, $different_network ) { 479 $network_id = $different_network ? self::$different_network_id : null; 480 $network_option = 'users' === $using ? 'user_count' : 'blog_count'; 481 482 update_network_option( $network_id, $network_option, $count ); 483 484 $result = wp_is_large_network( $using, $network_id ); 485 if ( $expected ) { 486 $this->assertTrue( $result ); 487 } else { 488 $this->assertFalse( $result ); 489 } 490 } 491 492 public function data_wp_is_large_network() { 493 return array( 494 array( 'sites', 10000, false, false ), 495 array( 'sites', 10001, true, false ), 496 array( 'users', 10000, false, false ), 497 array( 'users', 10001, true, false ), 498 array( 'sites', 10000, false, true ), 499 array( 'sites', 10001, true, true ), 500 array( 'users', 10000, false, true ), 501 array( 'users', 10001, true, true ), 502 ); 503 } 504 505 /** 506 * @ticket 40489 507 * @dataProvider data_wp_is_large_network_filtered_by_component 508 */ 509 public function test_wp_is_large_network_filtered_by_component( $using, $count, $expected, $different_network ) { 510 $network_id = $different_network ? self::$different_network_id : null; 511 $network_option = 'users' === $using ? 'user_count' : 'blog_count'; 512 513 update_network_option( $network_id, $network_option, $count ); 514 515 add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10, 3 ); 516 $result = wp_is_large_network( $using, $network_id ); 517 remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10 ); 518 519 if ( $expected ) { 520 $this->assertTrue( $result ); 521 } else { 522 $this->assertFalse( $result ); 523 } 524 } 525 526 public function data_wp_is_large_network_filtered_by_component() { 527 return array( 528 array( 'sites', 10000, false, false ), 529 array( 'sites', 10001, true, false ), 530 array( 'users', 1000, false, false ), 531 array( 'users', 1001, true, false ), 532 array( 'sites', 10000, false, true ), 533 array( 'sites', 10001, true, true ), 534 array( 'users', 1000, false, true ), 535 array( 'users', 1001, true, true ), 536 ); 537 } 538 539 public function filter_wp_is_large_network_for_users( $is_large_network, $using, $count ) { 540 if ( 'users' === $using ) { 541 return $count > 1000; 542 } 543 544 return $is_large_network; 545 } 546 547 /** 548 * @ticket 40489 549 * @dataProvider data_wp_is_large_network_filtered_by_network 550 */ 551 public function test_wp_is_large_network_filtered_by_network( $using, $count, $expected, $different_network ) { 552 $network_id = $different_network ? self::$different_network_id : null; 553 $network_option = 'users' === $using ? 'user_count' : 'blog_count'; 554 555 update_network_option( $network_id, $network_option, $count ); 556 557 add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10, 4 ); 558 $result = wp_is_large_network( $using, $network_id ); 559 remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10 ); 560 561 if ( $expected ) { 562 $this->assertTrue( $result ); 563 } else { 564 $this->assertFalse( $result ); 565 } 566 } 567 568 public function data_wp_is_large_network_filtered_by_network() { 569 return array( 570 array( 'sites', 10000, false, false ), 571 array( 'sites', 10001, true, false ), 572 array( 'users', 10000, false, false ), 573 array( 'users', 10001, true, false ), 574 array( 'sites', 1000, false, true ), 575 array( 'sites', 1001, true, true ), 576 array( 'users', 1000, false, true ), 577 array( 'users', 1001, true, true ), 578 ); 579 } 580 581 public function filter_wp_is_large_network_on_different_network( $is_large_network, $using, $count, $network_id ) { 582 if ( $network_id === (int) self::$different_network_id ) { 583 return $count > 1000; 584 } 585 586 return $is_large_network; 587 } 473 588 } 474 589
Note: See TracChangeset
for help on using the changeset viewer.