Created
April 12, 2012 21:12
-
-
Save menslow/2371021 to your computer and use it in GitHub Desktop.
WordPress: Simple sign in function for custom front-end sign in forms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* mm_sign_in function. | |
* Sign the user in | |
* @access public | |
* @return User errors or true if successful signon | |
*/ | |
function mm_sign_in() { | |
if(!is_user_logged_in()) { | |
if(!empty($_POST)) { | |
// verify nonce | |
$nonce = $_POST['signin_nonce']; | |
if ( ! wp_verify_nonce( $nonce, 'signin_nonce' ) ) | |
{ | |
die(); | |
} | |
$credentials = array(); | |
$credentials['user_login'] = stripslashes($_POST['signin_username']); | |
$credentials['user_password'] = stripslashes($_POST['signin_password']); | |
if ( isset($_POST['signin_remember']) ) { | |
$credentials['remember'] = (bool)stripslashes($_POST['signin_remember']); | |
} | |
// sign the user in | |
$user = wp_signon($credentials, false); | |
// prepare response | |
if ( is_wp_error($user) ) { | |
return $user->errors; | |
} else { | |
wp_redirect( home_url() ); | |
exit(); | |
} | |
} | |
return false; | |
} else { | |
// user is logged in already | |
wp_redirect( home_url() ); | |
exit(); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment