Parsing PHP functions that control user login and judge user login in WordPress

Source: Internet
Author: User
Login function: Wp_signon ()

Function Description:
The Wp_signon () function is used to authorize users to log on to WordPress and remember the user name. This function replaces the wp_login. The WordPress 2.5 version is enabled.

function use:

Parameter description:

    • $credentials
    • (array) (optional) login user information.
    • Default:none
    • $secure _cookie
    • (Boolean) (optional) Decide whether to use a security cookie.
    • Default:none

Note: If you do not provide a $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 successful 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-&G T;get_error_message ();

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

Determine if the user is logged in: is_user_logged_in ()

Function Description:
The is_user_logged_in () function returns false because it determines whether the user is logged on or not and returns true if the user has logged in.

function use:

Function parameters:
The function does not accept any arguments.

return value:
(Boolean)
Logged in returns True, otherwise false is returned.

function instance:
The following example shows what is displayed by the logged on user or the user who is not logged in:

<?phpif (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 describes the analysis of the WordPress control user login and judge the user login PHP function, including the content, I hope the PHP tutorial interested in a friend to help.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.