返回介绍

update_user_option()

发布于 2017-09-11 11:06:40 字数 4028 浏览 1003 评论 0 收藏 0

update_user_option( int $user_id,  string $option_name,  mixed $newvalue,  bool $global = false )

Update user option with global blog capability.


description

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

Deletes the user option if $newvalue is empty.


参数

$user_id

(int) (Required) User ID.

$option_name

(string) (Required) User option name.

$newvalue

(mixed) (Required) User option value.

$global

(bool) (Optional) Whether option name is global or blog specific. Default false (blog specific).

Default value: false


返回值

(int|bool) User meta ID if the option didn't exist, true on successful update, false on failure.


源代码

File: wp-includes/user.php

function update_user_option( $user_id, $option_name, $newvalue, $global = false ) {
	global $wpdb;

	if ( !$global )
		$option_name = $wpdb->get_blog_prefix() . $option_name;

	return update_user_meta( $user_id, $option_name, $newvalue );
}

更新日志

Versiondescription
2.0.0Introduced.

相关函数

Uses

  • wp-includes/user.php: update_user_meta()
  • wp-includes/wp-db.php: wpdb::get_blog_prefix()

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/dashboard.php: wp_dashboard_quick_press()
  • wp-admin/includes/upgrade.php: wp_install()
  • wp-admin/includes/user.php: default_password_nag_handler()
  • wp-admin/includes/user.php: default_password_nag_edit_user()
  • wp-admin/includes/ajax-actions.php: wp_ajax_closed_postboxes()
  • wp-admin/includes/ajax-actions.php: wp_ajax_hidden_columns()
  • wp-admin/includes/ajax-actions.php: wp_ajax_meta_box_order()
  • wp-admin/includes/nav-menu.php: wp_nav_menu_setup()
  • wp-admin/includes/nav-menu.php: wp_initial_nav_menu_meta_boxes()
  • wp-includes/option.php: wp_user_settings()
  • wp-includes/option.php: wp_set_all_user_settings()
  • wp-includes/option.php: delete_all_user_settings()
  • wp-includes/user.php: reset_password()
  • wp-includes/user.php: register_new_user()
  • Show 11 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

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

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

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

发布评论

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