delete_usermeta( int $user_id, string $meta_key, mixed $meta_value = '' ): bool
- Since
- 2.0.0
- Source
wp-includes/deprecated.php:2229
Compatibility
Deprecated in WordPress 3.0.0. Use delete_user_meta()
- WordPress
- since 2.0.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
$user_idint- User ID.
$meta_keystring- Metadata key.
$meta_valuemixedoptional- Metadata value. Default empty.Default:
''
Return value
bool- True deletion completed and false if user_id is not a number.
Performance profile
How much work a call to delete_usermeta() 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
- Heavy
- Scaling
- Constant
- Instructions
- 12–85
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches the database via ->get_row().
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 98.
Third-party callbacks on 'delete_usermeta', 'deleted_usermeta' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()called directly - cacheobject cache
wp_cache_delete()called directly - serializeserialisation
serialize()called directly - sqldatabase query
->get_row()called directly
Further down the call graph this can also reach query, option and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 9 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost delete_usermeta() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$user_id | 12 | _deprecated_function() |
$user_id && !is_array($meta_value) && !is_object($meta_value) | 57–63 | _deprecated_function(), ->prepare(), ->get_row(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete() |
$user_id | 59–67 | _deprecated_function(), serialize(), ->prepare(), ->get_row(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete() |
$user_id && !is_array($meta_value) && !is_object($meta_value) && $cur | 68–72 | _deprecated_function(), ->prepare(), ->get_row(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete(), do_action() |
$user_id && !is_array($meta_value) && !is_object($meta_value) && $cur | 68–72 | _deprecated_function(), ->prepare(), ->get_row(), do_action(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete() |
$user_id && $cur | 70–76 | _deprecated_function(), serialize(), ->prepare(), ->get_row(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete(), do_action() |
$user_id && $cur | 70–76 | _deprecated_function(), serialize(), ->prepare(), ->get_row(), do_action(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete() |
$user_id && !is_array($meta_value) && !is_object($meta_value) && $cur | 79–81 | _deprecated_function(), ->prepare(), ->get_row(), do_action(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete(), do_action() |
$user_id && $cur | 81–85 | _deprecated_function(), serialize(), ->prepare(), ->get_row(), do_action(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete(), do_action() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 98 | 12–85 | 8 | |
| 8.5 | 98 | 12–85 | 8 | |
| 8.4 | 98 | 12–85 | 8 | 7 fewer instructions than PHP 8.3 |
| 8.3 | 105 | 14–92 | 8 | |
| 8.2 | 105 | 14–92 | 8 | |
| 8.1 | 105 | 14–92 | 8 | |
| 7.4 | 105 | 14–92 | 8 |
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 · 2
2 hooks fire while delete_usermeta() runs, in this order:
- do_action( delete_usermeta )actionline 2243 (+14 into the body)
- do_action( deleted_usermeta )actionline 2254 (+25 into the body)
Uses · 4
- _deprecated_function()Marks a function as deprecated and inform when it has been used.
- do_action()Calls the callback functions that have been added to an action hook.
- clean_user_cache()Cleans all user caches.
- wp_cache_delete()Removes the cache contents matching key and group.
Used by · 1
- update_usermeta()Update metadata of user.
Source code
function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) { _deprecated_function( __FUNCTION__, '3.0.0', 'delete_user_meta()' ); global $wpdb; if ( !is_numeric( $user_id ) ) return false; $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if ( is_array($meta_value) || is_object($meta_value) ) $meta_value = serialize($meta_value); $meta_value = trim( $meta_value ); $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); if ( $cur && $cur->umeta_id ) do_action( 'delete_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); if ( ! empty($meta_value) ) $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s", $user_id, $meta_key, $meta_value) ); else $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); clean_user_cache( $user_id ); wp_cache_delete( $user_id, 'user_meta' ); if ( $cur && $cur->umeta_id ) do_action( 'deleted_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); return true;}Changelog
Introduced in 2.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/deprecated.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.