X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/b137f4ce021b4022c56f452c2eafa7abfcef0a7c..refs/tags/wordpress-3.2:/wp-includes/user.php diff --git a/wp-includes/user.php b/wp-includes/user.php index 0a1a4354..af7f5de5 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -165,18 +165,19 @@ function count_user_posts($userid) { * Number of posts written by a list of users. * * @since 3.0.0 - * @param array $users User ID number list. + * @param array $user_ids Array of user IDs. + * @param string|array $post_type Optional. Post type to check. Defaults to post. * @return array Amount of posts each user has written. */ -function count_many_users_posts($users) { +function count_many_users_posts($users, $post_type = 'post' ) { global $wpdb; $count = array(); - if ( ! is_array($users) || empty( $users ) ) + if ( empty( $users ) || ! is_array( $users ) ) return $count; - $userlist = implode( ',', $users ); - $where = get_posts_by_author_sql( 'post' ); + $userlist = implode( ',', array_map( 'absint', $users ) ); + $where = get_posts_by_author_sql( $post_type ); $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); foreach ( $result as $row ) { @@ -360,12 +361,6 @@ class WP_User_Query { var $query_orderby; var $query_limit; - /** - * PHP4 constructor - */ - function WP_User_Query( $query = null ) { - $this->__construct( $query ); - } /** * PHP5 constructor @@ -388,7 +383,8 @@ class WP_User_Query { 'search' => '', 'orderby' => 'login', 'order' => 'ASC', - 'offset' => '', 'number' => '', + 'offset' => '', + 'number' => '', 'count_total' => true, 'fields' => 'all', 'who' => '' @@ -423,6 +419,9 @@ class WP_User_Query { $this->query_fields = "$wpdb->users.ID"; } + if ( $this->query_vars['count_total'] ) + $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; + $this->query_from = "FROM $wpdb->users"; $this->query_where = "WHERE 1=1"; @@ -496,13 +495,11 @@ class WP_User_Query { if ( 'authors' == $qv['who'] && $blog_id ) { $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level'; - $qv['meta_value'] = '_wp_zero_value'; // Hack to pass '0' + $qv['meta_value'] = 0; $qv['meta_compare'] = '!='; $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query } - _parse_meta_query( $qv ); - $role = trim( $qv['role'] ); if ( $blog_id && ( $role || is_multisite() ) ) { @@ -517,10 +514,16 @@ class WP_User_Query { $qv['meta_query'][] = $cap_meta_query; } - if ( !empty( $qv['meta_query'] ) ) { - $clauses = call_user_func_array( '_get_meta_sql', array( $qv['meta_query'], 'user', $wpdb->users, 'ID', &$this ) ); + $meta_query = new WP_Meta_Query(); + $meta_query->parse_query_vars( $qv ); + + if ( !empty( $meta_query->queries ) ) { + $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $this ); $this->query_from .= $clauses['join']; $this->query_where .= $clauses['where']; + + if ( 'OR' == $meta_query->relation ) + $this->query_fields = 'DISTINCT ' . $this->query_fields; } if ( !empty( $qv['include'] ) ) { @@ -550,7 +553,7 @@ class WP_User_Query { } if ( $this->query_vars['count_total'] ) - $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where"); + $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); if ( !$this->results ) return; @@ -740,7 +743,7 @@ function is_blog_user( $blog_id = 0 ) { /** * Add meta data field to a user. * - * Post meta data is called "Custom Fields" on the Administration Panels. + * Post meta data is called "Custom Fields" on the Administration Screens. * * @since 3.0.0 * @uses add_metadata() @@ -1355,9 +1358,7 @@ function validate_username( $username ) { * 'user_url' - A string containing the user's URL for the user's web site. * 'user_email' - A string containing the user's email address. * 'display_name' - A string that will be shown on the site. Defaults to user's - * username. It is likely that you will want to change this, for both - * appearance and security through obscurity (that is if you don't use and - * delete the default 'admin' user). + * username. It is likely that you will want to change this, for appearance. * 'nickname' - The user's nickname, defaults to the user's username. * 'first_name' - The user's first name. * 'last_name' - The user's last name.