WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/update user option

Description

Update a user option that can be either per Site or per Network.

User options are just like user metadata except that they have support for blog-specific options when using multisite. If the $global parameter is false, which it is by default, it will prepend the WordPress table prefix to the option name.

Usage

<?php update_user_option$user_id$option_name$newvalue$global ?>

Parameters

$user_id
(integer) (required) User ID
Default: None
$option_name
(string) (required) User option name.
Default: None
$newvalue
(mixed) (required) User option value.
Default: None
$global
(boolean) (optional) Whether option name is blog specific or not.
Default: false

Return Values

(boolean) 
Whether the update was successful

Examples

Hide the admin bar for a user on the front end of the site:

update_user_option( $user_id, 'show_admin_bar_front', false );

When multisite is installed, the $global parameter can be used to set the user option for the whole network, instead of just the current site:

update_user_option( $user_id, 'show_admin_bar_front', false, true );

Notes

  • Uses global: (object) $wpdb WordPress database object for queries.

Change Log

Source File

update_user_option() is located in wp-includes/user.php.

Related

add_user_meta(), delete_user_meta(), get_user_meta(), update_user_meta(), get_user_option(), delete_user_option(), update_user_option(),

See also index of Function Reference and index of Template Tags.