Changeset 31669 for trunk/src/wp-includes/user.php
- Timestamp:
- 03/07/2015 06:37:05 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/user.php
r31665 r31669 532 532 * @type array $search_columns Array of column names to be searched. Accepts 'ID', 'login', 533 533 * 'nicename', 'email', 'url'. Default empty array. 534 * @type string|array $orderby Field to sort the retrieved users by. May be a single value,534 * @type string|array $orderby Field(s) to sort the retrieved users by. May be a single value, 535 535 * an array of values, or a multi-dimensional array with fields as keys 536 536 * and orders ('ASC' or 'DESC') as values. Accepted values are'ID', … … 538 538 * 'user_nicename' (or 'nicename'), 'user_email' (or 'email'), 539 539 * 'user_url' (or 'url'), 'user_registered' (or 'registered'), 540 * 'post_count', 'meta_value', or 'meta_value_num'. To use 'meta_value' 540 * 'post_count', 'meta_value', 'meta_value_num', the value of 541 * `$meta_key`, or an array key of `$meta_query`. To use 'meta_value' 541 542 * or 'meta_value_num', `$meta_key` must be also be defined. 542 543 * Default 'user_login'. … … 626 627 } 627 628 629 // Meta query. 630 $this->meta_query = new WP_Meta_Query(); 631 $this->meta_query->parse_query_vars( $qv ); 632 633 $blog_id = 0; 634 if ( isset( $qv['blog_id'] ) ) { 635 $blog_id = absint( $qv['blog_id'] ); 636 } 637 638 $role = ''; 639 if ( isset( $qv['role'] ) ) { 640 $role = trim( $qv['role'] ); 641 } 642 643 if ( $blog_id && ( $role || is_multisite() ) ) { 644 $cap_meta_query = array(); 645 $cap_meta_query['key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; 646 647 if ( $role ) { 648 $cap_meta_query['value'] = '"' . $role . '"'; 649 $cap_meta_query['compare'] = 'like'; 650 } 651 652 if ( empty( $this->meta_query->queries ) ) { 653 $this->meta_query->queries = array( $cap_meta_query ); 654 } elseif ( ! in_array( $cap_meta_query, $this->meta_query->queries, true ) ) { 655 // Append the cap query to the original queries and reparse the query. 656 $this->meta_query->queries = array( 657 'relation' => 'AND', 658 array( $this->meta_query->queries, $cap_meta_query ), 659 ); 660 } 661 662 $this->meta_query->parse_query_vars( $this->meta_query->queries ); 663 } 664 665 if ( ! empty( $this->meta_query->queries ) ) { 666 $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this ); 667 $this->query_from .= $clauses['join']; 668 $this->query_where .= $clauses['where']; 669 670 if ( 'OR' == $this->meta_query->relation ) { 671 $this->query_fields = 'DISTINCT ' . $this->query_fields; 672 } 673 } 674 628 675 // sorting 629 676 $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; … … 729 776 } 730 777 731 $blog_id = 0;732 if ( isset( $qv['blog_id'] ) )733 $blog_id = absint( $qv['blog_id'] );734 735 778 if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { 736 779 $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level'; … … 738 781 $qv['meta_compare'] = '!='; 739 782 $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query 740 }741 742 $this->meta_query = new WP_Meta_Query();743 $this->meta_query->parse_query_vars( $qv );744 745 $role = '';746 if ( isset( $qv['role'] ) )747 $role = trim( $qv['role'] );748 749 if ( $blog_id && ( $role || is_multisite() ) ) {750 $cap_meta_query = array();751 $cap_meta_query['key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';752 753 if ( $role ) {754 $cap_meta_query['value'] = '"' . $role . '"';755 $cap_meta_query['compare'] = 'like';756 }757 758 if ( empty( $this->meta_query->queries ) ) {759 $this->meta_query->queries = array( $cap_meta_query );760 } elseif ( ! in_array( $cap_meta_query, $this->meta_query->queries, true ) ) {761 // Append the cap query to the original queries and reparse the query.762 $this->meta_query->queries = array(763 'relation' => 'AND',764 array( $this->meta_query->queries, $cap_meta_query ),765 );766 }767 768 $this->meta_query->parse_query_vars( $this->meta_query->queries );769 }770 771 if ( !empty( $this->meta_query->queries ) ) {772 $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );773 $this->query_from .= $clauses['join'];774 $this->query_where .= $clauses['where'];775 776 if ( 'OR' == $this->meta_query->relation )777 $this->query_fields = 'DISTINCT ' . $this->query_fields;778 783 } 779 784 … … 955 960 protected function parse_orderby( $orderby ) { 956 961 global $wpdb; 962 963 $meta_query_clauses = $this->meta_query->get_clauses(); 957 964 958 965 $_orderby = ''; … … 976 983 } elseif ( 'ID' == $orderby || 'id' == $orderby ) { 977 984 $_orderby = 'ID'; 978 } elseif ( 'meta_value' == $orderby ) {985 } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) { 979 986 $_orderby = "$wpdb->usermeta.meta_value"; 980 987 } elseif ( 'meta_value_num' == $orderby ) { … … 984 991 $include_sql = implode( ',', $include ); 985 992 $_orderby = "FIELD( $wpdb->users.ID, $include_sql )"; 993 } elseif ( isset( $meta_query_clauses[ $orderby ] ) ) { 994 $meta_clause = $meta_query_clauses[ $orderby ]; 995 $_orderby = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); 986 996 } 987 997
Note: See TracChangeset
for help on using the changeset viewer.