WordPress at Your Fingertips
function is not described

clean_user_cache() WP 3.0.0

Clean all user caches

Hooks from the function

Return

null. Nothing.

Usage

clean_user_cache( $user );
$user(WP_User|int) (required)
User object or ID to be cleaned from the cache

Notes

  • Global. WP_User. $current_user The current user object which holds the user data.

Changelog

Since 4.4.0 clean_user_cache was added.
Since 5.8.0 Refreshes the global user instance if cleaning the user cache for the current user.

Code of clean_user_cache() WP 5.8.3

function clean_user_cache( $user ) {
	global $current_user;

	if ( is_numeric( $user ) ) {
		$user = new WP_User( $user );
	}

	if ( ! $user->exists() ) {
		return;
	}

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

	/**
	 * Fires immediately after the given user's cache is cleaned.
	 *
	 * @since 4.4.0
	 *
	 * @param int     $user_id User ID.
	 * @param WP_User $user    User object.
	 */
	do_action( 'clean_user_cache', $user->ID, $user );

	// Refresh the global user instance if the cleaning current user.
	if ( get_current_user_id() === (int) $user->ID ) {
		$user_id      = (int) $user->ID;
		$current_user = null;
		wp_set_current_user( $user_id, '' );
	}
}