Title: clean_user_cache
Published: April 25, 2014
Last modified: February 24, 2026

---

# clean_user_cache( WP_User|int $user )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#wp--skip-link--target)

Cleans all user caches.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#parameters)󠁿

 `$user`[WP_User](https://developer.wordpress.org/reference/classes/wp_user/)|intrequired

User object or ID to be cleaned from the cache

## 󠀁[Source](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#source)󠁿

    ```php
    function clean_user_cache( $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_nicename, 'userslugs' );

    	if ( ! empty( $user->user_email ) ) {
    		wp_cache_delete( $user->user_email, 'useremail' );
    	}

    	wp_cache_delete( $user->ID, 'user_meta' );
    	wp_cache_set_users_last_changed();

    	/**
    	 * 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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/user.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/user.php#L2019)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/user.php#L2019-L2048)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#hooks)󠁿

 [do_action( ‘clean_user_cache’, int $user_id, WP_User $user )](https://developer.wordpress.org/reference/hooks/clean_user_cache/)

Fires immediately after the given user’s cache is cleaned.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_cache_set_users_last_changed()](https://developer.wordpress.org/reference/functions/wp_cache_set_users_last_changed/)`wp-includes/user.php` |

Sets the last changed time for the ‘users’ cache group.

  | 
| [WP_User::__construct()](https://developer.wordpress.org/reference/classes/wp_user/__construct/)`wp-includes/class-wp-user.php` |

Constructor.

  | 
| [wp_cache_delete()](https://developer.wordpress.org/reference/functions/wp_cache_delete/)`wp-includes/cache.php` |

Removes the cache contents matching key and group.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#)

| Used by | Description | 
| [wpmu_delete_user()](https://developer.wordpress.org/reference/functions/wpmu_delete_user/)`wp-admin/includes/ms.php` |

Deletes a user and all of their posts from the network.

  | 
| [refresh_user_details()](https://developer.wordpress.org/reference/functions/refresh_user_details/)`wp-admin/includes/ms.php` |

Cleans the user cache for a specific user.

  | 
| [update_user_status()](https://developer.wordpress.org/reference/functions/update_user_status/)`wp-includes/ms-deprecated.php` |

Update the status of a user in the database.

  | 
| [wp_delete_user()](https://developer.wordpress.org/reference/functions/wp_delete_user/)`wp-admin/includes/user.php` |

Delete user and optionally reassign posts and links to another user.

  | 
| [wp_set_password()](https://developer.wordpress.org/reference/functions/wp_set_password/)`wp-includes/pluggable.php` |

Updates the user’s password with a new hashed one.

  | 
| [delete_usermeta()](https://developer.wordpress.org/reference/functions/delete_usermeta/)`wp-includes/deprecated.php` |

Remove user meta data.

  | 
| [update_usermeta()](https://developer.wordpress.org/reference/functions/update_usermeta/)`wp-includes/deprecated.php` |

Update metadata of user.

  | 
| [wp_update_user()](https://developer.wordpress.org/reference/functions/wp_update_user/)`wp-includes/user.php` |

Updates a user in the database.

  | 
| [wp_insert_user()](https://developer.wordpress.org/reference/functions/wp_insert_user/)`wp-includes/user.php` |

Inserts a user into the database.

  | 
| [add_user_to_blog()](https://developer.wordpress.org/reference/functions/add_user_to_blog/)`wp-includes/ms-functions.php` |

Adds a user to a blog, along with specifying the user’s role.

  | 
| [remove_user_from_blog()](https://developer.wordpress.org/reference/functions/remove_user_from_blog/)`wp-includes/ms-functions.php` |

Removes a user from a blog.

  |

[Show 6 more](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/clean_user_cache/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.0/) | User metadata caches are now cleared. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | `'clean_user_cache'` action was added. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fclean_user_cache%2F)
before being able to contribute a note or feedback.