返回介绍

get_user_option()

发布于 2017-09-11 00:45:40 字数 5946 浏览 1315 评论 0 收藏 0

get_user_option( string $option,  int $user,  string $deprecated = '' )

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


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.


参数

$option

(string) (Required) User option name.

$user

(int) (Optional) User ID.

$deprecated

(string) (Optional) Use get_option() to check for an option in the options table.

Default value: ''


返回值

(mixed) User option value on success, false on failure.


源代码

File: wp-includes/user.php

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();

	if ( ! $user = get_userdata( $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 );
}

更新日志

Versiondescription
2.0.0Introduced.

相关函数

Uses

  • wp-includes/pluggable.php: get_userdata()
  • wp-includes/functions.php: _deprecated_argument()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/user.php: get_user_option_{$option}
  • wp-includes/user.php: get_current_user_id()
  • wp-includes/wp-db.php: wpdb::get_blog_prefix()
  • Show 1 more use Hide more uses

Used By

  • wp-includes/script-loader.php: wp_localize_community_events()
  • wp-admin/includes/ajax-actions.php: wp_ajax_get_community_events()
  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::html()
  • wp-admin/includes/post.php: wp_edit_attachments_query_vars()
  • wp-admin/includes/class-wp-screen.php: WP_Screen::render_per_page_options()
  • wp-admin/includes/class-wp-screen.php: WP_Screen::render_screen_meta()
  • wp-admin/includes/screen.php: get_hidden_columns()
  • wp-admin/includes/screen.php: get_hidden_meta_boxes()
  • wp-admin/includes/class-wp-list-table.php: WP_List_Table::get_items_per_page()
  • wp-admin/includes/misc.php: admin_color_scheme_picker()
  • wp-admin/includes/misc.php: wp_color_scheme_settings()
  • wp-admin/includes/plugin-install.php: install_plugins_favorites_form()
  • wp-admin/includes/plugin-install.php: display_plugins_table()
  • wp-admin/includes/dashboard.php: wp_dashboard_quick_press()
  • wp-admin/includes/user.php: default_password_nag_handler()
  • wp-admin/includes/user.php: default_password_nag_edit_user()
  • wp-admin/includes/user.php: default_password_nag()
  • wp-admin/includes/class-wp-plugin-install-list-table.php: WP_Plugin_Install_List_Table::prepare_items()
  • wp-admin/includes/template.php: do_meta_boxes()
  • wp-admin/includes/post.php: wp_edit_posts_query()
  • wp-admin/includes/post.php: postbox_classes()
  • wp-admin/includes/ajax-actions.php: wp_ajax_query_themes()
  • wp-admin/includes/nav-menu.php: wp_nav_menu_setup()
  • wp-admin/includes/nav-menu.php: wp_initial_nav_menu_meta_boxes()
  • wp-admin/includes/comment.php: enqueue_comment_hotkeys_js()
  • wp-includes/pluggable.php: auth_redirect()
  • wp-includes/general-template.php: user_can_richedit()
  • wp-includes/admin-bar.php: _get_admin_bar_pref()
  • wp-includes/option.php: wp_user_settings()
  • wp-includes/option.php: get_all_user_settings()
  • wp-includes/script-loader.php: wp_style_loader_src()
  • Show 26 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    
    $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';
    }
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文