Warning: This function has been deprecated. Use delete_user_meta() instead.

delete_usermeta() WordPress Function

The delete_usermeta() function is used to delete user meta data from the database. It takes two arguments, the user ID and the meta key, and returns true on success or false on failure.

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

Remove user meta data.


Description

Top ↑

See also


Top ↑

Parameters

$user_id

(int)(Required)User ID.

$meta_key

(string)(Required)Metadata key.

$meta_value

(mixed)(Optional) Metadata value.

Default value: ''


Top ↑

Return

(bool) True deletion completed and false if user_id is not a number.


Top ↑

Source

File: wp-includes/deprecated.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Use delete_user_meta()
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More