I have an front-end ajax login on my site. I want to set the redirect url to '/services/clientarea';
for every page that is not part of the blog. For blog pages i want the login redirect to be $_SERVER['REQUEST_URI'];
Here is the code that I'm using which isn't working for me:
function ajax_login_init(){
wp_register_script('ajax-login-script', get_template_directory_uri() . '/library/js/ajax-login-script.js', array('jquery') );
wp_enqueue_script('ajax-login-script');
global $post;
$posttype = get_post_type($post);
if ($posttype == 'post') {
$loginredirect = $_SERVER['REQUEST_URI'];
} else {
$loginredirect = '/services/clientarea';
}
wp_localize_script( 'ajax-login-script', 'ajax_login_object', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'redirecturl' => $loginredirect,
'loadingmessage' => __('Signing in, please wait...')
));
// Enable the user with no privileges to run ajax_login() in AJAX
add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );
}
// Execute the action only if the user isn't logged in
if (!is_user_logged_in()) {
add_action('init', 'ajax_login_init');
}
It seems that the post type isn't loaded in the init hook. Is there any way to identify it?