Move most instances of new WP_User to get_userdata(). see #21120.

git-svn-id: http://core.svn.wordpress.org/trunk@21413 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-08-03 01:06:05 +00:00
parent 3a0841fee7
commit 7127ed1197
16 changed files with 56 additions and 59 deletions

View File

@ -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);
?>
<h2><?php _e('Your account is now active!'); ?></h2>

View File

@ -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');

View File

@ -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;

View File

@ -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) ) {

View File

@ -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 );

View File

@ -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:

View File

@ -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';

View File

@ -143,7 +143,7 @@ if ( $action ) {
if ( !is_user_member_of_blog( $user_id ) )
wp_die(__('Cheatin&#8217; uh?'));
$user = new WP_User( $user_id );
$user = get_userdata( $user_id );
$user->set_role( $_REQUEST['new_role'] );
}
} else {

View File

@ -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';

View File

@ -111,7 +111,7 @@ case 'promote':
if ( is_multisite() && !is_user_member_of_blog( $id ) )
wp_die(__('Cheatin&#8217; 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 "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\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 "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
} elseif ( !current_user_can('remove_user', $id) ) {

View File

@ -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;

View File

@ -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 {

View File

@ -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 )

View File

@ -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 );
}

View File

@ -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);

View File

@ -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(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), 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', __('<strong>ERROR</strong>: 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( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?' ),
$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;