Make WordPress Core


Ignore:
Timestamp:
03/27/2017 07:47:53 PM (8 years ago)
Author:
jeremyfelt
Message:

Multisite: Add lang_id support to WP_Site_Query.

Sites can now be queried by lang_id, lang__in, and lang__not_in.

Props ocean90.
Fixes #40196.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-site-query.php

    r38849 r40340  
    100100     *
    101101     * @since 4.6.0
     102     * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
    102103     * @access public
    103104     *
     
    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.
     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.
    141145     *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
    142146     *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
     
    170174            'spam'              => null,
    171175            'deleted'           => null,
     176            'lang_id'           => null,
     177            'lang__in'          => '',
     178            'lang__not_in'      => '',
    172179            'search'            => '',
    173180            'search_columns'    => array(),
     
    470477            $public = absint( $this->query_vars['public'] );
    471478            $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'] ) ) . ' )';
    472494        }
    473495
Note: See TracChangeset for help on using the changeset viewer.