update_user_status

Update the status of a user in the database.

Description

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

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

Returns (int)

The initially passed $value.

Parameters (4)

0. $id (int)
The user ID.
1. $pref (string)
The column in the wp_users table to update the user's status in (presumably user_status, spam, or deleted).
2. $value (int)
The new status for the user.
3. $deprecated — Optional. (null) => null
Deprecated as of 3.0.2 and should not be used.

Usage

  1. if ( !function_exists( 'update_user_status' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ms.php'; 
  3.  
  4. // The user ID. 
  5. $id = -1; 
  6.  
  7. // The column in the wp_users table to update the user's status 
  8. // in (presumably user_status, spam, or deleted). 
  9. $pref = ''; 
  10.  
  11. // The new status for the user. 
  12. $value = -1; 
  13.  
  14. // Deprecated as of 3.0.2 and should not be used. 
  15. $deprecated = null; 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = update_user_status($id, $pref, $value, $deprecated); 
  19.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ms.php  
  1. function update_user_status( $id, $pref, $value, $deprecated = null ) { 
  2. global $wpdb; 
  3.  
  4. if ( null !== $deprecated ) 
  5. _deprecated_argument( __FUNCTION__, '3.0.2' ); 
  6.  
  7. $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) ); 
  8.  
  9. $user = new WP_User( $id ); 
  10. clean_user_cache( $user ); 
  11.  
  12. if ( $pref == 'spam' ) { 
  13. if ( $value == 1 ) { 
  14. /** 
  15. * Fires after the user is marked as a SPAM user. 
  16. * @since 3.0.0 
  17. * @param int $id ID of the user marked as SPAM. 
  18. */ 
  19. } else { 
  20. /** 
  21. * Fires after the user is marked as a HAM user. Opposite of SPAM. 
  22. * @since 3.0.0 
  23. * @param int $id ID of the user marked as HAM. 
  24. */ 
  25.  
  26. return $value;