delete_user_setting() WordPress Function

The delete_user_setting() function deletes a user setting for the current user. This function is typically used when a user setting needs to be reset to the default value.

delete_user_setting( string $names ) #

Deletes user interface settings.


Description

Deleting settings would reset them to the defaults.

This function has to be used before any output has started as it calls setcookie().


Top ↑

Parameters

$names

(string)(Required)The name or array of names of the setting to be deleted.


Top ↑

Return

(bool|null) True if deleted successfully, false otherwise. Null if the current user is not a member of the site.


Top ↑

Source

File: wp-includes/option.php

function delete_user_setting( $names ) {
	if ( headers_sent() ) {
		return false;
	}

	$all_user_settings = get_all_user_settings();
	$names             = (array) $names;
	$deleted           = false;

	foreach ( $names as $name ) {
		if ( isset( $all_user_settings[ $name ] ) ) {
			unset( $all_user_settings[ $name ] );
			$deleted = true;
		}
	}

	if ( $deleted ) {
		return wp_set_all_user_settings( $all_user_settings );
	}

	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.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