Home  >  Article  >  Backend Development  >  Analyze the PHP functions in WordPress that control user login and determine user login, wordpress user login_PHP tutorial

Analyze the PHP functions in WordPress that control user login and determine user login, wordpress user login_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:58:11854browse

Analysis of the PHP functions in WordPress that control user login and determine user login, WordPress user login

Login function: wp_signon()

Function introduction:
The wp_signon() function is used to authorize users to log in to WordPress and remember the user name. This function replaces wp_login. Enabled from WordPress version 2.5.

Function usage:

<&#63;php wp_signon( $credentials, $secure_cookie ) &#63;> 

Parameter description:

  • $credentials
  • (array) (optional) Login user information.
  • Default: None
  • $secure_cookie
  • (boolean) (optional) Determines whether to use secure cookies.
  • Default: None

Note: If you do not provide $credentials, wp_signon uses the $_POST parameter (the key values ​​are "log", "pwd" and "rememberme").

Function return value:
(object)
The object WP_Error is returned if the login fails, and WP_User

is returned if the login is successful.

Function example:

$creds = array();
$creds['user_login'] = 'example'; //wordperss后台用户名称
$creds['user_password'] = '123456'; //wordperss后台用户密码
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
  echo $user->get_error_message();

Source file:
wp_signon() is located in wp-includes/user.php.

Function to determine whether the user is logged in: is_user_logged_in()

Function introduction:
The is_user_logged_in() function determines whether the user is logged in. If the user is logged in, it returns True otherwise it returns False.

Function usage:

<&#63;php if ( is_user_logged_in() ) { ... } &#63;> 

Function parameters:
This function does not accept any parameters.

Return value:
(boolean)
Returns True if logged in, otherwise returns False.

Function instance:
The following example shows the content displayed by logged in users or non-logged in users:

<&#63;php
if ( is_user_logged_in() ) {
  echo 'Welcome, registered user!';
} else {
  echo 'Welcome, visitor!';
}
&#63;>

Source file:
is_user_logged_in() is located in the file wp-includes/pluggable.php.

Articles you may be interested in:

  • Close the login page after logging in in WordPress and set up invisible columns for users
  • Example sharing of PHP scripts to implement email reminders for visitor login in WordPress

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1105377.htmlTechArticleAnalysis of the PHP functions in WordPress that control user login and determine user login, WordPress user login login function: wp_signon() function Introduction: The wp_signon() function is used to authorize user login...
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