Pass full user objects to clean_user_cache(). See #19500, fixes #20460.

Prevents notices when clean_user_cache() is called for a user that has been removed from the database.


git-svn-id: http://svn.automattic.com/wordpress/trunk@20522 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
duck_ 2012-04-18 21:07:31 +00:00
parent 715efd86f0
commit e641c48a72
3 changed files with 20 additions and 11 deletions

View File

@ -132,6 +132,7 @@ function wpmu_delete_user( $id ) {
global $wpdb;
$id = (int) $id;
$user = new WP_User( $id );
do_action( 'wpmu_delete_user', $id );
@ -162,7 +163,7 @@ function wpmu_delete_user( $id ) {
$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
$wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) );
clean_user_cache( $id );
clean_user_cache( $user );
// allow for commit transaction
do_action( 'deleted_user', $id );
@ -389,7 +390,8 @@ function update_user_status( $id, $pref, $value, $deprecated = null ) {
$wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
clean_user_cache( $id );
$user = new WP_User( $id );
clean_user_cache( $user );
if ( $pref == 'spam' ) {
if ( $value == 1 )
@ -407,7 +409,7 @@ function refresh_user_details( $id ) {
if ( !$user = get_userdata( $id ) )
return false;
clean_user_cache( $id );
clean_user_cache( $user );
return $id;
}

View File

@ -237,6 +237,7 @@ function wp_delete_user( $id, $reassign = 'novalue' ) {
global $wpdb;
$id = (int) $id;
$user = new WP_User( $id );
// allow for transaction statement
do_action('delete_user', $id);
@ -262,7 +263,7 @@ function wp_delete_user( $id, $reassign = 'novalue' ) {
$wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) );
}
clean_user_cache($id);
clean_user_cache( $user );
// FINALLY, delete user
if ( !is_multisite() ) {

View File

@ -1143,15 +1143,21 @@ function update_user_caches($user) {
*
* @since 3.0.0
*
* @param int $id User ID
* @param WP_User $user User object to be cleaned from the cache
*/
function clean_user_cache($id) {
$user = WP_User::get_data_by( 'id', $id );
function clean_user_cache( $user ) {
if ( is_numeric( $user ) ) {
_deprecated_argument( __FUNCTION__, '3.4', 'Pass the full user object instead of the ID.' );
$user = new WP_User( $user );
}
wp_cache_delete($id, 'users');
wp_cache_delete($user->user_login, 'userlogins');
wp_cache_delete($user->user_email, 'useremail');
wp_cache_delete($user->user_nicename, 'userslugs');
if ( ! $user->exists() )
return;
wp_cache_delete( $user->ID, 'users' );
wp_cache_delete( $user->user_login, 'userlogins' );
wp_cache_delete( $user->user_email, 'useremail' );
wp_cache_delete( $user->user_nicename, 'userslugs' );
}
/**