Home  >  Article  >  Backend Development  >  Detailed explanation of the PHP functions used to update and obtain user option data in WordPress, wordpressphp_PHP tutorial

Detailed explanation of the PHP functions used to update and obtain user option data in WordPress, wordpressphp_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:57:491000browse

Detailed explanation of the PHP functions used to update and obtain user option data in WordPress, wordpressphp

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】

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

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

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

【Source file】

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


Articles you may be interested in:

  • Analysis of the PHP functions in WordPress that control user login and determine user login
  • A method to write a PHP script to clear the redundant code in the WordPress header Explain
  • Related PHP function analysis of custom headers in WordPress theme production
  • Related PHP function usage analysis of debugging thumbnails in WordPress
  • Customized menus in WordPress development Introduction to the use of related PHP functions
  • Analysis of the use of PHP functions used to obtain search forms in WordPress
  • Detailed explanation of related PHP functions for creating and adding filters in WordPress
  • Used in WordPress Explanation of PHP functions for creating and obtaining sidebars
  • Explanation of PHP functions for obtaining comment templates and search forms in WordPress
  • Related PHP function analysis for writing custom storage fields in WordPress

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106883.htmlTechArticleDetailed explanation of the PHP functions used to update and obtain user option data in WordPress, wordpressphp update_user_option() function update_user_option() function Function Utilizes global blog permissions to update user selections...
Statement:
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