Make WordPress Core

Ticket #40196: 40196.patch

File 40196.patch, 4.5 KB (added by ocean90, 8 years ago)
  • src/wp-includes/class-wp-site-query.php

     
    9999         * Sets up the site query, based on the query vars passed.
    100100         *
    101101         * @since 4.6.0
     102         * @since 4.8.0 Introduced 'lang_id' parameter.
    102103         * @access public
    103104         *
    104105         * @param string|array $query {
     
    138139         *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
    139140         *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
    140141         *     @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.
    141143         *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
    142144         *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
    143145         *                                           Default empty array.
     
    169171                        'mature'            => null,
    170172                        'spam'              => null,
    171173                        'deleted'           => null,
     174                        'lang_id'           => null,
    172175                        'search'            => '',
    173176                        'search_columns'    => array(),
    174177                        'count'             => false,
     
    471474                        $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public );
    472475                }
    473476
     477                if ( is_numeric( $this->query_vars['lang_id'] ) ) {
     478                        $lang_id = absint( $this->query_vars['lang_id'] );
     479                        $this->sql_clauses['where']['lang_id'] = $wpdb->prepare( "lang_id = %d ", $lang_id );
     480                }
     481
    474482                // Falsey search strings are ignored.
    475483                if ( strlen( $this->query_vars['search'] ) ) {
    476484                        $search_columns = array();
  • src/wp-includes/ms-blogs.php

     
    556556 * Retrieves a list of sites matching requested arguments.
    557557 *
    558558 * @since 4.6.0
     559 * @since 4.8.0 Introduced 'lang_id' parameter.
    559560 *
    560561 * @see WP_Site_Query::parse_query()
    561562 *
     
    596597 *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
    597598 *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
    598599 *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
     600 *     @type int          $lang_id           Limit results to a language ID. Default empty.
    599601 *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
    600602 *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
    601603 *                                           Default empty array.
  • tests/phpunit/tests/multisite/siteQuery.php

     
    431431                $this->assertEqualSets( array_values( self::$site_ids ), $found );
    432432        }
    433433
     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_values( self::$site_ids ), $found );
     444        }
     445
     446        public function test_wp_site_query_by_lang_id() {
     447                update_blog_details(
     448                        self::$site_ids['www.w.org/make/'],
     449                        array(
     450                                'lang_id' => 1,
     451                        )
     452                );
     453
     454                $q = new WP_Site_Query();
     455                $found = $q->query( array(
     456                        'fields'       => 'ids',
     457                        'lang_id'      => 1,
     458                ) );
     459
     460                update_blog_details(
     461                        self::$site_ids['www.w.org/make/'],
     462                        array(
     463                                'lang_id' => 0,
     464                        )
     465                );
     466
     467                $expected = array(
     468                        self::$site_ids['www.w.org/make/'],
     469                );
     470
     471                $this->assertEqualSets( $expected, $found );
     472        }
     473
     474        public function test_wp_site_query_by_lang_id_with_no_results() {
     475                $q = new WP_Site_Query();
     476                $found = $q->query( array(
     477                        'fields'       => 'ids',
     478                        'lang_id'      => 2,
     479                ) );
     480
     481                $this->assertEmpty( $found );
     482        }
     483
    434484        public function test_wp_site_query_by_search_with_text_in_domain() {
    435485                $q = new WP_Site_Query();
    436486                $found = $q->query( array(