Ticket #40196: 40196.2.patch
File 40196.2.patch, 7.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-site-query.php
99 99 * Sets up the site query, based on the query vars passed. 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 * 104 105 * @param string|array $query { … … 138 139 * @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. 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'. 143 147 * Default empty array. … … 169 173 'mature' => null, 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(), 174 181 'count' => false, … … 471 478 $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public ); 472 479 } 473 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'] ) ) . ' )'; 494 } 495 474 496 // Falsey search strings are ignored. 475 497 if ( strlen( $this->query_vars['search'] ) ) { 476 498 $search_columns = array(); -
src/wp-includes/ms-blogs.php
574 574 * Retrieves a list of sites matching requested arguments. 575 575 * 576 576 * @since 4.6.0 577 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. 577 578 * 578 579 * @see WP_Site_Query::parse_query() 579 580 * … … 614 615 * @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. 615 616 * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. 616 617 * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. 618 * @type int $lang_id Limit results to a language ID. Default empty. 619 * @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. 620 * @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. 617 621 * @type string $search Search term(s) to retrieve matching sites for. Default empty. 618 622 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. 619 623 * Default empty array. -
tests/phpunit/tests/multisite/siteQuery.php
47 47 'www.w.org/' => array( 'domain' => 'www.w.org', 'path' => '/' ), 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 53 53 foreach ( self::$site_ids as &$id ) { … … 431 431 $this->assertEqualSets( array_values( self::$site_ids ), $found ); 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(); 436 522 $found = $q->query( array(