set_user_setting( string $name, string $value )

Adds or updates 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().


Top ↑

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 otherwise. Null if the current user is not a member of the site.


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.