wppaste
WordPress

delete_usermeta( int $user_id, string $meta_key, mixed $meta_value = '' ): bool

Since
2.0.0
Source
wp-includes/deprecated.php:2232
Remove user meta data.

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

Reaches the database via ->get_row().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
12–85

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 98.

Plugin surface
2 hooks

Third-party callbacks on 'delete_usermeta', 'deleted_usermeta' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()called directly
  • cacheobject cachewp_cache_delete()called directly
  • serializeserialisationserialize()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.

WhenInstructionsCalls it makes
!$user_id12_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_id59–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) && $cur68–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) && $cur68–72_deprecated_function(), ->prepare(), ->get_row(), do_action(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete()
$user_id && $cur70–76_deprecated_function(), serialize(), ->prepare(), ->get_row(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete(), do_action()
$user_id && $cur70–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) && $cur79–81_deprecated_function(), ->prepare(), ->get_row(), do_action(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete(), do_action()
$user_id && $cur81–85_deprecated_function(), serialize(), ->prepare(), ->get_row(), do_action(), ->prepare(), ->query(), clean_user_cache(), wp_cache_delete(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev9812–858
8.59812–858
8.49812–8587 fewer instructions than PHP 8.3
8.310514–928
8.210514–928
8.110514–928
7.410514–928

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:

  1. do_action( delete_usermeta )actionline 2246 (+14 into the body)
  2. do_action( deleted_usermeta )actionline 2257 (+25 into the body)

Uses · 4

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

3.0.0
Deprecated. Use delete_user_meta()from the docblock
2.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.