Ajax login fails after upgrade to 4.2.3
-
Hi.
I just updated WP and my custom login form stopped working. It works good in 4.2.2, but not in 4.2.3.In functions.php i have:
function add_scripts() { wp_localize_script ('cool-main-script', 'ajax_login_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'redirecturl' => $_SERVER['REQUEST_URI'], 'loadingmessage' => __('Checking...') )); } add_action ('wp_enqueue_scripts', 'add_scripts' ); function ajax_login_init(){ add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' ); } if (!is_user_logged_in()) { add_action('init', 'ajax_login_init'); } function ajax_login(){ check_ajax_referer( 'ajax-login-nonce', 'security' ); $info = array(); $info['user_login'] = $_POST['username']; $info['user_password'] = $_POST['password']; $info['remember'] = true; $user_signon = wp_signon( $info, false ); if ( is_wp_error($user_signon) ){ echo json_encode(array('loggedin'=>false, 'message'=>__('Wrong'))); } else { echo json_encode(array('loggedin'=>true, 'message'=>__('Redirecting'))); } die(); }
In .js file i have
jQuery(document).ready(function($){ //Ajax login $('.login_box #login').on('submit', function(e){ $('.login_box .status_login').show().html(ajax_login_object.loadingmessage); $.ajax({ type: 'POST', dataType: 'json', url: ajax_login_object.ajaxurl, data: { 'action': 'ajaxlogin', //calls wp_ajax_nopriv_ajaxlogin 'username': $('.login_box #username').val(), 'password': $('.login_box #password').val(), 'security': $('.login_box #security').val() }, success: function(data){ $('.login_box .status_login').html(data.message); if (data.loggedin == true){ document.location.href = ajax_login_object.redirecturl; } } }); e.preventDefault(); }); });
The process stops at ‘Checking…’
As I can see wp-admin/includes/ajax-actions.php was revised. May be that’s the problem.
How to change the code to meet the new core?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Ajax login fails after upgrade to 4.2.3’ is closed to new replies.