Languages: English • Italiano • 日本語 (Add your language)
Authenticates a user with option to remember credentials. Replaces deprecated function wp_login.
<?php wp_signon( $credentials, $secure_cookie ) ?>
NOTE: If you don't provide $credentials, wp_signon uses the $_POST variable (the keys being "log", "pwd" and "rememberme").
This function and action can be placed in functions.php of the theme. Using the hook init will make it run before the headers and cookies are sent, so it can set the needed cookie for login.
function custom_login() { $creds = array(); $creds['user_login'] = 'example'; $creds['user_password'] = 'plaintextpw'; $creds['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) echo $user->get_error_message(); } // run it before the headers and cookies are sent add_action( 'init', 'custom_login' );
Since: 2.5.0
wp_signon() is located in wp-includes/user.php
.