clean_user_cache

Clean all user caches.

Description

clean_user_cache( (WP_User|int) $user ); 

Parameters (1)

0. $user (WP_User|int)
User object or ID to be cleaned from the cache

Usage

  1. if ( !function_exists( 'clean_user_cache' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // User object or ID to be cleaned from the cache 
  5. $user = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = clean_user_cache($user); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function clean_user_cache( $user ) { 
  2. if ( is_numeric( $user ) ) 
  3. $user = new WP_User( $user ); 
  4.  
  5. if ( ! $user->exists() ) 
  6. return; 
  7.  
  8. wp_cache_delete( $user->ID, 'users' ); 
  9. wp_cache_delete( $user->user_login, 'userlogins' ); 
  10. wp_cache_delete( $user->user_email, 'useremail' ); 
  11. wp_cache_delete( $user->user_nicename, 'userslugs' ); 
  12.  
  13. /** 
  14. * Fires immediately after the given user's cache is cleaned. 
  15. * @since 4.4.0 
  16. * @param int $user_id User ID. 
  17. * @param WP_User $user User object. 
  18. */ 
  19. do_action( 'clean_user_cache', $user->ID, $user );