clean_user_cache( WP_User|int $user )
- Since
- 3.0.0, 4.4.0, 6.2.0
- Source
wp-includes/user.php:2019
Compatibility
- WordPress
- since 6.2.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$userWP_User|int- User object or ID to be cleaned from the cache
Performance profile
How much work a call to clean_user_cache() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Constant
- Instructions
- 7–52
- Plugin surface
- 1 hook
- Called by
- 11
Only touches the object cache, via wp_cache_delete().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 53.
Third-party callbacks on 'clean_user_cache' run inside this call, and their cost is not bounded by anything here.
11 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_delete()called directly - hookthird-party callbacks
do_action()called directly
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost clean_user_cache() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!->exists() | 7–11 | ->exists() |
->exists() && empty($user) | 42–46 | ->exists(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_set_users_last_changed(), do_action() |
->exists() && !empty($user) | 48–52 | ->exists(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_set_users_last_changed(), do_action() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 53 | 7–52 | 3 | |
| 8.5 | 53 | 7–52 | 3 | |
| 8.4 | 53 | 7–52 | 3 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 55 | 9–54 | 3 | |
| 8.2 | 55 | 9–54 | 3 | |
| 8.1 | 55 | 9–54 | 3 | |
| 7.4 | 55 | 9–54 | 3 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while clean_user_cache() runs, in this order:
- do_action( clean_user_cache )actionline 2047 (+28 into the body)
Fires immediately after the given user's cache is cleaned.
Uses · 4
- wp_cache_delete()Removes the cache contents matching key and group.
- wp_cache_set_users_last_changed()Sets the last changed time for the 'users' cache group.
- do_action()Calls the callback functions that have been added to an action hook.
- WP_User::__construct()Constructor.
Used by · 11
- add_user_to_blog()Adds a user to a blog, along with specifying the user's role.
- delete_usermeta()Remove user meta data.
- refresh_user_details()Cleans the user cache for a specific user.
- remove_user_from_blog()Removes a user from a blog.
- update_user_status()Update the status of a user in the database.
- update_usermeta()Update metadata of user.
- wp_delete_user()Delete user and optionally reassign posts and links to another user.
- wp_insert_user()Inserts a user into the database.
- wp_set_password()Updates the user's password with a new hashed one.
- wp_update_user()Updates a user in the database.
- wpmu_delete_user()Deletes a user and all of their posts from the network.
Source code
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 );}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.