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; global $wpdb;
$id = (int) $id; $id = (int) $id;
$user = new WP_User( $id );
do_action( 'wpmu_delete_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->users, array( 'ID' => $id ) );
$wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) ); $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) );
clean_user_cache( $id ); clean_user_cache( $user );
// allow for commit transaction // allow for commit transaction
do_action( 'deleted_user', $id ); 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 ) ); $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 ( $pref == 'spam' ) {
if ( $value == 1 ) if ( $value == 1 )
@ -407,7 +409,7 @@ function refresh_user_details( $id ) {
if ( !$user = get_userdata( $id ) ) if ( !$user = get_userdata( $id ) )
return false; return false;
clean_user_cache( $id ); clean_user_cache( $user );
return $id; return $id;
} }

View File

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

View File

@ -1143,15 +1143,21 @@ function update_user_caches($user) {
* *
* @since 3.0.0 * @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) { function clean_user_cache( $user ) {
$user = WP_User::get_data_by( 'id', $id ); 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'); if ( ! $user->exists() )
wp_cache_delete($user->user_login, 'userlogins'); return;
wp_cache_delete($user->user_email, 'useremail');
wp_cache_delete($user->user_nicename, 'userslugs'); 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' );
} }
/** /**