Ticket #43891: 43891.diff
File 43891.diff, 3.6 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-query.php
1161 1161 if ( ! isset( $q['category__in'] ) ) { 1162 1162 $q['category__in'] = array(); 1163 1163 } 1164 $q['category__in'][] = absint( reset( $q['category__and'] ) );1164 $q['category__in'][] = absint( $this->reset( $q['category__and'] ) ); 1165 1165 unset( $q['category__and'] ); 1166 1166 } 1167 1167 … … 1504 1504 } 1505 1505 } else { 1506 1506 // single word or sentence search 1507 $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC';1507 $search_orderby = $this->reset( $q['search_orderby_title'] ) . ' DESC'; 1508 1508 } 1509 1509 1510 1510 return $search_orderby; … … 1549 1549 $primary_meta_query = false; 1550 1550 $meta_clauses = $this->meta_query->get_clauses(); 1551 1551 if ( ! empty( $meta_clauses ) ) { 1552 $primary_meta_query = reset( $meta_clauses );1552 $primary_meta_query = $this->reset( $meta_clauses ); 1553 1553 1554 1554 if ( ! empty( $primary_meta_query['key'] ) ) { 1555 1555 $primary_meta_key = $primary_meta_query['key']; … … 2319 2319 $post_type_cap = 'multiple_post_type'; 2320 2320 } else { 2321 2321 if ( is_array( $post_type ) ) { 2322 $post_type = reset( $post_type );2322 $post_type = $this->reset( $post_type ); 2323 2323 } 2324 2324 $post_type_object = get_post_type_object( $post_type ); 2325 2325 if ( empty( $post_type_object ) ) { … … 3119 3119 update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 3120 3120 } 3121 3121 3122 $this->post = reset( $this->posts );3122 $this->post = $this->reset( $this->posts ); 3123 3123 } else { 3124 3124 $this->post_count = 0; 3125 3125 $this->posts = array(); … … 3396 3396 // For other tax queries, grab the first term from the first clause. 3397 3397 if ( ! empty( $this->tax_query->queried_terms ) ) { 3398 3398 $queried_taxonomies = array_keys( $this->tax_query->queried_terms ); 3399 $matched_taxonomy = reset( $queried_taxonomies );3399 $matched_taxonomy = $this->reset( $queried_taxonomies ); 3400 3400 $query = $this->tax_query->queried_terms[ $matched_taxonomy ]; 3401 3401 3402 3402 if ( ! empty( $query['terms'] ) ) { 3403 3403 if ( 'term_id' == $query['field'] ) { 3404 $term = get_term( reset( $query['terms'] ), $matched_taxonomy );3404 $term = get_term( $this->reset( $query['terms'] ), $matched_taxonomy ); 3405 3405 } else { 3406 $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy );3406 $term = get_term_by( $query['field'], $this->reset( $query['terms'] ), $matched_taxonomy ); 3407 3407 } 3408 3408 } 3409 3409 } … … 3420 3420 } elseif ( $this->is_post_type_archive ) { 3421 3421 $post_type = $this->get( 'post_type' ); 3422 3422 if ( is_array( $post_type ) ) { 3423 $post_type = reset( $post_type );3423 $post_type = $this->reset( $post_type ); 3424 3424 } 3425 3425 $this->queried_object = get_post_type_object( $post_type ); 3426 3426 } elseif ( $this->is_posts_page ) { … … 3542 3542 3543 3543 $post_type = $this->get( 'post_type' ); 3544 3544 if ( is_array( $post_type ) ) { 3545 $post_type = reset( $post_type );3545 $post_type = $this->reset( $post_type ); 3546 3546 } 3547 3547 $post_type_object = get_post_type_object( $post_type ); 3548 3548 … … 4250 4250 _deprecated_function( __METHOD__, '4.5.0' ); 4251 4251 return $check; 4252 4252 } 4253 4254 /** 4255 * Returns the first element of an array. 4256 * This is introduced as a replacement 4257 * of the PHP native function reset() 4258 * for performance improvement. 4259 * 4260 * @since 5.0.0 4261 * 4262 * @param array $array 4263 * 4264 * @return mixed 4265 */ 4266 private function reset( $array ) { 4267 foreach ( $array as $element ) { 4268 return $element; 4269 } 4270 } 4253 4271 }