WordPress at a glance

update_user_status() WP 1.0

Update the status of a user in the database.

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

  • Global. wpdb. $wpdb WordPress database abstraction object.
Hooks from function:
Return

Int. The initially passed $value.

Usage

update_user_status( $id, $pref, $value, $deprecated );
$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)
Deprecated as of 3.0.2 and should not be used.
Default: null

Code of update_user_status: wp-admin/includes/ms.php VER 4.9.8

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

Related Functions

From tag: statuses (of post comment user)

More from tag: Users (_user)

More from category: Multisite

No comments
    Hello, !     Log In . Register