wp/wp-includes/class-wp-network-query.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   156 		/**
   156 		/**
   157 		 * Fires after the network query vars have been parsed.
   157 		 * Fires after the network query vars have been parsed.
   158 		 *
   158 		 *
   159 		 * @since 4.6.0
   159 		 * @since 4.6.0
   160 		 *
   160 		 *
   161 		 * @param WP_Network_Query $this The WP_Network_Query instance (passed by reference).
   161 		 * @param WP_Network_Query $query The WP_Network_Query instance (passed by reference).
   162 		 */
   162 		 */
   163 		do_action_ref_array( 'parse_network_query', array( &$this ) );
   163 		do_action_ref_array( 'parse_network_query', array( &$this ) );
   164 	}
   164 	}
   165 
   165 
   166 	/**
   166 	/**
   191 		/**
   191 		/**
   192 		 * Fires before networks are retrieved.
   192 		 * Fires before networks are retrieved.
   193 		 *
   193 		 *
   194 		 * @since 4.6.0
   194 		 * @since 4.6.0
   195 		 *
   195 		 *
   196 		 * @param WP_Network_Query $this Current instance of WP_Network_Query (passed by reference).
   196 		 * @param WP_Network_Query $query Current instance of WP_Network_Query (passed by reference).
   197 		 */
   197 		 */
   198 		do_action_ref_array( 'pre_get_networks', array( &$this ) );
   198 		do_action_ref_array( 'pre_get_networks', array( &$this ) );
   199 
   199 
   200 		$network_data = null;
   200 		$network_data = null;
   201 
   201 
   240 		}
   240 		}
   241 
   241 
   242 		// $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
   242 		// $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
   243 		$_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
   243 		$_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
   244 
   244 
   245 		// Ignore the $fields argument as the queried result will be the same regardless.
   245 		// Ignore the $fields, $update_network_cache arguments as the queried result will be the same regardless.
   246 		unset( $_args['fields'] );
   246 		unset( $_args['fields'], $_args['update_network_cache'] );
   247 
   247 
   248 		$key          = md5( serialize( $_args ) );
   248 		$key          = md5( serialize( $_args ) );
   249 		$last_changed = wp_cache_get_last_changed( 'networks' );
   249 		$last_changed = wp_cache_get_last_changed( 'networks' );
   250 
   250 
   251 		$cache_key   = "get_network_ids:$key:$last_changed";
   251 		$cache_key   = "get_network_ids:$key:$last_changed";
   436 
   436 
   437 		$where = implode( ' AND ', $this->sql_clauses['where'] );
   437 		$where = implode( ' AND ', $this->sql_clauses['where'] );
   438 
   438 
   439 		$groupby = '';
   439 		$groupby = '';
   440 
   440 
   441 		$pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
   441 		$clauses = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
   442 
   442 
   443 		/**
   443 		/**
   444 		 * Filters the network query clauses.
   444 		 * Filters the network query clauses.
   445 		 *
   445 		 *
   446 		 * @since 4.6.0
   446 		 * @since 4.6.0
   447 		 *
   447 		 *
   448 		 * @param string[]         $pieces An associative array of network query clauses.
   448 		 * @param string[]         $clauses An associative array of network query clauses.
   449 		 * @param WP_Network_Query $query  Current instance of WP_Network_Query (passed by reference).
   449 		 * @param WP_Network_Query $query   Current instance of WP_Network_Query (passed by reference).
   450 		 */
   450 		 */
   451 		$clauses = apply_filters_ref_array( 'networks_clauses', array( compact( $pieces ), &$this ) );
   451 		$clauses = apply_filters_ref_array( 'networks_clauses', array( compact( $clauses ), &$this ) );
   452 
   452 
   453 		$fields  = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
   453 		$fields  = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
   454 		$join    = isset( $clauses['join'] ) ? $clauses['join'] : '';
   454 		$join    = isset( $clauses['join'] ) ? $clauses['join'] : '';
   455 		$where   = isset( $clauses['where'] ) ? $clauses['where'] : '';
   455 		$where   = isset( $clauses['where'] ) ? $clauses['where'] : '';
   456 		$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
   456 		$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
   478 		$this->sql_clauses['from']    = "FROM $wpdb->site $join";
   478 		$this->sql_clauses['from']    = "FROM $wpdb->site $join";
   479 		$this->sql_clauses['groupby'] = $groupby;
   479 		$this->sql_clauses['groupby'] = $groupby;
   480 		$this->sql_clauses['orderby'] = $orderby;
   480 		$this->sql_clauses['orderby'] = $orderby;
   481 		$this->sql_clauses['limits']  = $limits;
   481 		$this->sql_clauses['limits']  = $limits;
   482 
   482 
   483 		$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
   483 		$this->request = "
       
   484 			{$this->sql_clauses['select']}
       
   485 			{$this->sql_clauses['from']}
       
   486 			{$where}
       
   487 			{$this->sql_clauses['groupby']}
       
   488 			{$this->sql_clauses['orderby']}
       
   489 			{$this->sql_clauses['limits']}
       
   490 		";
   484 
   491 
   485 		if ( $this->query_vars['count'] ) {
   492 		if ( $this->query_vars['count'] ) {
   486 			return (int) $wpdb->get_var( $this->request );
   493 			return (int) $wpdb->get_var( $this->request );
   487 		}
   494 		}
   488 
   495 
   522 	 *
   529 	 *
   523 	 * @since 4.6.0
   530 	 * @since 4.6.0
   524 	 *
   531 	 *
   525 	 * @global wpdb $wpdb WordPress database abstraction object.
   532 	 * @global wpdb $wpdb WordPress database abstraction object.
   526 	 *
   533 	 *
   527 	 * @param string   $string  Search string.
   534 	 * @param string   $search  Search string.
   528 	 * @param string[] $columns Array of columns to search.
   535 	 * @param string[] $columns Array of columns to search.
   529 	 * @return string Search SQL.
   536 	 * @return string Search SQL.
   530 	 */
   537 	 */
   531 	protected function get_search_sql( $string, $columns ) {
   538 	protected function get_search_sql( $search, $columns ) {
   532 		global $wpdb;
   539 		global $wpdb;
   533 
   540 
   534 		$like = '%' . $wpdb->esc_like( $string ) . '%';
   541 		$like = '%' . $wpdb->esc_like( $search ) . '%';
   535 
   542 
   536 		$searches = array();
   543 		$searches = array();
   537 		foreach ( $columns as $column ) {
   544 		foreach ( $columns as $column ) {
   538 			$searches[] = $wpdb->prepare( "$column LIKE %s", $like );
   545 			$searches[] = $wpdb->prepare( "$column LIKE %s", $like );
   539 		}
   546 		}