Login function: Wp_signon ()
Function Description:
The Wp_signon () function is used to authorize users to login to WordPress and to remember the user name. This function replaces the wp_login. WordPress version 2.5 is enabled.
function uses:
<?php Wp_signon ($credentials, $secure _cookie)?>
Parameter description:
- $credentials
- (array) (optional) login user information.
- Default:none
- $secure _cookie
- (Boolean) Optionally, decide whether to use a secure cookie.
- Default:none
Note: If you do not provide $credentials, Wp_signon uses the $_post parameter (the key value is "log", "pwd" and "RememberMe").
function return value:
(object)
Login failed return object Wp_error, login success return Wp_user
function instance:
$creds = Array ();
$creds [' user_login '] = ' example '; Wordperss background User name
$creds [' user_password '] = ' 123456 ';//wordperss background user password
$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.
Determine whether the user login function: is_user_logged_in ()
Function Description:
The is_user_logged_in () function returns False if the user has logged in to return True because it determines whether the user is logged in.
function uses:
<?php if (is_user_logged_in ()) {...}?>
Function arguments:
The function does not accept any arguments.
return value:
(Boolean)
Login returns True, otherwise returns false.
function instance:
The following example shows what is displayed by a logged in user or a user who is not logged in:
<?php
if (is_user_logged_in ()) {
echo ' Welcome, registered user! ';
} else {
echo ' Welcome, visitor! ' ;
}
? >
Source file:
Is_user_logged_in () is located in the file wp-includes/pluggable.php.