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:
<?php wp_signon( $credentials, $secure_cookie ) ?>
Parameter description:
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
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:
<?php if ( is_user_logged_in() ) { ... } ?>
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:
<?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.