Permalink
Browse files

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
  • Loading branch information...
1 parent 715efd8 commit e641c48a725b1e18a2b531fa49a55c4d245f3751 duck_ committed Apr 18, 2012
Showing with 20 additions and 11 deletions.
  1. +5 −3 wp-admin/includes/ms.php
  2. +2 −1 wp-admin/includes/user.php
  3. +13 −7 wp-includes/user.php
View
@@ -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;
}
@@ -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
@@ -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 );
+ }
+
+ if ( ! $user->exists() )
+ return;
- 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');
+ 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' );
}
/**

0 comments on commit e641c48

Please sign in to comment.