WordPress custom user login function wp_signon ()

wp_signon()Function returns the authentication username and password authorized user logs in, the simple point to understand is that after a user submits a user name and password after wp_signon()verification, validation successful return WP_User information, validation failure information WP_Error is returned. This function is commonly used in the development of WordPress login form reception function, after WordPress 2.5 is an alternative version wp_login()of a WordPress function.

Function Structure

1
<?php wp_signon($credentials, $secure_cookie);?>
Parameter Description:

$ credentials - (array) (optional), submit login information, such as user name, password, default is an empty array array().

$ Secure_cookie - (string or Boolean) (optional), whether to use secure Cookie, the default value is empty.

Tip: If $credentialsempty, the default use $_POST['log'], $_POST['pwd'], $_POST['remember']the value passed over, equal to null.

return value:

Successful return WP_User, failed to return WP_Error

Examples

1
2
3
4
5
6
7
8
9
10
11
12
$ creds = Array (); 
$ creds [ 'USER_LOGIN'] = 'blog it'; 
$ creds [ 'user_password'] = '1234567890'; 
$ creds [ 'Remember'] = to true; 
$ User = wp_signon ($ creds, false); // login, and the information back to the variable value attached User $ 
IF (is_wp_error ($ User)) {	 
	wp_die ( 'Login failed'); 
	Exit ();    
} the else { 
	wp_safe_redirect ( 'HTTP: // WWW .boke8.net / '); // successful login, jump to the designated page 
	Exit (); 
}

Function of the position

File: wp-includes / user.php

Guess you like

Origin www.cnblogs.com/wnh678/p/11872872.html