get_user_option( string $option, int $user = 0, string $deprecated = '' ): mixed
- Since
- 2.0.0
- Source
wp-includes/user.php:753
Description
If the user ID is not given, then the current user will be used instead. If the user ID is given, then the user data will be retrieved. The filter for the result, will also pass the original option name and finally the user data object as the third parameter.
The option will first check for the per site name and then the per Network name.
Compatibility
- WordPress
- since 2.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$optionstring- User option name.
$userintoptional- User ID.Default:
0 $deprecatedstringoptional- Use get_option() to check for an option in the options table.Default:
''
Return value
mixed- User option value on success, false on failure.
Performance profile
How much work a call to get_user_option() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 14–45
- Plugin surface
- 1 hook
- Called by
- 33
Reaches the database via get_user_by().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 53.
Third-party callbacks on 'get_user_option_{$option}' run inside this call, and their cost is not bounded by anything here.
33 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_user_by()one call below get_user_option()
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_user_option() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($deprecated) && !empty($user) | 14 | get_userdata() |
empty($deprecated) && empty($user) | 17 | get_current_user_id(), get_userdata() |
!empty($deprecated) && !empty($user) | 18 | _deprecated_argument(), get_userdata() |
!empty($deprecated) && empty($user) | 21 | _deprecated_argument(), get_current_user_id(), get_userdata() |
empty($deprecated) && !empty($user) && !->has_prop() | 34 | get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), apply_filters() |
empty($deprecated) && !empty($user) && ->has_prop() | 35 | get_userdata(), ->get_blog_prefix(), ->has_prop(), ->get(), apply_filters() |
empty($deprecated) && empty($user) && !->has_prop() | 37 | get_current_user_id(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), apply_filters() |
empty($deprecated) && !empty($user) | 38 | get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), ->get(), apply_filters() |
empty($deprecated) && empty($user) && ->has_prop() | 38 | get_current_user_id(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->get(), apply_filters() |
!empty($deprecated) && !empty($user) && !->has_prop() | 38 | _deprecated_argument(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), apply_filters() |
!empty($deprecated) && !empty($user) && ->has_prop() | 39 | _deprecated_argument(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->get(), apply_filters() |
empty($deprecated) && empty($user) | 41 | get_current_user_id(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), ->get(), apply_filters() |
4 further outcomes, up to 45 instructions
!empty($deprecated) && empty($user) && !->has_prop() | 41 | _deprecated_argument(), get_current_user_id(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), apply_filters() |
!empty($deprecated) && !empty($user) | 42 | _deprecated_argument(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), ->get(), apply_filters() |
!empty($deprecated) && empty($user) && ->has_prop() | 42 | _deprecated_argument(), get_current_user_id(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->get(), apply_filters() |
!empty($deprecated) && empty($user) | 45 | _deprecated_argument(), get_current_user_id(), get_userdata(), ->get_blog_prefix(), ->has_prop(), ->has_prop(), ->get(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 53 instructions, 14–45 executed per call, 5 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while get_user_option() runs, in this order:
- apply_filters( get_user_option_{$option} )filterline 789 (+36 into the body)
Filters a specific user option value.
Uses · 4
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- get_current_user_id()Gets the current user's ID.
- get_userdata()Retrieves user info by user ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 33
- WP_List_Table::get_items_per_page()Gets the number of items to display on a single page.
- WP_Plugin_Install_List_Table::prepare_items()
- WP_Screen::render_per_page_options()Renders the items per page option.
- WP_Screen::render_screen_meta()Renders the screen's help section.
- _get_admin_bar_pref()Retrieves the admin bar display preference of a user.
- admin_color_scheme_picker()Displays the default administration color scheme picker (Used in user-edit.php).
- auth_redirect()Checks if a user is logged in, if not it redirects them to the login page.
- default_password_nag()
- default_password_nag_edit_user()
- default_password_nag_handler()
- display_plugins_table()Displays plugin content based on plugin list.
- do_meta_boxes()Meta-Box template function.
Show all 33
- enqueue_comment_hotkeys_js()Enqueues comment shortcuts jQuery script.
- get_all_user_settings()Retrieves all user interface settings.
- get_hidden_columns()Get a list of hidden columns.
- get_hidden_meta_boxes()Gets an array of IDs of hidden meta boxes.
- iframe_header()Generic Iframe header for use with Thickbox.
- install_plugins_favorites_form()Shows a username form for the favorites page.
- postbox_classes()Returns the list of classes to be used by a meta box.
- user_can_richedit()Determines whether the user can access the visual editor.
- wp_ajax_get_community_events()Handles Ajax requests for community events
- wp_ajax_query_themes()Handles getting themes from themes_api() via AJAX.
- wp_color_scheme_settings()Outputs the JavaScript for the admin color scheme settings.
- wp_dashboard_quick_press()Displays the Quick Draft widget.
- wp_edit_attachments_query_vars()Returns the query variables for the current attachments request.
- wp_edit_posts_query()Runs the query to fetch the posts for listing on the edit posts page.
- wp_enqueue_media()Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.
- wp_iframe()Outputs the iframe to display the media upload page.
- wp_initial_nav_menu_meta_boxes()Limit the amount of meta boxes to pages, posts, links, and categories for first time users.
- wp_localize_community_events()Localizes community events data that needs to be passed to dashboard.js.
- wp_nav_menu_setup()Register nav menu meta boxes and advanced menu items.
- wp_style_loader_src()Administration Screen CSS for changing the styles.
- wp_user_settings()Saves and restores user interface settings stored in a cookie.
Source code
function get_user_option( $option, $user = 0, $deprecated = '' ) { global $wpdb; if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '3.0.0' ); } if ( empty( $user ) ) { $user = get_current_user_id(); } $user = get_userdata( $user ); if ( ! $user ) { return false; } $prefix = $wpdb->get_blog_prefix(); if ( $user->has_prop( $prefix . $option ) ) { // Blog-specific. $result = $user->get( $prefix . $option ); } elseif ( $user->has_prop( $option ) ) { // User-specific and cross-blog. $result = $user->get( $option ); } else { $result = false; } /** * Filters a specific user option value. * * The dynamic portion of the hook name, `$option`, refers to the user option name. * * @since 2.5.0 * * @param mixed $result Value for the user's option. * @param string $option Name of the option being retrieved. * @param WP_User $user WP_User object of the user whose option is being retrieved. */ return apply_filters( "get_user_option_{$option}", $result, $option, $user );}Changelog
Introduced in 2.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.