Ticket #42284: 42284.diff
| File 42284.diff, 5.3 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/class-wp-site-query.php
143 143 $this->query_var_defaults = array( 144 144 'fields' => '', 145 145 'ID' => '', 146 'site__in' => '',146 'site__in' => array(), 147 147 'site__not_in' => '', 148 148 'number' => 100, 149 149 'offset' => '', … … 151 151 'orderby' => 'id', 152 152 'order' => 'ASC', 153 153 'network_id' => 0, 154 'network__in' => '',154 'network__in' => array(), 155 155 'network__not_in' => '', 156 156 'domain' => '', 157 'domain__in' => '',157 'domain__in' => array(), 158 158 'domain__not_in' => '', 159 159 'path' => '', 160 'path__in' => '',160 'path__in' => array(), 161 161 'path__not_in' => '', 162 162 'public' => null, 163 163 'archived' => null, … … 165 165 'spam' => null, 166 166 'deleted' => null, 167 167 'lang_id' => null, 168 'lang__in' => '',168 'lang__in' => array(), 169 169 'lang__not_in' => '', 170 170 'search' => '', 171 171 'search_columns' => array(), … … 206 206 } 207 207 208 208 /** 209 * @param string $query 210 */ 211 public function tidy_query( $query = '' ) { 212 if ( empty( $query ) ) { 213 $query = $this->query_vars; 214 } 215 $query = wp_parse_args( $query ); 216 217 $list = array( 218 'ID' => 'site__in', 219 'network_id' => 'network__in', 220 'domain' => 'domain__in', 221 'path' => 'path__in', 222 'lang_id' => 'lang__in' 223 ); 224 225 foreach ( $list as $key => $value ) { 226 if ( empty( $query[ $key ] ) ) { 227 unset( $query[ $key ] ); 228 continue; 229 } 230 if ( empty( $query[ $value ] ) || ! is_array( $query[ $value ] ) ) { 231 $query[ $value ] = array(); 232 } 233 234 if ( ! in_array( $query[ $key ], $query[ $value ] ) ) { 235 $query[ $value ][] = $query[ $key ]; 236 } 237 238 unset( $query[ $key ] ); 239 } 240 241 $this->query_vars = $query; 242 } 243 244 /** 209 245 * Sets up the WordPress query for retrieving sites. 210 246 * 211 247 * @since 4.6.0 … … 240 276 */ 241 277 do_action_ref_array( 'pre_get_sites', array( &$this ) ); 242 278 279 $this->tidy_query(); 280 243 281 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 244 282 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); 245 283 … … 388 426 } 389 427 390 428 // Parse site IDs for an IN clause. 391 $site_id = absint( $this->query_vars['ID'] );392 if ( ! empty( $site_id ) ) {393 $this->sql_clauses['where']['ID'] = $wpdb->prepare( 'blog_id = %d', $site_id );394 }395 396 // Parse site IDs for an IN clause.397 429 if ( ! empty( $this->query_vars['site__in'] ) ) { 398 430 $this->sql_clauses['where']['site__in'] = "blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )'; 399 431 } … … 403 435 $this->sql_clauses['where']['site__not_in'] = "blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )'; 404 436 } 405 437 406 $network_id = absint( $this->query_vars['network_id'] );407 408 if ( ! empty( $network_id ) ) {409 $this->sql_clauses['where']['network_id'] = $wpdb->prepare( 'site_id = %d', $network_id );410 }411 412 438 // Parse site network IDs for an IN clause. 413 439 if ( ! empty( $this->query_vars['network__in'] ) ) { 414 440 $this->sql_clauses['where']['network__in'] = 'site_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )'; … … 419 445 $this->sql_clauses['where']['network__not_in'] = 'site_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )'; 420 446 } 421 447 422 if ( ! empty( $this->query_vars['domain'] ) ) {423 $this->sql_clauses['where']['domain'] = $wpdb->prepare( 'domain = %s', $this->query_vars['domain'] );424 }425 426 448 // Parse site domain for an IN clause. 427 449 if ( is_array( $this->query_vars['domain__in'] ) ) { 428 450 $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )"; … … 433 455 $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 434 456 } 435 457 436 if ( ! empty( $this->query_vars['path'] ) ) {437 $this->sql_clauses['where']['path'] = $wpdb->prepare( 'path = %s', $this->query_vars['path'] );438 }439 440 458 // Parse site path for an IN clause. 441 459 if ( is_array( $this->query_vars['path__in'] ) ) { 442 460 $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )"; … … 472 490 $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public ); 473 491 } 474 492 475 if ( is_numeric( $this->query_vars['lang_id'] ) ) {476 $lang_id = absint( $this->query_vars['lang_id'] );477 $this->sql_clauses['where']['lang_id'] = $wpdb->prepare( "lang_id = %d ", $lang_id );478 }479 480 493 // Parse site language IDs for an IN clause. 481 494 if ( ! empty( $this->query_vars['lang__in'] ) ) { 482 495 $this->sql_clauses['where']['lang__in'] = 'lang_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__in'] ) ) . ' )';
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)