clean_user_cache

Advertisement

Summery Summery

Clean all user caches

Syntax Syntax

clean_user_cache( WP_User|int $user )

Parameters Parameters

$user

(Required) User object or ID to be cleaned from the cache

Source Source

File: wp-includes/user.php

	wp_cache_add( $user->ID, $user, 'users' );
	wp_cache_add( $user->user_login, $user->ID, 'userlogins' );
	wp_cache_add( $user->user_email, $user->ID, 'useremail' );
	wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' );
}

/**
 * Clean all user caches
 *
 * @since 3.0.0
 * @since 4.4.0 'clean_user_cache' action was added.
 *
 * @param WP_User|int $user User object or ID to be cleaned from the cache
 */
function clean_user_cache( $user ) {
	if ( is_numeric( $user ) ) {
		$user = new WP_User( $user );
	}

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

	wp_cache_delete( $user->ID, 'users' );

Advertisement

Changelog Changelog

Changelog
Version Description
4.4.0 'clean_user_cache' action was added.
3.0.0 Introduced.

Advertisement

Leave a Reply