Analysis of WordPress Control user Login and judge user login PHP function _php skills

Source: Internet
Author: User
Tags wordpress version

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.

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.