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 } |