update_user_status()更新用户状态

目录

描述

Update the status of a user in the database. Used in core to mark a user as spam or "ham" (not spam) on multisite installs.

update_user_status() 描述

用法

<?php update_user_status$id$pref$value ); ?>

update_user_status() 用法

参数

$id

(integer) (必填) The ID of the user.

默认值: None

$pref

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

默认值: None

$value

(integer) (必填) The new status for the user.

默认值: None

$deprecated

(null) (可选) This parameter is deprecated and should not be used.

默认值: null

update_user_status() 参数

示例

Mark a User as Spam

Note: You can only do this on multisite installs!

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

$user_id = 394;

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

Mark a User as Ham

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

$user_id = 394;

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

Again, this will not work on single site installs.

update_user_status() 示例

注意

update_user_status() 注意

历史

  • 3.0.2: The $refresh parameter was deprecated.
  • 添加于 版本: 3.0.0

update_user_status() 历史

源文件

update_user_status() 函数的代码位于 wp-admin/includes/ms.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Update the status of a user in the database.
 *
 * Used in core to mark a user as spam or "ham" (not spam) in Multisite.
 *
 * @since 3.0.0
 *
 * @global wpdb $wpdb
 *
 * @param int    $id         The user ID.
 * @param string $pref       The column in the wp_users table to update the user's status
 *                           in (presumably user_status, spam, or deleted).
 * @param int    $value      The new status for the user.
 * @param null   $deprecated Deprecated as of 3.0.2 and should not be used.
 * @return int   The initially passed $value.
 */
function update_user_status( $id, $pref, $value, $deprecated = null ) {
	global $wpdb;

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

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

update_user_status() 源文件