Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17635 r18178  
    166166 *
    167167 * @since 3.0.0
    168  * @param array $users User ID number list.
     168 * @param array $user_ids Array of user IDs.
     169 * @param string|array $post_type Optional. Post type to check. Defaults to post.
    169170 * @return array Amount of posts each user has written.
    170171 */
    171 function count_many_users_posts($users) {
     172function count_many_users_posts($users, $post_type = 'post' ) {
    172173    global $wpdb;
    173174
    174175    $count = array();
    175     if ( ! is_array($users) || empty( $users ) )
     176    if ( empty( $users ) || ! is_array( $users ) )
    176177        return $count;
    177178
    178     $userlist = implode( ',', $users );
    179     $where = get_posts_by_author_sql( 'post' );
     179    $userlist = implode( ',', array_map( 'absint', $users ) );
     180    $where = get_posts_by_author_sql( $post_type );
    180181
    181182    $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
     
    361362    var $query_limit;
    362363
    363     /**
    364      * PHP4 constructor
    365      */
    366     function WP_User_Query( $query = null ) {
    367         $this->__construct( $query );
    368     }
    369364
    370365    /**
     
    389384                'orderby' => 'login',
    390385                'order' => 'ASC',
    391                 'offset' => '', 'number' => '',
     386                'offset' => '',
     387                'number' => '',
    392388                'count_total' => true,
    393389                'fields' => 'all',
     
    423419            $this->query_fields = "$wpdb->users.ID";
    424420        }
     421
     422        if ( $this->query_vars['count_total'] )
     423            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
    425424
    426425        $this->query_from = "FROM $wpdb->users";
     
    497496        if ( 'authors' == $qv['who'] && $blog_id ) {
    498497            $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
    499             $qv['meta_value'] = '_wp_zero_value'; // Hack to pass '0'
     498            $qv['meta_value'] = 0;
    500499            $qv['meta_compare'] = '!=';
    501500            $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
    502501        }
    503 
    504         _parse_meta_query( $qv );
    505502
    506503        $role = trim( $qv['role'] );
     
    518515        }
    519516
    520         if ( !empty( $qv['meta_query'] ) ) {
    521             $clauses = call_user_func_array( '_get_meta_sql', array( $qv['meta_query'], 'user', $wpdb->users, 'ID', &$this ) );
     517        $meta_query = new WP_Meta_Query();
     518        $meta_query->parse_query_vars( $qv );
     519
     520        if ( !empty( $meta_query->queries ) ) {
     521            $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
    522522            $this->query_from .= $clauses['join'];
    523523            $this->query_where .= $clauses['where'];
     524
     525            if ( 'OR' == $meta_query->relation )
     526                $this->query_fields = 'DISTINCT ' . $this->query_fields;
    524527        }
    525528
     
    551554
    552555        if ( $this->query_vars['count_total'] )
    553             $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where");
     556            $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
    554557
    555558        if ( !$this->results )
     
    741744 * Add meta data field to a user.
    742745 *
    743  * Post meta data is called "Custom Fields" on the Administration Panels.
     746 * Post meta data is called "Custom Fields" on the Administration Screens.
    744747 *
    745748 * @since 3.0.0
     
    13561359 * 'user_email' - A string containing the user's email address.
    13571360 * 'display_name' - A string that will be shown on the site. Defaults to user's
    1358  *      username. It is likely that you will want to change this, for both
    1359  *      appearance and security through obscurity (that is if you don't use and
    1360  *      delete the default 'admin' user).
     1361 *      username. It is likely that you will want to change this, for appearance.
    13611362 * 'nickname' - The user's nickname, defaults to the user's username.
    13621363 * 'first_name' - The user's first name.
Note: See TracChangeset for help on using the changeset viewer.