WordPress.org

Codex

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

Function Reference/get user option

Description

Retrieve user option that can be either per Site or per Network.

If the user ID is not given, then the current user will be used instead. The filter for the result will also pass the original option name and finally the user data object as the third parameter.

The function will first check for the site-specific user metadata, then the network-wide user metadata. The option can either be modified or set by a plugin.

Usage

<?php get_user_option$option$user ?>

Parameters

$option
(string) (required) User option name.
Default: None
$user
(integer) (optional) User ID. If not given, the current user will be used.
Default: 0
$deprecated
(string) (optional) This parameter is no longer used. Setting it will generate a deprecated argument notice.
Default: Empty string

Return Values

(mixed) 
Option value on success, false on failure

Examples

<?php

$bar = get_user_option( 'show_admin_bar_front', get_current_user_id() );

if (  $bar == 'true' ) {
	echo 'The admin bar is enabled';
} else {
	echo 'The admin bar is disabled';
}

?>

Notes

  • Uses: apply_filters() Calls 'get_user_option_$option' hook with result, option parameter, and user data object.
  • Uses global: (object) $wpdb WordPress database object for queries.

Change Log

  • 3.0.0 - The $check_blog_options parameter was deprecated, and the function no longer checks the options table if the option isn't found in wp_usermeta. See #11615.
  • Since: 2.0.0

Source File

get_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.