Make WordPress Core


Ignore:
Timestamp:
02/06/2010 12:35:15 PM (15 years ago)
Author:
westi
Message:

Allow plugins to modify the query run by WP_User_Search. Fixes #10781 props scribu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/user.php

    r12983 r12989  
    567567     * @since unknown
    568568     * @access private
    569      * @var unknown_type
     569     * @var string
    570570     */
    571571    var $query_limit;
     
    574574     * {@internal Missing Description}}
    575575     *
    576      * @since unknown
    577      * @access private
    578      * @var unknown_type
    579      */
    580     var $query_sort;
    581 
    582     /**
    583      * {@internal Missing Description}}
    584      *
    585      * @since unknown
    586      * @access private
    587      * @var unknown_type
    588      */
    589     var $query_from_where;
     576     * @since 3.0
     577     * @access private
     578     * @var string
     579     */
     580    var $query_orderby;
     581
     582    /**
     583     * {@internal Missing Description}}
     584     *
     585     * @since 3.0
     586     * @access private
     587     * @var string
     588     */
     589    var $query_from;
     590
     591    /**
     592     * {@internal Missing Description}}
     593     *
     594     * @since 3.0
     595     * @access private
     596     * @var string
     597     */
     598    var $query_where;
    590599
    591600    /**
     
    658667        global $wpdb;
    659668        $this->first_user = ($this->page - 1) * $this->users_per_page;
     669
    660670        $this->query_limit = $wpdb->prepare(" LIMIT %d, %d", $this->first_user, $this->users_per_page);
    661         $this->query_sort = ' ORDER BY user_login';
     671        $this->query_orderby = ' ORDER BY user_login';
     672
    662673        $search_sql = '';
    663674        if ( $this->search_term ) {
     
    670681        }
    671682
    672         $this->query_from_where = "FROM $wpdb->users";
     683        $this->query_from = " FROM $wpdb->users";
     684        $this->query_where = " WHERE 1=1 $search_sql";
     685
    673686        if ( $this->role ) {
    674             $this->query_from_where .= $wpdb->prepare(" INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%');
    675         } elseif ( !is_multisite() ) {
    676             $this->query_from_where .= " WHERE 1=1";
    677         } else {
     687            $this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id";
     688            $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%');
     689        } elseif ( is_multisite() ) {
    678690            $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
    679             $this->query_from_where .= ", $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'";
     691            $this->query_from .= ", $wpdb->usermeta";
     692            $this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'";
    680693        }
    681         $this->query_from_where .= " $search_sql";
    682 
     694
     695        do_action_ref_array( 'pre_user_search', array( &$this ) );
    683696    }
    684697
     
    693706    function query() {
    694707        global $wpdb;
    695         $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_sort . $this->query_limit);
     708
     709        $this->results = $wpdb->get_col("SELECT DISTINCT($wpdb->users.ID)" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit);
    696710
    697711        if ( $this->results )
    698             $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit
     712            $this->total_users_for_query = $wpdb->get_var("SELECT COUNT(DISTINCT($wpdb->users.ID))" . $this->query_from . $this->query_where); // no limit
    699713        else
    700714            $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!'));
Note: See TracChangeset for help on using the changeset viewer.