update_user_option

Update user option with global blog capability.

Description

(int|bool) update_user_option( (int) $user_id, (string) $option_name, (mixed) $newvalue, (bool) $global = false ); 

User options are just like user metadata except that they have support for global blog options. If the global parameter is false, which it is by default it will prepend the WordPress table prefix to the option name.

Deletes the user option if $newvalue is empty.

Returns (int|bool)

User meta ID if the option didn't exist, true on successful update, false on failure.

Parameters (4)

0. $user_id (int)
The user id.
1. $option_name (string)
User option name.
2. $newvalue (mixed)
User option value.
3. $global — Optional. (bool) => false
Whether option name is global or blog specific. Default false (blog specific).

Usage

  1. if ( !function_exists( 'update_user_option' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // User option name. 
  8. $option_name = ''; 
  9.  
  10. // User option value. 
  11. $newvalue = null; 
  12.  
  13. // Optional. Whether option name is global or blog specific. 
  14. // Default false (blog specific). 
  15. $global = false; 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = update_user_option($user_id, $option_name, $newvalue, $global); 
  19.  

Defined (1)

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

/wp-includes/user.php  
  1. function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { 
  2. global $wpdb; 
  3.  
  4. if ( !$global ) 
  5. $option_name = $wpdb->get_blog_prefix() . $option_name; 
  6.  
  7. return update_user_meta( $user_id, $option_name, $newvalue );