set_user_setting

Add or update user interface setting.

Description

(bool|null) set_user_setting( (string) $name, (string) $value ); 

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

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

Returns (bool|null)

True if set successfully, false if not. Null if the current user can't be established.

Parameters (2)

0. $name (string)
The name of the setting.
1. $value (string)
The value for the setting.

Usage

  1. if ( !function_exists( 'set_user_setting' ) ) { 
  2. require_once ABSPATH . WPINC . '/option.php'; 
  3.  
  4. // The name of the setting. 
  5. $name = ''; 
  6.  
  7. // The value for the setting. 
  8. $value = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = set_user_setting($name, $value); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/option.php  
  1. function set_user_setting( $name, $value ) { 
  2. if ( headers_sent() ) { 
  3. return false; 
  4.  
  5. $all_user_settings = get_all_user_settings(); 
  6. $all_user_settings[$name] = $value; 
  7.  
  8. return wp_set_all_user_settings( $all_user_settings );