Есть вот такая функция
function ajax_register(){
check_ajax_referer( 'ajax-register-nonce', 'security' );
$info = array();
$info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['username']) ;
$info['user_pass'] = wp_generate_password( 12, false );
$info['user_email'] = sanitize_email( $_POST['email']);
// Register the user
$user_register = wp_insert_user( $info );
if ( is_wp_error($user_register) ){
$error = $user_register->get_error_codes() ;
if(in_array('empty_user_login', $error))
echo json_encode(array('loggedin'=>false, 'message'=>__($user_register->get_error_message('empty_user_login'))));
elseif(in_array('existing_user_login',$error))
echo json_encode(array('loggedin'=>false, 'message'=>__('This username is already registered.')));
elseif(in_array('existing_user_email',$error))
echo json_encode(array('loggedin'=>false, 'message'=>__('This email address is already registered.')));
} else {
wp_new_user_notification( $user_register, $info['user_pass'] );
echo json_encode(array('loggedin'=>true, 'message'=>__('Check your email. redirecting...')));
}
die();
}
Здесь все работает. на страницу возвращаются данные :
echo json_encode(array('loggedin'=>false, 'message'=>__('This username is already registered.')));
и т.п
А вот вторая функция и она не возвращает данные
function ajax_recover(){
check_ajax_referer( 'ajax-register-nonce', 'security' );
global $wpdb, $wp_hasher;
if ( empty( $_POST['username'] ) ) {
echo json_encode(array('loggedin'=>false, 'message'=>__('<strong>ERROR</strong>: Enter a username or e-mail address.')));
} else if ( strpos( $_POST['username'], '@' ) ) {
$user_data = get_user_by( 'email', trim( $_POST['username'] ) );
if ( empty( $user_data ) )
echo json_encode(array('loggedin'=>false, 'message'=>__('<strong>ERROR</strong>: There is no user registered with that email address.')));
} else {
$login = trim($_POST['username']);
$user_data = get_user_by('login', $login);
}
do_action( 'lostpassword_post' );
if ( !$user_data ) {
echo json_encode(array('loggedin'=>false, 'message'=>__('<strong>ERROR</strong>: Invalid username or e-mail.')));
}
$user_login = $user_data->user_login;
$user_email = $user_data->user_email;
do_action( 'retreive_password', $user_login );
do_action( 'retrieve_password', $user_login );
$allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
if ( ! $allow )
echo json_encode(array('loggedin'=>false, 'message'=>__('Password reset is not allowed for this user')));
else if ( is_wp_error($allow) )
return $allow;
$key = wp_generate_password( 20, false );
do_action( 'retrieve_password_key', $user_login, $key );
if ( empty( $wp_hasher ) ) {
require_once ABSPATH . WPINC . '/class-phpass.php';
$wp_hasher = new PasswordHash( 8, true );
}
$hashed = $wp_hasher->HashPassword( $key );
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user_login ) );
$message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
$message .= network_home_url( '/' ) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
$message .= '<' . network_site_url("login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
if ( is_multisite() )
$blogname = $GLOBALS['current_site']->site_name;
else
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$title = sprintf( __('[%s] Password Reset'), $blogname );
$title = apply_filters( 'retrieve_password_title', $title );
$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
echo json_encode(array('loggedin'=>false, 'message'=>__('Possible reason: your host may have disabled the mail() function.')));
die();
}
А вот js который это все передает и принмает.
$('form#login, form#register').on('submit', function (e) {
if (!$(this).valid()) return false;
$('p.status', this).show().text(ajax_auth_object.loadingmessage);
action = 'ajaxlogin';
username = $('form#login #username').val();
password = $('form#login #password').val();
email = '';
security = $('form#login #security').val();
if ($(this).attr('id') == 'registerz') {
action = 'ajaxregister';
username = $('#signonname').val();
email = $('#email').val();
security = $('#signonsecurity').val();
}
if ($(this).attr('id') == 'recover') {
action = 'ajaxrecover';
username = $('#signonname').val();
security = $('#signonsecurity').val();
}
ctrl = $(this);
$.ajax({
type: 'POST',
dataType: 'json',
url: ajax_auth_object.ajaxurl,
data: {
'action': action,
'username': username,
'password': password,
'email': email,
'security': security
},
success: function (data) {
$('p.status', ctrl).text(data.message);
if (data.loggedin == true) {
document.location.href = ajax_auth_object.redirecturl;
}
}
});
e.preventDefault();
});
Кто подскажет, в чем проблема?=)