set_user_setting() WordPress Function

The set_user_setting() function is used to store a user setting for the current user. The function accepts two arguments: the setting name and the setting value. The setting name is used to identify the setting, and the setting value is the value that will be stored for the setting.

set_user_setting( string $name, string $value ) #

Adds or updates user interface setting.


Description

Both $name and $value can contain only ASCII letters, numbers, hyphens, and underscores.

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


Top ↑

Parameters

$name

(string)(Required)The name of the setting.

$value

(string)(Required)The value for the setting.


Top ↑

Return

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


Top ↑

Source

File: wp-includes/option.php

function set_user_setting( $name, $value ) {
	if ( headers_sent() ) {
		return false;
	}

	$all_user_settings          = get_all_user_settings();
	$all_user_settings[ $name ] = $value;

	return wp_set_all_user_settings( $all_user_settings );
}


Top ↑

Changelog

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