diff --git a/wp-activate.php b/wp-activate.php
index d470772ff6..2ce531f696 100644
--- a/wp-activate.php
+++ b/wp-activate.php
@@ -77,7 +77,7 @@ get_header();
} else {
extract($result);
$url = get_blogaddress_by_id( (int) $blog_id);
- $user = new WP_User( (int) $user_id);
+ $user = get_userdata( (int) $user_id);
?>
diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php
index 31e934b9b2..439014d8cf 100644
--- a/wp-admin/includes/ajax-actions.php
+++ b/wp-admin/includes/ajax-actions.php
@@ -1018,7 +1018,7 @@ function wp_ajax_add_user( $action ) {
) );
$x->send();
}
- $user_object = new WP_User( $user_id );
+ $user_object = get_userdata( $user_id );
$wp_list_table = _get_list_table('WP_Users_List_Table');
diff --git a/wp-admin/includes/class-wp-users-list-table.php b/wp-admin/includes/class-wp-users-list-table.php
index 485093e488..6dbb6b157d 100644
--- a/wp-admin/includes/class-wp-users-list-table.php
+++ b/wp-admin/includes/class-wp-users-list-table.php
@@ -218,7 +218,7 @@ class WP_Users_List_Table extends WP_List_Table {
global $wp_roles;
if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
- $user_object = new WP_User( (int) $user_object );
+ $user_object = get_userdata( (int) $user_object );
$user_object->filter = 'display';
$email = $user_object->user_email;
diff --git a/wp-admin/includes/deprecated.php b/wp-admin/includes/deprecated.php
index 7a53671a8e..6a66e43b16 100644
--- a/wp-admin/includes/deprecated.php
+++ b/wp-admin/includes/deprecated.php
@@ -249,7 +249,8 @@ function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'p
global $wpdb;
- $user = new WP_User( $user_id );
+ if ( ! $user = get_userdata( $user_id ) )
+ return array();
$post_type_obj = get_post_type_object($post_type);
if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) {
diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php
index 6980156d5b..fcdfad8e85 100644
--- a/wp-admin/includes/ms.php
+++ b/wp-admin/includes/ms.php
@@ -689,8 +689,8 @@ function grant_super_admin( $user_id ) {
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
- $user = new WP_User( $user_id );
- if ( ! in_array( $user->user_login, $super_admins ) ) {
+ $user = get_userdata( $user_id );
+ if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
$super_admins[] = $user->user_login;
update_site_option( 'site_admins' , $super_admins );
do_action( 'granted_super_admin', $user_id );
@@ -717,8 +717,8 @@ function revoke_super_admin( $user_id ) {
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
- $user = new WP_User( $user_id );
- if ( $user->user_email != get_site_option( 'admin_email' ) ) {
+ $user = get_userdata( $user_id );
+ if ( $user && $user->user_email != get_site_option( 'admin_email' ) ) {
if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
unset( $super_admins[$key] );
update_site_option( 'site_admins', $super_admins );
diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php
index 08a7b4b8dd..0053d99f09 100644
--- a/wp-admin/includes/upgrade.php
+++ b/wp-admin/includes/upgrade.php
@@ -320,7 +320,7 @@ if ( !function_exists('wp_new_blog_notification') ) :
* @param string $password User's Password.
*/
function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
- $user = new WP_User($user_id);
+ $user = new WP_User( $user_id );
$email = $user->user_email;
$name = $user->user_login;
$message = sprintf(__("Your new WordPress site has been successfully set up at:
diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php
index 55f0df2c6c..46b5183ec2 100644
--- a/wp-admin/includes/user.php
+++ b/wp-admin/includes/user.php
@@ -198,7 +198,7 @@ function get_editable_roles() {
* @return object WP_User object with user data.
*/
function get_user_to_edit( $user_id ) {
- $user = new WP_User( $user_id );
+ $user = get_userdata( $user_id );
$user->filter = 'edit';
diff --git a/wp-admin/network/site-users.php b/wp-admin/network/site-users.php
index 58796b258d..177af4b44b 100644
--- a/wp-admin/network/site-users.php
+++ b/wp-admin/network/site-users.php
@@ -143,7 +143,7 @@ if ( $action ) {
if ( !is_user_member_of_blog( $user_id ) )
wp_die(__('Cheatin’ uh?'));
- $user = new WP_User( $user_id );
+ $user = get_userdata( $user_id );
$user->set_role( $_REQUEST['new_role'] );
}
} else {
diff --git a/wp-admin/network/users.php b/wp-admin/network/users.php
index 98246c3fbf..1d16fbbd4e 100644
--- a/wp-admin/network/users.php
+++ b/wp-admin/network/users.php
@@ -34,7 +34,7 @@ function confirm_delete_users( $users ) {
foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
if ( $val != '' && $val != '0' ) {
- $delete_user = new WP_User( $val );
+ $delete_user = get_userdata( $val );
if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
@@ -139,8 +139,8 @@ if ( isset( $_GET['action'] ) ) {
break;
case 'spam':
- $user = new WP_User( $val );
- if ( in_array( $user->user_login, get_super_admins() ) )
+ $user = get_userdata( $val );
+ if ( is_super_admin( $user->ID ) )
wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
$userfunction = 'all_spam';
diff --git a/wp-admin/users.php b/wp-admin/users.php
index f26255fca6..47faacfcb6 100644
--- a/wp-admin/users.php
+++ b/wp-admin/users.php
@@ -111,7 +111,7 @@ case 'promote':
if ( is_multisite() && !is_user_member_of_blog( $id ) )
wp_die(__('Cheatin’ uh?'));
- $user = new WP_User($id);
+ $user = get_userdata( $id );
$user->set_role($_REQUEST['new_role']);
}
@@ -201,7 +201,7 @@ case 'delete':
$go_delete = 0;
foreach ( $userids as $id ) {
$id = (int) $id;
- $user = new WP_User($id);
+ $user = get_userdata( $id );
if ( $id == $current_user->ID ) {
echo "" . sprintf(__('ID #%1s: %2s The current user will not be deleted.'), $id, $user->user_login) . "\n";
} else {
@@ -302,7 +302,7 @@ case 'remove':
$go_remove = false;
foreach ( $userids as $id ) {
$id = (int) $id;
- $user = new WP_User($id);
+ $user = get_userdata( $id );
if ( $id == $current_user->ID && !is_super_admin() ) {
echo "" . sprintf(__('ID #%1s: %2s The current user will not be removed.'), $id, $user->user_login) . "\n";
} elseif ( !current_user_can('remove_user', $id) ) {
diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php
index 11331ecc62..4687d4f18b 100644
--- a/wp-includes/capabilities.php
+++ b/wp-includes/capabilities.php
@@ -1237,7 +1237,7 @@ function current_user_can_for_blog( $blog_id, $capability ) {
return false;
// Create new object to avoid stomping the global current_user.
- $user = new WP_User( $current_user->ID) ;
+ $user = new WP_User( $current_user->ID );
// Set the blog id. @todo add blog id arg to WP_User constructor?
$user->for_blog( $blog_id );
@@ -1261,9 +1261,9 @@ function author_can( $post, $capability ) {
if ( !$post = get_post($post) )
return false;
- $author = new WP_User( $post->post_author );
+ $author = get_userdata( $post->post_author );
- if ( empty( $author->ID ) )
+ if ( ! $author )
return false;
$args = array_slice( func_get_args(), 2 );
@@ -1283,7 +1283,7 @@ function author_can( $post, $capability ) {
*/
function user_can( $user, $capability ) {
if ( ! is_object( $user ) )
- $user = new WP_User( $user );
+ $user = get_userdata( $user );
if ( ! $user || ! $user->exists() )
return false;
diff --git a/wp-includes/comment.php b/wp-includes/comment.php
index 3fa944397c..dc3de4ed39 100644
--- a/wp-includes/comment.php
+++ b/wp-includes/comment.php
@@ -650,13 +650,12 @@ function wp_allow_comment($commentdata) {
do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );
- if ( isset($user_id) && $user_id) {
- $userdata = get_userdata($user_id);
- $user = new WP_User($user_id);
+ if ( ! empty( $user_id ) ) {
+ $user = get_userdata( $user_id );
$post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID));
}
- if ( isset($userdata) && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {
+ if ( $user && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {
// The author and the admins get respect.
$approved = 1;
} else {
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index bdda370b28..b458b69c11 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -1071,9 +1071,9 @@ function get_edit_user_link( $user_id = null ) {
if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
return '';
- $user = new WP_User( $user_id );
+ $user = get_userdata( $user_id );
- if ( ! $user->exists() )
+ if ( ! $user )
return '';
if ( get_current_user_id() == $user->ID )
diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php
index a791b4ce57..202c3ab239 100644
--- a/wp-includes/ms-functions.php
+++ b/wp-includes/ms-functions.php
@@ -183,9 +183,9 @@ function get_blog_post( $blog_id, $post_id ) {
function add_user_to_blog( $blog_id, $user_id, $role ) {
switch_to_blog($blog_id);
- $user = new WP_User($user_id);
+ $user = get_userdata( $user_id );
- if ( ! $user->exists() ) {
+ if ( ! $user ) {
restore_current_blog();
return new WP_Error('user_does_not_exist', __('That user does not exist.'));
}
@@ -246,8 +246,8 @@ function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
}
// wp_revoke_user($user_id);
- $user = new WP_User($user_id);
- if ( ! $user->exists() ) {
+ $user = get_userdata( $user_id );
+ if ( ! $user ) {
restore_current_blog();
return new WP_Error('user_does_not_exist', __('That user does not exist.'));
}
@@ -1056,7 +1056,7 @@ function newuser_notify_siteadmin( $user_id ) {
if ( is_email($email) == false )
return false;
- $user = new WP_User($user_id);
+ $user = get_userdata( $user_id );
$options_site_url = esc_url(network_admin_url('settings.php'));
$msg = sprintf(__('New User: %1s
@@ -1233,7 +1233,7 @@ We hope you enjoy your new site. Thanks!
--The Team @ SITE_NAME' ) );
$url = get_blogaddress_by_id($blog_id);
- $user = new WP_User($user_id);
+ $user = get_userdata( $user_id );
$welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
$welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
@@ -1282,7 +1282,7 @@ function wpmu_welcome_user_notification($user_id, $password, $meta = '') {
$welcome_email = get_site_option( 'welcome_user_email' );
- $user = new WP_User($user_id);
+ $user = get_userdata( $user_id );
$welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta);
$welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
@@ -1508,7 +1508,7 @@ function update_posts_count( $deprecated = '' ) {
*/
function wpmu_log_new_registrations( $blog_id, $user_id ) {
global $wpdb;
- $user = new WP_User( (int) $user_id );
+ $user = get_userdata( (int) $user_id );
$wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
}
@@ -1751,7 +1751,7 @@ function is_user_spammy( $username = 0 ) {
} else {
$user_id = get_user_id_from_string( $username );
}
- $u = new WP_User( $user_id );
+ $u = get_userdata( $user_id );
return ( isset( $u->spam ) && $u->spam == 1 );
}
diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php
index 49208e6a73..8e823b443c 100644
--- a/wp-includes/pluggable.php
+++ b/wp-includes/pluggable.php
@@ -1198,7 +1198,7 @@ if ( !function_exists('wp_new_user_notification') ) :
* @param string $plaintext_pass Optional. The user's plaintext password
*/
function wp_new_user_notification($user_id, $plaintext_pass = '') {
- $user = new WP_User($user_id);
+ $user = get_userdata( $user_id );
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
diff --git a/wp-includes/user.php b/wp-includes/user.php
index 45f1c051f8..1417853931 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;
}
@@ -255,11 +254,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
@@ -928,19 +925,19 @@ function setup_userdata($for_user_id = '') {
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);
+ $for_user_id = get_current_user_id();
+ $user = get_userdata( $for_user_id );
- $userdata = null;
- $user_ID = (int) $user->ID;
- $user_level = (int) isset($user->user_level) ? $user->user_level : 0;
-
- if ( ! $user->exists() ) {
+ 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;