Changeset 40340
- Timestamp:
- 03/27/2017 07:47:53 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-site-query.php
r38849 r40340 100 100 * 101 101 * @since 4.6.0 102 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. 102 103 * @access public 103 104 * … … 139 140 * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. 140 141 * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. 142 * @type int $lang_id Limit results to a language ID. Default empty. 143 * @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. 144 * @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. 141 145 * @type string $search Search term(s) to retrieve matching sites for. Default empty. 142 146 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. … … 170 174 'spam' => null, 171 175 'deleted' => null, 176 'lang_id' => null, 177 'lang__in' => '', 178 'lang__not_in' => '', 172 179 'search' => '', 173 180 'search_columns' => array(), … … 470 477 $public = absint( $this->query_vars['public'] ); 471 478 $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public ); 479 } 480 481 if ( is_numeric( $this->query_vars['lang_id'] ) ) { 482 $lang_id = absint( $this->query_vars['lang_id'] ); 483 $this->sql_clauses['where']['lang_id'] = $wpdb->prepare( "lang_id = %d ", $lang_id ); 484 } 485 486 // Parse site language IDs for an IN clause. 487 if ( ! empty( $this->query_vars['lang__in'] ) ) { 488 $this->sql_clauses['where']['lang__in'] = 'lang_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__in'] ) ) . ' )'; 489 } 490 491 // Parse site language IDs for a NOT IN clause. 492 if ( ! empty( $this->query_vars['lang__not_in'] ) ) { 493 $this->sql_clauses['where']['lang__not_in'] = 'lang_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__not_in'] ) ) . ' )'; 472 494 } 473 495 -
trunk/src/wp-includes/ms-blogs.php
r40333 r40340 574 574 * 575 575 * @since 4.6.0 576 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. 576 577 * 577 578 * @see WP_Site_Query::parse_query() … … 614 615 * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. 615 616 * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. 617 * @type int $lang_id Limit results to a language ID. Default empty. 618 * @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. 619 * @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. 616 620 * @type string $search Search term(s) to retrieve matching sites for. Default empty. 617 621 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. -
trunk/tests/phpunit/tests/multisite/siteQuery.php
r38085 r40340 48 48 'www.w.org/foo/' => array( 'domain' => 'www.w.org', 'path' => '/foo/' ), 49 49 'www.w.org/foo/bar/' => array( 'domain' => 'www.w.org', 'path' => '/foo/bar/' ), 50 'www.w.org/make/' => array( 'domain' => 'www.w.org', 'path' => '/make/' ),50 'www.w.org/make/' => array( 'domain' => 'www.w.org', 'path' => '/make/', 'meta' => array( 'public' => 1, 'lang_id' => 1 ) ), 51 51 ); 52 52 … … 432 432 } 433 433 434 public function test_wp_site_query_by_lang_id_with_zero() { 435 $q = new WP_Site_Query(); 436 $found = $q->query( array( 437 'fields' => 'ids', 438 // Exclude main site since we don't have control over it here. 439 'site__not_in' => array( 1 ), 440 'lang_id' => 0, 441 ) ); 442 443 $this->assertEqualSets( array_diff( array_values( self::$site_ids ), array( self::$site_ids['www.w.org/make/'] ) ), $found ); 444 } 445 446 public function test_wp_site_query_by_lang_id() { 447 $q = new WP_Site_Query(); 448 $found = $q->query( array( 449 'fields' => 'ids', 450 'lang_id' => 1, 451 ) ); 452 453 $expected = array( 454 self::$site_ids['www.w.org/make/'], 455 ); 456 457 $this->assertEqualSets( $expected, $found ); 458 } 459 460 public function test_wp_site_query_by_lang_id_with_no_results() { 461 $q = new WP_Site_Query(); 462 $found = $q->query( array( 463 'fields' => 'ids', 464 'lang_id' => 2, 465 ) ); 466 467 $this->assertEmpty( $found ); 468 } 469 470 public function test_wp_site_query_by_lang__in() { 471 $q = new WP_Site_Query(); 472 $found = $q->query( array( 473 'fields' => 'ids', 474 'lang__in' => array( 1 ), 475 ) ); 476 477 $expected = array( 478 self::$site_ids['www.w.org/make/'], 479 ); 480 481 $this->assertEqualSets( $expected, $found ); 482 } 483 484 public function test_wp_site_query_by_lang__in_with_multiple_ids() { 485 $q = new WP_Site_Query(); 486 $found = $q->query( array( 487 'fields' => 'ids', 488 // Exclude main site since we don't have control over it here. 489 'site__not_in' => array( 1 ), 490 'lang__in' => array( 0, 1 ), 491 ) ); 492 493 $this->assertEqualSets( array_values( self::$site_ids ), $found ); 494 } 495 496 public function test_wp_site_query_by_lang__not_in() { 497 $q = new WP_Site_Query(); 498 $found = $q->query( array( 499 'fields' => 'ids', 500 'lang__not_in' => array( 0 ), 501 ) ); 502 503 $expected = array( 504 self::$site_ids['www.w.org/make/'], 505 ); 506 507 $this->assertEqualSets( $expected, $found ); 508 } 509 510 public function test_wp_site_query_by_lang__not_in_with_multiple_ids() { 511 $q = new WP_Site_Query(); 512 $found = $q->query( array( 513 'fields' => 'ids', 514 'lang__not_in' => array( 0, 1 ), 515 ) ); 516 517 $this->assertEmpty( $found ); 518 } 519 434 520 public function test_wp_site_query_by_search_with_text_in_domain() { 435 521 $q = new WP_Site_Query();
Note: See TracChangeset
for help on using the changeset viewer.