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