X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/8f374b7233bc2815ccc387e448d208c5434eb961..6c8f14c09105d0afa4c1574215c59b5021040e76:/wp-includes/user.php?ds=sidebyside
diff --git a/wp-includes/user.php b/wp-includes/user.php
index 6b342c85..7bdc37cc 100644
--- a/wp-includes/user.php
+++ b/wp-includes/user.php
@@ -84,33 +84,32 @@ function wp_authenticate_username_password($user, $username, $password) {
return $error;
}
- $userdata = get_user_by('login', $username);
+ $user = get_user_by('login', $username);
- if ( !$userdata )
+ if ( !$user )
return new WP_Error('invalid_username', sprintf(__('ERROR: Invalid username. Lost your password?'), wp_lostpassword_url()));
if ( is_multisite() ) {
// Is user marked as spam?
- if ( 1 == $userdata->spam)
+ if ( 1 == $user->spam)
return new WP_Error('invalid_username', __('ERROR: Your account has been marked as a spammer.'));
// Is a user's blog marked as spam?
- if ( !is_super_admin( $userdata->ID ) && isset($userdata->primary_blog) ) {
- $details = get_blog_details( $userdata->primary_blog );
+ if ( !is_super_admin( $user->ID ) && isset($user->primary_blog) ) {
+ $details = get_blog_details( $user->primary_blog );
if ( is_object( $details ) && $details->spam == 1 )
return new WP_Error('blog_suspended', __('Site Suspended.'));
}
}
- $userdata = apply_filters('wp_authenticate_user', $userdata, $password);
- if ( is_wp_error($userdata) )
- return $userdata;
+ $user = apply_filters('wp_authenticate_user', $user, $password);
+ if ( is_wp_error($user) )
+ return $user;
- if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) )
+ if ( !wp_check_password($password, $user->user_pass, $user->ID) )
return new WP_Error( 'incorrect_password', sprintf( __( 'ERROR: The password you entered for the username %1$s is incorrect. Lost your password?' ),
$username, wp_lostpassword_url() ) );
- $user = new WP_User($userdata->ID);
return $user;
}
@@ -166,10 +165,11 @@ function count_user_posts($userid) {
* @since 3.0.0
*
* @param array $users Array of user IDs.
- * @param string|array $post_type Optional. Post type to check. Defaults to post.
+ * @param string $post_type Optional. Post type to check. Defaults to post.
+ * @param bool $public_only Optional. Only return counts for public posts. Defaults to false.
* @return array Amount of posts each user has written.
*/
-function count_many_users_posts( $users, $post_type = 'post' ) {
+function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) {
global $wpdb;
$count = array();
@@ -177,7 +177,7 @@ function count_many_users_posts( $users, $post_type = 'post' ) {
return $count;
$userlist = implode( ',', array_map( 'absint', $users ) );
- $where = get_posts_by_author_sql( $post_type );
+ $where = get_posts_by_author_sql( $post_type, true, null, $public_only );
$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 ) {
@@ -192,24 +192,6 @@ function count_many_users_posts( $users, $post_type = 'post' ) {
return $count;
}
-/**
- * Check that the user login name and password is correct.
- *
- * @since 0.71
- * @todo xmlrpc only. Maybe move to xmlrpc.php.
- *
- * @param string $user_login User name.
- * @param string $user_pass User password.
- * @return bool False if does not authenticate, true if username and password authenticates.
- */
-function user_pass_ok($user_login, $user_pass) {
- $user = wp_authenticate($user_login, $user_pass);
- if ( is_wp_error($user) )
- return false;
-
- return true;
-}
-
//
// User option functions
//
@@ -255,11 +237,9 @@ function get_user_option( $option, $user = 0, $deprecated = '' ) {
_deprecated_argument( __FUNCTION__, '3.0' );
if ( empty( $user ) )
- $user = wp_get_current_user();
- else
- $user = new WP_User( $user );
+ $user = get_current_user_id();
- if ( ! $user->exists() )
+ if ( ! $user = get_userdata( $user ) )
return false;
if ( $user->has_prop( $wpdb->prefix . $option ) ) // Blog specific
@@ -334,6 +314,15 @@ function delete_user_option( $user_id, $option_name, $global = false ) {
*/
class WP_User_Query {
+ /**
+ * Query vars, after parsing
+ *
+ * @since 3.5.0
+ * @access public
+ * @var array
+ */
+ var $query_vars = array();
+
/**
* List of found user ids
*
@@ -402,7 +391,7 @@ class WP_User_Query {
function prepare_query() {
global $wpdb;
- $qv = &$this->query_vars;
+ $qv =& $this->query_vars;
if ( is_array( $qv['fields'] ) ) {
$qv['fields'] = array_unique( $qv['fields'] );
@@ -417,7 +406,7 @@ class WP_User_Query {
$this->query_fields = "$wpdb->users.ID";
}
- if ( $this->query_vars['count_total'] )
+ if ( $qv['count_total'] )
$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
$this->query_from = "FROM $wpdb->users";
@@ -549,29 +538,64 @@ class WP_User_Query {
function query() {
global $wpdb;
- if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) {
+ $qv =& $this->query_vars;
+
+ if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
$this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
} else {
$this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
}
- if ( $this->query_vars['count_total'] )
+ if ( $qv['count_total'] )
$this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
if ( !$this->results )
return;
- if ( 'all_with_meta' == $this->query_vars['fields'] ) {
+ if ( 'all_with_meta' == $qv['fields'] ) {
cache_users( $this->results );
$r = array();
foreach ( $this->results as $userid )
- $r[ $userid ] = new WP_User( $userid, '', $this->query_vars['blog_id'] );
+ $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] );
$this->results = $r;
+ } elseif ( 'all' == $qv['fields'] ) {
+ foreach ( $this->results as $key => $user ) {
+ $this->results[ $key ] = new WP_User( $user );
+ }
}
}
+ /**
+ * Retrieve query variable.
+ *
+ * @since 3.5.0
+ * @access public
+ *
+ * @param string $query_var Query variable key.
+ * @return mixed
+ */
+ function get( $query_var ) {
+ if ( isset( $this->query_vars[$query_var] ) )
+ return $this->query_vars[$query_var];
+
+ return null;
+ }
+
+ /**
+ * Set query variable.
+ *
+ * @since 3.5.0
+ * @access public
+ *
+ * @param string $query_var Query variable key.
+ * @param mixed $value Query variable value.
+ */
+ function set( $query_var, $value ) {
+ $this->query_vars[$query_var] = $value;
+ }
+
/*
* Used internally to generate an SQL string for searching across multiple columns
*
@@ -676,6 +700,9 @@ function get_blogs_of_user( $user_id, $all = false ) {
$blogs[ $blog_id ]->path = '';
$blogs[ $blog_id ]->site_id = 1;
$blogs[ $blog_id ]->siteurl = get_option('siteurl');
+ $blogs[ $blog_id ]->archived = 0;
+ $blogs[ $blog_id ]->spam = 0;
+ $blogs[ $blog_id ]->deleted = 0;
return $blogs;
}
@@ -691,6 +718,9 @@ function get_blogs_of_user( $user_id, $all = false ) {
'path' => $blog->path,
'site_id' => $blog->site_id,
'siteurl' => $blog->siteurl,
+ 'archived' => 0,
+ 'spam' => 0,
+ 'deleted' => 0
);
}
unset( $keys[ $wpdb->base_prefix . 'capabilities' ] );
@@ -717,6 +747,9 @@ function get_blogs_of_user( $user_id, $all = false ) {
'path' => $blog->path,
'site_id' => $blog->site_id,
'siteurl' => $blog->siteurl,
+ 'archived' => 0,
+ 'spam' => 0,
+ 'deleted' => 0
);
}
}
@@ -920,33 +953,31 @@ function count_users($strategy = 'time') {
* @global int $user_ID The ID of the user
* @global string $user_email The email address of the user
* @global string $user_url The url in the user's profile
- * @global string $user_pass_md5 MD5 of the user's password
* @global string $user_identity The display name of the user
*
* @param int $for_user_id Optional. User ID to set up global data.
*/
function setup_userdata($for_user_id = '') {
- global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity;
+ global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity;
if ( '' == $for_user_id )
- $user = wp_get_current_user();
- else
- $user = new WP_User($for_user_id);
-
- $userdata = null;
- $user_ID = (int) $user->ID;
- $user_level = (int) isset($user->user_level) ? $user->user_level : 0;
-
- if ( ! $user->exists() ) {
- $user_login = $user_email = $user_url = $user_pass_md5 = $user_identity = '';
+ $for_user_id = get_current_user_id();
+ $user = get_userdata( $for_user_id );
+
+ if ( ! $user ) {
+ $user_ID = 0;
+ $user_level = 0;
+ $userdata = null;
+ $user_login = $user_email = $user_url = $user_identity = '';
return;
}
+ $user_ID = (int) $user->ID;
+ $user_level = (int) $user->user_level;
$userdata = $user;
$user_login = $user->user_login;
$user_email = $user->user_email;
$user_url = $user->user_url;
- $user_pass_md5 = md5( $user->user_pass );
$user_identity = $user->display_name;
}
@@ -1221,7 +1252,7 @@ function validate_username( $username ) {
* 'ID' - An integer that will be used for updating an existing user.
* 'user_pass' - A string that contains the plain text password for the user.
* 'user_login' - A string that contains the user's username for logging in.
- * 'user_nicename' - A string that contains a nicer looking name for the user.
+ * 'user_nicename' - A string that contains a URL-friendly name for the user.
* The default is the user's 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.
@@ -1245,13 +1276,18 @@ function validate_username( $username ) {
* @uses do_action() Calls 'profile_update' hook when updating giving the user's ID
* @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
*
- * @param array $userdata An array of user data.
+ * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
* @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created.
*/
-function wp_insert_user($userdata) {
+function wp_insert_user( $userdata ) {
global $wpdb;
- extract($userdata, EXTR_SKIP);
+ if ( is_a( $userdata, 'stdClass' ) )
+ $userdata = get_object_vars( $userdata );
+ elseif ( is_a( $userdata, 'WP_User' ) )
+ $userdata = $userdata->to_array();
+
+ extract( $userdata, EXTR_SKIP );
// Are we updating or creating?
if ( !empty($ID) ) {
@@ -1274,7 +1310,7 @@ function wp_insert_user($userdata) {
return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
if ( !$update && username_exists( $user_login ) )
- return new WP_Error('existing_user_login', __('This username is already registered.') );
+ return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) );
if ( empty($user_nicename) )
$user_nicename = sanitize_title( $user_login );
@@ -1289,11 +1325,7 @@ function wp_insert_user($userdata) {
$user_email = apply_filters('pre_user_email', $user_email);
if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
- return new WP_Error('existing_user_email', __('This email address is already registered.') );
-
- if ( empty($display_name) )
- $display_name = $user_login;
- $display_name = apply_filters('pre_user_display_name', $display_name);
+ return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) );
if ( empty($nickname) )
$nickname = $user_login;
@@ -1307,6 +1339,21 @@ function wp_insert_user($userdata) {
$last_name = '';
$last_name = apply_filters('pre_user_last_name', $last_name);
+ if ( empty( $display_name ) ) {
+ if ( $update )
+ $display_name = $user_login;
+ elseif ( $first_name && $last_name )
+ /* translators: 1: first name, 2: last name */
+ $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $first_name, $last_name );
+ elseif ( $first_name )
+ $display_name = $first_name;
+ elseif ( $last_name )
+ $display_name = $last_name;
+ else
+ $display_name = $user_login;
+ }
+ $display_name = apply_filters( 'pre_user_display_name', $display_name );
+
if ( empty($description) )
$description = '';
$description = apply_filters('pre_user_description', $description);
@@ -1392,16 +1439,21 @@ function wp_insert_user($userdata) {
* @see wp_insert_user() For what fields can be set in $userdata
* @uses wp_insert_user() Used to update existing user or add new one if user doesn't exist already
*
- * @param array $userdata An array of user data.
- * @return int The updated user's ID.
+ * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
+ * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated.
*/
function wp_update_user($userdata) {
+ if ( is_a( $userdata, 'stdClass' ) )
+ $userdata = get_object_vars( $userdata );
+ elseif ( is_a( $userdata, 'WP_User' ) )
+ $userdata = $userdata->to_array();
+
$ID = (int) $userdata['ID'];
// First, get all of the original fields
$user_obj = get_userdata( $ID );
- $user = get_object_vars( $user_obj->data );
+ $user = $user_obj->to_array();
// Add additional custom fields
foreach ( _get_additional_user_keys( $user_obj ) as $key ) {
@@ -1461,10 +1513,10 @@ function wp_create_user($username, $password, $email = '') {
/**
* Return a list of meta keys that wp_insert_user() is supposed to set.
*
- * @access private
* @since 3.3.0
+ * @access private
*
- * @param object $user WP_User instance
+ * @param object $user WP_User instance.
* @return array
*/
function _get_additional_user_keys( $user ) {
@@ -1473,12 +1525,12 @@ function _get_additional_user_keys( $user ) {
}
/**
- * Set up the default contact methods
+ * Set up the default contact methods.
*
+ * @since 2.9.0
* @access private
- * @since
*
- * @param object $user User data object (optional)
+ * @param object $user User data object (optional).
* @return array $user_contactmethods Array of contact methods and their labels.
*/
function _wp_get_user_contactmethods( $user = null ) {