From f940beae2b86b2faf212a31f7d495d5587996286 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Mon, 27 Mar 2017 19:48:52 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-site-query.php | 22 ++++++++++++++++++++++ wp-includes/ms-blogs.php | 4 ++++ wp-includes/version.php | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-site-query.php b/wp-includes/class-wp-site-query.php index 8f52372d3b..b711422479 100644 --- a/wp-includes/class-wp-site-query.php +++ b/wp-includes/class-wp-site-query.php @@ -99,6 +99,7 @@ class WP_Site_Query { * Sets up the site query, based on the query vars passed. * * @since 4.6.0 + * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. * @access public * * @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 $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 $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 array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. * Default empty array. @@ -169,6 +173,9 @@ class WP_Site_Query { 'mature' => null, 'spam' => null, 'deleted' => null, + 'lang_id' => null, + 'lang__in' => '', + 'lang__not_in' => '', 'search' => '', 'search_columns' => array(), 'count' => false, @@ -471,6 +478,21 @@ class WP_Site_Query { $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. if ( strlen( $this->query_vars['search'] ) ) { $search_columns = array(); diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index cf34289a44..4f0e26085a 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -573,6 +573,7 @@ function update_site_cache( $sites ) { * Retrieves a list of sites matching requested arguments. * * @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() * @@ -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 $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 $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 array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. * Default empty array. diff --git a/wp-includes/version.php b/wp-includes/version.php index 1858631936..c4b6da6bbd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @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.