Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Slavek

    (@jackoneill)

    I found the issue. I use the following code to deny access to wp admin dashboard to subscribers, and because of that, admin-ajax.php is returning 302. So how to deny acces to wp-admin for subscribers and allow them adding reviews?

    function redirect_subscriber_to_frontend() {
    $current_user = wp_get_current_user();

    if (count($current_user->roles) == 1 && $current_user->roles[0] == 'subscriber') {
    wp_redirect(site_url('/dashboard/'));
    exit;
    }
    }

    add_action('admin_init', 'redirect_subscriber_to_frontend');

    Hello @jackoneill,

    Thank you for reaching out and providing detailed information about the issue you’re experiencing.

    The problem arises because your current code redirects all subscribers away from any admin-related pages, including the admin-ajax.php file, which is necessary for certain frontend operations like adding reviews.

    To resolve this, please remove the old code and add the following code to your theme’s functions.php file:

    function redirect_subscribers_to_dashboard() {
    // Check if the current user is logged in
    if (is_user_logged_in()) {
    $user = wp_get_current_user();

    // Check if the current user has the 'subscriber' role
    if (in_array('subscriber', (array) $user->roles)) {
    // Get the current admin URL
    $current_url = $_SERVER['REQUEST_URI'];

    // Check if the current URL is an admin page and not an AJAX request
    if (strpos($current_url, '/wp-admin') !== false && strpos($current_url, 'admin-ajax.php') === false) {
    // Redirect to the Tutor LMS dashboard
    wp_redirect(home_url('/dashboard/'));
    exit;
    }
    }
    }
    }
    add_action('admin_init', 'redirect_subscribers_to_dashboard');

    After adding this code, subscribers will be able to add reviews without being redirected.

    If you continue to experience issues or have any other questions, please feel free to let us know. We are here to help!

    Best regards,

    Mohammad Nafiz

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error when adding reviews’ is closed to new replies.