Ticket #23849: 23849.4.diff
File 23849.4.diff, 2.3 KB (added by , 10 years ago) |
---|
-
src/wp-includes/user.php
715 715 $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query 716 716 } 717 717 718 $meta_query = new WP_Meta_Query(); 719 $meta_query->parse_query_vars( $qv ); 720 718 721 $role = ''; 719 722 if ( isset( $qv['role'] ) ) 720 723 $role = trim( $qv['role'] ); … … 728 731 $cap_meta_query['compare'] = 'like'; 729 732 } 730 733 731 if ( empty( $qv['meta_query'] ) || ! in_array( $cap_meta_query, $qv['meta_query'], true ) ) { 732 $qv['meta_query'][] = $cap_meta_query; 734 if ( empty( $meta_query->queries ) ) { 735 $meta_query->queries = array( $cap_meta_query ); 736 } elseif ( ! in_array( $cap_meta_query, $meta_query->queries, true ) ) { 737 // Append the cap query to the original queries and reparse the query. 738 $meta_query->queries = array( 739 'relation' => 'AND', 740 array( $meta_query->queries, $cap_meta_query ), 741 ); 733 742 } 743 744 $meta_query->parse_query_vars( $meta_query->queries ); 734 745 } 735 746 736 $meta_query = new WP_Meta_Query();737 $meta_query->parse_query_vars( $qv );738 739 747 if ( !empty( $meta_query->queries ) ) { 740 748 $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $this ); 741 749 $this->query_from .= $clauses['join']; -
tests/phpunit/tests/user/query.php
221 221 $query->prepare_query(); 222 222 $this->assertEquals( $_query_vars, $query->query_vars ); 223 223 } 224 225 /** 226 * @ticket 23849 227 */ 228 function test_meta_query_with_role() { 229 $author_ids = $this->factory->user->create_many( 4, array( 'role' => 'author' ) ); 230 231 add_user_meta( $author_ids[0], 'foo', 'bar' ); 232 add_user_meta( $author_ids[1], 'foo', 'baz' ); 233 234 // Users with foo = bar or baz restricted to the author role. 235 $query = new WP_User_Query( array( 236 'fields' => '', 237 'role' => 'author', 238 'meta_query' => array( 239 'relation' => 'OR', 240 array( 241 'key' => 'foo', 242 'value' => 'bar', 243 ), 244 array( 245 'key' => 'foo', 246 'value' => 'baz', 247 ), 248 ), 249 ) ); 250 251 $this->assertEquals( array( $author_ids[0], $author_ids[1] ), $query->get_results() ); 252 } 224 253 }