Parse the PHP functions that control user login and determine user login in WordPress. wordpress User Login

Source: Internet
Author: User

Parse the PHP functions that control user login and determine user login in WordPress. wordpress User Login

Login function: wp_signon ()

Function introduction:
The wp_signon () function is used to authorize a user to log on to wordpress and remember the user name. This function replaces wp_login. Start WordPress 2.5.

Function usage:

<?php wp_signon( $credentials, $secure_cookie ) ?> 

Parameter description:

  • $ Credentials
  • (Array) (optional) login user information.
  • Default: None
  • $ Secure_cookie
  • (Boolean) (optional) determines whether to use a secure cookie.
  • Default: None

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)
WP_Error is returned when logon fails. If logon succeeds, WP_User is returned.

Function example:

$ Creds = array (); $ creds ['user _ login'] = 'example '; // wordperss background user name $ creds ['user _ password'] = '000000'; // 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-nodes des/user. php.

Determine whether the user logs in to the function: is_user_logged_in ()

Function introduction:
The is_user_logged_in () function determines whether a user has logged on. If the user has logged on, True is returned. Otherwise, False is returned.

Function usage:

<?php if ( is_user_logged_in() ) { ... } ?> 

Function parameters:
This function does not accept any parameters.

Return Value:
(Boolean)
If you have logged on, True is returned. Otherwise, False is returned.

Function example:
The following instances show logged-in users or Unlogged-in users:

<?phpif ( is_user_logged_in() ) {  echo 'Welcome, registered user!';} else {  echo 'Welcome, visitor!';}?>

Source file:
Is_user_logged_in () is in the wp-uplodes/pluggable. php file.

Articles you may be interested in:
  • After logging on to WordPress, close the login page and set invisible topics for users.
  • Share a PHP script instance for email reminders during Guest Login in WordPress

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.