Created
March 4, 2012 03:47
-
-
Save zanematthew/1970587 to your computer and use it in GitHub Desktop.
WordPress Ajax Login -- Form Processor
This file contains hidden or 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
<?php | |
/** | |
* To be used in AJAX submission, gets the $_POST data and logs the user in. | |
* | |
* @uses check_ajax_referer() | |
* @uses wp_signon() | |
* @uses is_wp_error() | |
* | |
* @todo move this to the abtract! | |
*/ | |
function zm_register_login_submit() { | |
check_ajax_referer( 'tt-ajax-forms', 'security' ); | |
$creds = array(); | |
$creds['user_login'] = $_POST['user_name']; | |
$creds['user_password'] = $_POST['password']; | |
if ( isset( $_POST['remember'] ) ) { | |
$creds['remember'] = true; | |
} | |
$user = wp_signon( $creds, false ); | |
if ( is_wp_error( $user ) ) { | |
$user->get_error_message(); | |
} | |
die(); | |
} // zm_register_login_submit | |
add_action( 'wp_ajax_zm_register_login_submit', 'zm_register_login_submit' ); | |
add_action( 'wp_ajax_nopriv_zm_register_login_submit', 'zm_register_login_submit' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment