On this page
clean_user_cache( WP_User|int $user )
Cleans all user caches.
Parameters
$userWP_User|int Required-
User object or ID to be cleaned from the cache
Source
File: wp-includes/user.php. View all references
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' );
}
/**
* 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 );
}
Hooks
- do_action( 'clean_user_cache',
int $user_id ,WP_User $user ) -
Fires immediately after the given user’s cache is cleaned.
Related
Uses
| Uses | Description |
|---|---|
| WP_User::__construct() wp-includes/class-wp-user.php | Constructor. |
| wp_cache_delete() wp-includes/cache.php | Removes the cache contents matching key and group. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
Used By
| Used By | Description |
|---|---|
| wpmu_delete_user() wp-admin/includes/ms.php | Delete a user from the network and remove from all sites. |
| refresh_user_details() wp-admin/includes/ms.php | Cleans the user cache for a specific user. |
| update_user_status() wp-includes/ms-deprecated.php | Update the status of a user in the database. |
| wp_delete_user() wp-admin/includes/user.php | Remove user and optionally reassign posts and links to another user. |
| wp_set_password() wp-includes/pluggable.php | Updates the user’s password with a new encrypted one. |
| delete_usermeta() wp-includes/deprecated.php | Remove user meta data. |
| update_usermeta() wp-includes/deprecated.php | Update metadata of user. |
| wp_update_user() wp-includes/user.php | Updates a user in the database. |
| wp_insert_user() wp-includes/user.php | Inserts a user into the database. |
| add_user_to_blog() wp-includes/ms-functions.php | Adds a user to a blog, along with specifying the user’s role. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/clean_user_cache