From ab27ecda6d58f521ba4641eeb1e1d816f93d21c4 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 29 Apr 2010 18:24:18 +0000 Subject: [PATCH] Reset the global current_user object when the current user is changed. git-svn-id: https://develop.svn.wordpress.org/trunk@14302 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/meta.php | 4 ++-- wp-includes/user.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 615fd05a94..06485b8609 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -61,7 +61,7 @@ function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = wp_cache_delete($object_id, $meta_type . '_meta'); // users cache stores usermeta that must be cleared. if ( 'user' == $meta_type ) - wp_cache_delete($object_id, 'users'); + clean_user_cache($object_id); do_action( "added_{$meta_type}_meta", $wpdb->insert_id, $object_id, $meta_key, $meta_value ); @@ -124,7 +124,7 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v wp_cache_delete($object_id, $meta_type . '_meta'); // users cache stores usermeta that must be cleared. if ( 'user' == $meta_type ) - wp_cache_delete($object_id, 'users'); + clean_user_cache($object_id); do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $meta_value ); diff --git a/wp-includes/user.php b/wp-includes/user.php index 61ee41cad9..0cc5c4c3ca 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -874,8 +874,17 @@ function update_user_caches(&$user) { * @param int $id User ID */ function clean_user_cache($id) { + global $current_user; + $user = new WP_User($id); + // If the current user changed, reset the current_user global.Π+ if ( isset($current_user) && $current_user->ID == $id ) { + $current_user->ID = -1; // Force wp_set_current_user to reset. + error_log(" Resetting current user "); + wp_set_current_user($id); + } + wp_cache_delete($id, 'users'); wp_cache_delete($user->user_login, 'userlogins'); wp_cache_delete($user->user_email, 'useremail');