--- a/wp/wp-includes/class-wp-network-query.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/class-wp-network-query.php Mon Oct 14 18:28:13 2019 +0200
@@ -91,25 +91,25 @@
*
* @type array $network__in Array of network IDs to include. Default empty.
* @type array $network__not_in Array of network IDs to exclude. Default empty.
- * @type bool $count Whether to return a network count (true) or array of network objects.
- * Default false.
- * @type string $fields Network fields to return. Accepts 'ids' (returns an array of network IDs)
- * or empty (returns an array of complete network objects). Default empty.
- * @type int $number Maximum number of networks to retrieve. Default empty (no limit).
- * @type int $offset Number of networks to offset the query. Used to build LIMIT clause.
- * Default 0.
- * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
- * @type string|array $orderby Network status or array of statuses. Accepts 'id', 'domain', 'path',
- * 'domain_length', 'path_length' and 'network__in'. Also accepts false,
- * an empty array, or 'none' to disable `ORDER BY` clause. Default 'id'.
- * @type string $order How to order retrieved networks. Accepts 'ASC', 'DESC'. Default 'ASC'.
- * @type string $domain Limit results to those affiliated with a given domain. Default empty.
- * @type array $domain__in Array of domains to include affiliated networks for. Default empty.
- * @type array $domain__not_in Array of domains to exclude affiliated networks for. Default empty.
- * @type string $path Limit results to those affiliated with a given path. Default empty.
- * @type array $path__in Array of paths to include affiliated networks for. Default empty.
- * @type array $path__not_in Array of paths to exclude affiliated networks for. Default empty.
- * @type string $search Search term(s) to retrieve matching networks for. Default empty.
+ * @type bool $count Whether to return a network count (true) or array of network objects.
+ * Default false.
+ * @type string $fields Network fields to return. Accepts 'ids' (returns an array of network IDs)
+ * or empty (returns an array of complete network objects). Default empty.
+ * @type int $number Maximum number of networks to retrieve. Default empty (no limit).
+ * @type int $offset Number of networks to offset the query. Used to build LIMIT clause.
+ * Default 0.
+ * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
+ * @type string|array $orderby Network status or array of statuses. Accepts 'id', 'domain', 'path',
+ * 'domain_length', 'path_length' and 'network__in'. Also accepts false,
+ * an empty array, or 'none' to disable `ORDER BY` clause. Default 'id'.
+ * @type string $order How to order retrieved networks. Accepts 'ASC', 'DESC'. Default 'ASC'.
+ * @type string $domain Limit results to those affiliated with a given domain. Default empty.
+ * @type array $domain__in Array of domains to include affiliated networks for. Default empty.
+ * @type array $domain__not_in Array of domains to exclude affiliated networks for. Default empty.
+ * @type string $path Limit results to those affiliated with a given path. Default empty.
+ * @type array $path__in Array of paths to include affiliated networks for. Default empty.
+ * @type array $path__not_in Array of paths to exclude affiliated networks for. Default empty.
+ * @type string $search Search term(s) to retrieve matching networks for. Default empty.
* @type bool $update_network_cache Whether to prime the cache for found networks. Default true.
* }
*/
@@ -144,7 +144,6 @@
*
* @since 4.6.0
*
- *
* @param string|array $query WP_Network_Query arguments. See WP_Network_Query::__construct()
*/
public function parse_query( $query = '' ) {
@@ -198,32 +197,51 @@
*/
do_action_ref_array( 'pre_get_networks', array( &$this ) );
- // $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
- $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
-
- // Ignore the $fields argument as the queried result will be the same regardless.
- unset( $_args['fields'] );
+ $network_ids = null;
- $key = md5( serialize( $_args ) );
- $last_changed = wp_cache_get_last_changed( 'networks' );
+ /**
+ * Filter the sites array before the query takes place.
+ *
+ * Return a non-null value to bypass WordPress's default site queries.
+ *
+ *
+ * @since 5.2.0
+ *
+ * @param array|null $site_ids Return an array of site data to short-circuit WP's site query,
+ * or null to allow WP to run its normal queries.
+ * @param WP_Network_Query $this The WP_Network_Query instance, passed by reference.
+ */
+ $network_ids = apply_filters_ref_array( 'networks_pre_query', array( $network_ids, &$this ) );
- $cache_key = "get_network_ids:$key:$last_changed";
- $cache_value = wp_cache_get( $cache_key, 'networks' );
+ if ( null === $network_ids ) {
+
+ // $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
+ $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
- if ( false === $cache_value ) {
- $network_ids = $this->get_network_ids();
- if ( $network_ids ) {
- $this->set_found_networks();
- }
+ // Ignore the $fields argument as the queried result will be the same regardless.
+ unset( $_args['fields'] );
+
+ $key = md5( serialize( $_args ) );
+ $last_changed = wp_cache_get_last_changed( 'networks' );
+
+ $cache_key = "get_network_ids:$key:$last_changed";
+ $cache_value = wp_cache_get( $cache_key, 'networks' );
- $cache_value = array(
- 'network_ids' => $network_ids,
- 'found_networks' => $this->found_networks,
- );
- wp_cache_add( $cache_key, $cache_value, 'networks' );
- } else {
- $network_ids = $cache_value['network_ids'];
- $this->found_networks = $cache_value['found_networks'];
+ if ( false === $cache_value ) {
+ $network_ids = $this->get_network_ids();
+ if ( $network_ids ) {
+ $this->set_found_networks();
+ }
+
+ $cache_value = array(
+ 'network_ids' => $network_ids,
+ 'found_networks' => $this->found_networks,
+ );
+ wp_cache_add( $cache_key, $cache_value, 'networks' );
+ } else {
+ $network_ids = $cache_value['network_ids'];
+ $this->found_networks = $cache_value['found_networks'];
+ }
}
if ( $this->found_networks && $this->query_vars['number'] ) {
@@ -260,7 +278,7 @@
*
* @since 4.6.0
*
- * @param array $_networks An array of WP_Network objects.
+ * @param WP_Network[] $_networks An array of WP_Network objects.
* @param WP_Network_Query $this Current instance of WP_Network_Query (passed by reference).
*/
$_networks = apply_filters_ref_array( 'the_networks', array( $_networks, &$this ) );
@@ -301,10 +319,10 @@
if ( is_int( $_key ) ) {
$_orderby = $_value;
- $_order = $order;
+ $_order = $order;
} else {
$_orderby = $_key;
- $_order = $_value;
+ $_order = $_value;
}
$parsed = $this->parse_orderby( $_orderby );
@@ -328,6 +346,7 @@
$number = absint( $this->query_vars['number'] );
$offset = absint( $this->query_vars['offset'] );
+ $limits = '';
if ( ! empty( $number ) ) {
if ( $offset ) {
@@ -393,6 +412,8 @@
$where = implode( ' AND ', $this->sql_clauses['where'] );
+ $groupby = '';
+
$pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
/**
@@ -400,16 +421,16 @@
*
* @since 4.6.0
*
- * @param array $pieces A compacted array of network query clauses.
+ * @param string[] $pieces An associative array of network query clauses.
* @param WP_Network_Query $this Current instance of WP_Network_Query (passed by reference).
*/
$clauses = apply_filters_ref_array( 'networks_clauses', array( compact( $pieces ), &$this ) );
- $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
- $join = isset( $clauses['join'] ) ? $clauses['join'] : '';
- $where = isset( $clauses['where'] ) ? $clauses['where'] : '';
+ $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
+ $join = isset( $clauses['join'] ) ? $clauses['join'] : '';
+ $where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
- $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
+ $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
if ( $where ) {
@@ -479,8 +500,8 @@
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @param string $string Search string.
- * @param array $columns Columns to search.
+ * @param string $string Search string.
+ * @param string[] $columns Array of columns to search.
*
* @return string Search SQL.
*/
@@ -519,9 +540,9 @@
$parsed = false;
if ( $orderby == 'network__in' ) {
$network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) );
- $parsed = "FIELD( {$wpdb->site}.id, $network__in )";
+ $parsed = "FIELD( {$wpdb->site}.id, $network__in )";
} elseif ( $orderby == 'domain_length' || $orderby == 'path_length' ) {
- $field = substr( $orderby, 0, -7 );
+ $field = substr( $orderby, 0, -7 );
$parsed = "CHAR_LENGTH($wpdb->site.$field)";
} elseif ( in_array( $orderby, $allowed_keys ) ) {
$parsed = "$wpdb->site.$orderby";