Front-end ajax problem all users and guests getting a 302 redirect when accessing wp-admin/admin-ajax.php
Question
I want to wp ajax for all users frontend but showing error of 302 Found and calling home page except admins.
I looked this thread and added the code below to the functions.php of my theme.
function custom_blockusers_init() {
if ( is_admin() && !defined('DOING_AJAX') && (
current_user_can('usercrp') || current_user_can('userpcp') ||
current_user_can('subscriber') || current_user_can('contributor') ||
current_user_can('editor'))) {
session_destroy();
wp_logout();
wp_redirect( home_url() );
exit;
}
}
add_action( 'init', 'custom_blockusers_init' );
Now it only works for admin and editors but still not working for subscribers and visitors.
How can i fix this? Thank you from now.
0
1 year
2022-10-02T11:04:54-05:00
2022-10-02T11:04:54-05:00 0 Answers
0 views
0
Leave an answer