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. Built from https://develop.svn.wordpress.org/trunk@40340 git-svn-id: http://core.svn.wordpress.org/trunk@40247 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
36aa674859
commit
f940beae2b
|
@ -99,6 +99,7 @@ class WP_Site_Query {
|
||||||
* Sets up the site query, based on the query vars passed.
|
* Sets up the site query, based on the query vars passed.
|
||||||
*
|
*
|
||||||
* @since 4.6.0
|
* @since 4.6.0
|
||||||
|
* @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
* @param string|array $query {
|
* @param string|array $query {
|
||||||
|
@ -138,6 +139,9 @@ class WP_Site_Query {
|
||||||
* @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty.
|
* @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty.
|
||||||
* @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty.
|
* @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty.
|
||||||
* @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty.
|
* @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty.
|
||||||
|
* @type int $lang_id Limit results to a language ID. Default empty.
|
||||||
|
* @type array $lang__in Array of language IDs to include affiliated sites for. Default empty.
|
||||||
|
* @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty.
|
||||||
* @type string $search Search term(s) to retrieve matching sites for. Default empty.
|
* @type string $search Search term(s) to retrieve matching sites for. Default empty.
|
||||||
* @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'.
|
* @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'.
|
||||||
* Default empty array.
|
* Default empty array.
|
||||||
|
@ -169,6 +173,9 @@ class WP_Site_Query {
|
||||||
'mature' => null,
|
'mature' => null,
|
||||||
'spam' => null,
|
'spam' => null,
|
||||||
'deleted' => null,
|
'deleted' => null,
|
||||||
|
'lang_id' => null,
|
||||||
|
'lang__in' => '',
|
||||||
|
'lang__not_in' => '',
|
||||||
'search' => '',
|
'search' => '',
|
||||||
'search_columns' => array(),
|
'search_columns' => array(),
|
||||||
'count' => false,
|
'count' => false,
|
||||||
|
@ -471,6 +478,21 @@ class WP_Site_Query {
|
||||||
$this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public );
|
$this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( is_numeric( $this->query_vars['lang_id'] ) ) {
|
||||||
|
$lang_id = absint( $this->query_vars['lang_id'] );
|
||||||
|
$this->sql_clauses['where']['lang_id'] = $wpdb->prepare( "lang_id = %d ", $lang_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse site language IDs for an IN clause.
|
||||||
|
if ( ! empty( $this->query_vars['lang__in'] ) ) {
|
||||||
|
$this->sql_clauses['where']['lang__in'] = 'lang_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__in'] ) ) . ' )';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse site language IDs for a NOT IN clause.
|
||||||
|
if ( ! empty( $this->query_vars['lang__not_in'] ) ) {
|
||||||
|
$this->sql_clauses['where']['lang__not_in'] = 'lang_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__not_in'] ) ) . ' )';
|
||||||
|
}
|
||||||
|
|
||||||
// Falsey search strings are ignored.
|
// Falsey search strings are ignored.
|
||||||
if ( strlen( $this->query_vars['search'] ) ) {
|
if ( strlen( $this->query_vars['search'] ) ) {
|
||||||
$search_columns = array();
|
$search_columns = array();
|
||||||
|
|
|
@ -573,6 +573,7 @@ function update_site_cache( $sites ) {
|
||||||
* Retrieves a list of sites matching requested arguments.
|
* Retrieves a list of sites matching requested arguments.
|
||||||
*
|
*
|
||||||
* @since 4.6.0
|
* @since 4.6.0
|
||||||
|
* @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
|
||||||
*
|
*
|
||||||
* @see WP_Site_Query::parse_query()
|
* @see WP_Site_Query::parse_query()
|
||||||
*
|
*
|
||||||
|
@ -613,6 +614,9 @@ function update_site_cache( $sites ) {
|
||||||
* @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty.
|
* @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty.
|
||||||
* @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty.
|
* @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty.
|
||||||
* @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty.
|
* @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty.
|
||||||
|
* @type int $lang_id Limit results to a language ID. Default empty.
|
||||||
|
* @type array $lang__in Array of language IDs to include affiliated sites for. Default empty.
|
||||||
|
* @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty.
|
||||||
* @type string $search Search term(s) to retrieve matching sites for. Default empty.
|
* @type string $search Search term(s) to retrieve matching sites for. Default empty.
|
||||||
* @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'.
|
* @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'.
|
||||||
* Default empty array.
|
* Default empty array.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.8-alpha-40339';
|
$wp_version = '4.8-alpha-40340';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue