返回介绍

update_user_status()

发布于 2017-09-11 11:06:45 字数 3385 浏览 948 评论 0 收藏 0

update_user_status( int $id,  string $pref,  int $value,  null $deprecated = null )

Update the status of a user in the database.


description

Used in core to mark a user as spam or "ham" (not spam) in Multisite.


参数

$id

(int) (Required) The user ID.

$pref

(string) (Required) The column in the wp_users table to update the user's status in (presumably user_status, spam, or deleted).

$value

(int) (Required) The new status for the user.

$deprecated

(null) (Optional) Deprecated as of 3.0.2 and should not be used.

Default value: null


返回值

(int) The initially passed $value.


源代码

File: wp-admin/includes/ms.php

function update_user_status( $id, $pref, $value, $deprecated = null ) {
	global $wpdb;

	if ( null !== $deprecated )
		_deprecated_argument( __FUNCTION__, '3.0.2' );

	$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );

	$user = new WP_User( $id );
	clean_user_cache( $user );

	if ( $pref == 'spam' ) {
		if ( $value == 1 ) {
			/**
			 * Fires after the user is marked as a SPAM user.
			 *
			 * @since 3.0.0
			 *
			 * @param int $id ID of the user marked as SPAM.
			 */
			do_action( 'make_spam_user', $id );
		} else {
			/**
			 * Fires after the user is marked as a HAM user. Opposite of SPAM.
			 *
			 * @since 3.0.0
			 *
			 * @param int $id ID of the user marked as HAM.
			 */
			do_action( 'make_ham_user', $id );
		}
	}

	return $value;
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-admin/includes/ms.php: make_spam_user
  • wp-admin/includes/ms.php: make_ham_user
  • wp-includes/class-wp-user.php: WP_User::__construct()
  • wp-includes/formatting.php: sanitize_key()
  • wp-includes/functions.php: _deprecated_argument()
  • wp-includes/plugin.php: do_action()
  • wp-includes/user.php: clean_user_cache()
  • wp-includes/wp-db.php: wpdb::update()
  • Show 3 more uses Hide more uses

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

    Mark a User as Spam
    Note: You can only do this on multisite installs!

    
    $user_id = 394;
    
    update_user_status( $user_id, 'spam', 1 );
    

    Mark a User as Ham

    
    $user_id = 394;
    
    update_user_status( $user_id, 'spam', 0 );
    

    Again, this will not work on single site installs.

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

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

发布评论

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