Detailed explanation of PHP functions used to update and obtain user option data in WordPress_php skills

WBOY
Release: 2016-05-16 19:57:14
Original
1040 people have browsed it

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 to the option name.

【Function usage】

<&#63;php update_user_option( $user_id, $option_name, $newvalue, $global ) &#63;>
Copy after login

[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】

<&#63;php get_user_option( $option, $user, $check_blog_options ) &#63;> 
Copy after login

[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

on failure

【Function Example】

<&#63;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';
 }
&#63;>
Copy after login

【Source file】

get_user_option() is located in wp-includes/user.php.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!