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
This commit is contained in:
Ryan Boren 2010-04-29 18:24:18 +00:00
parent bd14ce7734
commit ab27ecda6d
2 changed files with 11 additions and 2 deletions

View File

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

View File

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