get_user_option

Retrieve user option that can be either per Site or per Network.

Description

get_user_option( (string) $option, (int) $user = 0, (string) $deprecated = '' ); 

If the user ID is not given, then the current user will be used instead. If the user ID is given, then the user data will be retrieved. The filter for the result, will also pass the original option name and finally the user data object as the third parameter.

The option will first check for the per site name and then the per Network name.

Parameters (3)

0. $option (string)
User option name.
1. $user — Optional. (int)
User ID.
2. $deprecated — Optional. (string) => ''
Use get_option() to check for an option in the options table.

Usage

  1. if ( !function_exists( 'get_user_option' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // User option name. 
  5. $option = ''; 
  6.  
  7. // Optional. User ID. 
  8. $user = -1; 
  9.  
  10. // Use get_option() to check for an option in the options table. 
  11. $deprecated = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_user_option($option, $user, $deprecated); 
  15.  

Defined (1)

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

/wp-includes/user.php  
  1. function get_user_option( $option, $user = 0, $deprecated = '' ) { 
  2. global $wpdb; 
  3.  
  4. if ( !empty( $deprecated ) ) 
  5. _deprecated_argument( __FUNCTION__, '3.0.0' ); 
  6.  
  7. if ( empty( $user ) ) 
  8. $user = get_current_user_id(); 
  9.  
  10. if ( ! $user = get_userdata( $user ) ) 
  11. return false; 
  12.  
  13. $prefix = $wpdb->get_blog_prefix(); 
  14. if ( $user->has_prop( $prefix . $option ) ) // Blog specific 
  15. $result = $user->get( $prefix . $option ); 
  16. elseif ( $user->has_prop( $option ) ) // User specific and cross-blog 
  17. $result = $user->get( $option ); 
  18. else 
  19. $result = false; 
  20.  
  21. /** 
  22. * Filters a specific user option value. 
  23. * The dynamic portion of the hook name, `$option`, refers to the user option name. 
  24. * @since 2.5.0 
  25. * @param mixed $result Value for the user's option. 
  26. * @param string $option Name of the option being retrieved. 
  27. * @param WP_User $user WP_User object of the user whose option is being retrieved. 
  28. */ 
  29. return apply_filters( "get_user_option_{$option}", $result, $option, $user );