get_user_option
Retrieve user option that can be either per Site or per Network.
Description
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
if ( !function_exists( 'get_user_option' ) ) { require_once ABSPATH . WPINC . '/user.php'; } // User option name. $option = ''; // Optional. User ID. $user = -1; // Use get_option() to check for an option in the options table. $deprecated = ''; // NOTICE! Understand what this does before running. $result = get_user_option($option, $user, $deprecated);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/user.php
- function get_user_option( $option, $user = 0, $deprecated = '' ) {
- global $wpdb;
- if ( !empty( $deprecated ) )
- _deprecated_argument( __FUNCTION__, '3.0.0' );
- if ( empty( $user ) )
- $user = get_current_user_id();
- if ( ! $user = get_userdata( $user ) )
- return false;
- $prefix = $wpdb->get_blog_prefix();
- if ( $user->has_prop( $prefix . $option ) ) // Blog specific
- $result = $user->get( $prefix . $option );
- elseif ( $user->has_prop( $option ) ) // User specific and cross-blog
- $result = $user->get( $option );
- else
- $result = false;
- /**
- * Filters a specific user option value.
- *
- * The dynamic portion of the hook name, `$option`, refers to the user option name.
- *
- * @since 2.5.0
- *
- * @param mixed $result Value for the user's option.
- * @param string $option Name of the option being retrieved.
- */
- return apply_filters( "get_user_option_{$option}", $result, $option, $user );
- }