set_user_setting

The timeline below displays how wordpress function set_user_setting has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Adds or updates user interface setting.
 *
 * 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()`.
 *
 * @since 2.8.0
 *
 * @param string $name  The name of the setting.
 * @param string $value The value for the setting.
 * @return bool|null True if set successfully, false otherwise.
 *                   Null if the current user is not a member of the site.
 */
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);
}

WordPress Version: 5.5

/**
 * Adds or updates user interface setting.
 *
 * 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().
 *
 * @since 2.8.0
 *
 * @param string $name  The name of the setting.
 * @param string $value The value for the setting.
 * @return bool|null True if set successfully, false otherwise.
 *                   Null if the current user is not a member of the site.
 */
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);
}

WordPress Version: 5.4

/**
 * Adds or updates user interface setting.
 *
 * 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().
 *
 * @since 2.8.0
 *
 * @param string $name  The name of the setting.
 * @param string $value The value for the setting.
 * @return bool|null True if set successfully, false if not. Null if the current user can't be established.
 */
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);
}

WordPress Version: 5.3

/**
 * Add or update user interface setting.
 *
 * 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().
 *
 * @since 2.8.0
 *
 * @param string $name  The name of the setting.
 * @param string $value The value for the setting.
 * @return bool|null True if set successfully, false if not. Null if the current user can't be established.
 */
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);
}

WordPress Version: 4.6

/**
 * Add or update user interface setting.
 *
 * 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().
 *
 * @since 2.8.0
 *
 * @param string $name  The name of the setting.
 * @param string $value The value for the setting.
 * @return bool|null True if set successfully, false if not. Null if the current user can't be established.
 */
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);
}

WordPress Version: 4.3

/**
 * Add or update user interface setting.
 *
 * 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().
 *
 * @since 2.8.0
 *
 * @param string $name  The name of the setting.
 * @param string $value The value for the setting.
 * @return bool|void true if set successfully/false if not.
 */
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);
}

WordPress Version: 4.1

/**
 * Add or update user interface setting.
 *
 * 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().
 *
 * @since 2.8.0
 *
 * @param string $name The name of the setting.
 * @param string $value The value for the setting.
 * @return null|bool true if set successfully/false if not.
 */
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);
}

WordPress Version: 3.9

/**
 * Add or update user interface setting.
 *
 * 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().
 *
 * @since 2.8.0
 *
 * @param string $name The name of the setting.
 * @param string $value The value for the setting.
 * @return bool true if set successfully/false if not.
 */
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);
}

WordPress Version: 3.7

/**
 * Add or update user interface setting.
 *
 * 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().
 *
 * @package WordPress
 * @subpackage Option
 * @since 2.8.0
 *
 * @param string $name The name of the setting.
 * @param string $value The value for the setting.
 * @return bool true if set successfully/false if not.
 */
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);
}