Login function: wp_signon()
Function introduction:
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:
<?php wp_signon( $credentials, $secure_cookie ) ?>
Parameter description:
Note: If you do not provide $credentials, wp_signon uses the $_POST parameter (key values are "log", "pwd" and "rememberme").
Function return value:
(object)
The object WP_Error will be returned if the login fails, and WP_User will be returned if the login is successful. Function instance:
$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() 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:
<?php if ( is_user_logged_in() ) { ... } ?>
Function parameters:
This function does not accept any parameters.
Return value:
Return True if you have logged in, otherwise return False.
Function examples:
<?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.
The above has introduced the PHP functions that control user login and determine user login in WordPress, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.