Your problem probably starts with your callback:
public function handleAjax( $action )
To send a JSON error or success, you just have to call
wp_send_json_success( array( /* Data */ ) );
wp_send_json_error( array( /* Data */ ) );
The response will be like:
{
success : true,
data : [
// Some data as key/value pairs
]
}
Both functions internally call wp_send_json()
. This sets the appropriate header
:
@header( 'Content-Type: application/json; charset=" . get_option( "blog_charset' ) );
and does the encoding to JSON for you:
echo json_encode( $response );
Your callback on the set Cookie filter won’t work as it will never be called. Better go one level up and use wp_set_auth_cookie()
. Your user registration should already allow that as one of the later registration hooks already have the user ID present: user_register
or wpmu_new_user
should both work for that case.
add_action( 'user_register', wpse136539userRegistration' );
function wpse136539userRegistration( $id )
{
$user = get_user_by( 'id', $id );
# @TODO Custom Error handling needed here
if ( is_wp_error( $user ) )
return;
wp_set_current_user( $id );
// Log the user in - set Cookie and let the browser remember it
wp_set_auth_cookie( $id, TRUE );
// Redirect user to his admin profile page ... @TODO maybe somewhere else
exit( wp_safe_redirect( user_admin_url() ) );
}