Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created March 4, 2012 03:47
Show Gist options
  • Save zanematthew/1970587 to your computer and use it in GitHub Desktop.
Save zanematthew/1970587 to your computer and use it in GitHub Desktop.
WordPress Ajax Login -- Form Processor
<?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