set_user_setting( string $name, string $value )

Add or update user interface setting.


Description 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().


Parameters Parameters

$name

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

$value

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


Top ↑

Return Return

(bool|null) True if set successfully, false if not. Null if the current user can't be established.


Top ↑

Source 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

Changelog
Version Description
2.8.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Drew Jaynes

    Override the user setting to always collapse the admin menu for the current user:

    /**
     * Re-set user setting to always collapse the admin menu.
     *
     * @see set_user_setting()
     */
    function wpdocs_always_collapse_menu() {
    	if ( 'f' != get_user_setting( 'mfold' ) ) {
    		set_user_setting( 'mfold', 'f' );
    	}
    }
    add_action( 'admin_head', 'wpdocs_always_collapse_menu' );
    

You must log in before being able to contribute a note or feedback.