delete_user_option()WP 3.0.0

Deletes user metadata on a site-wide or network-wide basis.

If you are not using multisite, then use the function delete_user_meta() instead.

User options are the same as user metadata. The difference is that options have a database table prefix set for the metadata, i.e., if we have a key username, then for the option it will look like this: wp_username (where wp_ is the prefix of the current site's tables).

If the parameter $global = false (which is the default), then the function will add the database table prefix to the name of the meta-field.

No Hooks.

Returns

true|false. true on successful deletion and false if the deletion failed.

Usage

delete_user_option( $user_id, $option_name, $global );
$user_id(integer) (required)
User ID.
$option_name(string) (required)
Option name.
$global(boolean)
Is the option global (across the network of sites) or does it relate only to one blog? Default is false - relates to the current blog.
Default: false

Examples

0

#1 Delete the metadata default_password_nag of the user with ID=8:

if( delete_user_option( 8, 'default_password_nag' ) )
	echo "the default_password_nag option has been removed!";
else
	echo "failed to remove the default_password_nag option!";

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 3.0.0 Introduced.

delete_user_option() code WP 6.9.1

function delete_user_option( $user_id, $option_name, $is_global = false ) {
	global $wpdb;

	if ( ! $is_global ) {
		$option_name = $wpdb->get_blog_prefix() . $option_name;
	}

	return delete_user_meta( $user_id, $option_name );
}