update_user_status() - WordPress 函数参考中文文档

返回介绍

update_user_status()

发布于 2017-09-11 字数3387 浏览 878 评论 0

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

Update the status of a user in the database.


描述

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

更新日志

Version 描述
3.0.0 Introduced.

相关函数

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.

上一篇:update_user_option()

下一篇:upgrade_100()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!