Home > Article > Backend Development > Detailed explanation of the PHP functions used to update and obtain user option data in WordPress, wordpressphp_PHP tutorial
update_user_option() function
The update_user_option() function uses global blog permissions to update user options.
User options are similar to user metadata, the only difference is that user options support global blog options. If the 'global' parameter is False (the default), update_user_option will prefix the WordPress table with the option name.
【Function usage】
<?php update_user_option( $user_id, $option_name, $newvalue, $global ) ?>
[Function parameters]
$user_id
(integer) (required) user ID
Default value: None
$option_name
(String) (required) User option name
Default value: 0
$newvalue
(Mixed) (Required) User option value
Default value: None
$global
(boolean) (optional) Whether the option name is blog-specific
Default value: false
【Return value】
(boolean)
Returns True on success, False on failure
【Source file】
update_user_option()) is located in wp-includes/user.php.
wordpress get_user_option() function
get_user_option() function
【Function Introduction】
Retrieve user options, including global, user or blog.
If no user ID is given, the current user ID is used. If a user ID is given, retrieve data related to that user. The filter for the function result passes the original option name and the end-user database object as the third argument.
The options function looks first for non-global names, then for global names, and if still not found, the function looks for blog options. Options can be set or modified via plugins.
【Function Usage】
<?php get_user_option( $option, $user, $check_blog_options ) ?>
[Parameter introduction]
$option
(String) (required) User option name
Default value: None
$user
(integer) (optional) User ID
Default value: 0
$check_blog_options
(boolean) (optional) Whether to look for an option in the options table if the previous user option does not exist
Default value: true
【Return value】
(Mixed)
Returns the value of the option successfully, returns FALSE
【Function Example】
<?php $bar = get_user_option( 'show_admin_bar_front', get_current_user_id() ); if( $bar == 'true' ) { echo 'The admin bar is enabled'; } else { echo 'The admin bar is disabled'; } ?>
【Source file】
get_user_option() is located in wp-includes/user.php.