The get_user_option() WordPress PHP function retrieves a user option that can be either per Site or per Network.
Usage
get_user_option( $option, $user_id, $deprecated );
Example:
Input:
get_user_option( 'color_scheme', 1 );
Output:
'light'
Parameters
$option
(string) (Required) – User option name.$user_id
(int) (Optional) – User ID. Defaults to the current user.$deprecated
(string) (Optional) – Useget_option()
to check for an option in the options table. Default:''
.
More information
See WordPress Developer Resources: get_user_option()
Examples
Get color scheme of the current user
Get the color scheme preference of the currently logged-in user.
$color_scheme = get_user_option('color_scheme'); echo "The current user's color scheme is: " . $color_scheme;
Check if the admin bar is enabled for a specific user
Determine if the admin bar is enabled or disabled for user with ID 2.
$admin_bar = get_user_option('show_admin_bar_front', 2); if ($admin_bar == 'true') { echo 'The admin bar is enabled'; } else { echo 'The admin bar is disabled'; }
Get the timezone string for a specific user
Retrieve the timezone string for user with ID 3.
$timezone_string = get_user_option('timezone_string', 3); echo "The user's timezone is: " . $timezone_string;
Get the user’s posts per page preference
Get the preferred number of posts per page for the current user.
$posts_per_page = get_user_option('posts_per_page'); echo "The current user prefers to display " . $posts_per_page . " posts per page.";
Check if visual editor is disabled for a user
Determine if the visual editor is disabled for user with ID 4.
$rich_editing = get_user_option('rich_editing', 4); if ($rich_editing == 'false') { echo 'The visual editor is disabled'; } else { echo 'The visual editor is enabled'; }