On this page
update_user_status( int $id, string $pref, int $value, null $deprecated = null ): int
This function has been deprecated. Use wp_update_user() instead.
Update the status of a user in the database.
Description
Previously used in core to mark a user as spam or "ham" (not spam) in Multisite.
See also
Parameters
$idint Required-
The user ID.
$prefstring Required-
The column in the wp_users table to update the user's status in (presumably user_status, spam, or deleted).
$valueint Required-
The new status for the user.
$deprecatednull Optional-
Deprecated as of 3.0.2 and should not be used.
Default:
null
Return
int The initially passed $value.
Source
File: wp-includes/ms-deprecated.php. View all references
function update_user_status( $id, $pref, $value, $deprecated = null ) {
global $wpdb;
_deprecated_function( __FUNCTION__, '5.3.0', 'wp_update_user()' );
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 ( 'spam' === $pref ) {
if ( $value == 1 ) {
/** This filter is documented in wp-includes/user.php */
do_action( 'make_spam_user', $id );
} else {
/** This filter is documented in wp-includes/user.php */
do_action( 'make_ham_user', $id );
}
}
return $value;
}
Hooks
- do_action( 'make_ham_user',
int $user_id ) -
Fires after the user is marked as a HAM user. Opposite of SPAM.
- do_action( 'make_spam_user',
int $user_id ) -
Fires after the user is marked as a SPAM user.
Related
Uses
| Uses | Description |
|---|---|
| WP_User::__construct() wp-includes/class-wp-user.php | Constructor. |
| clean_user_cache() wp-includes/user.php | Cleans all user caches. |
| wpdb::update() wp-includes/class-wpdb.php | Updates a row in the table. |
| sanitize_key() wp-includes/formatting.php | Sanitizes a string key. |
| _deprecated_function() wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. |
| _deprecated_argument() wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
Changelog
| Version | Description |
|---|---|
| 5.3.0 | Use wp_update_user() |
| 3.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/update_user_status