Skip to:

Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)

  • scorpnetwork


    Awesome, that makes it even better! Thank you.



    Ok, solved it on my own.

    Like almost everybody else on this forum and on other blogs I found, most people are using the same function to block specific users to access WP admin and redirect them to the frontpage f.e..

    As stated above, the problem lies within the redirect. As far as I understood its because the admin_init hook is getting fired when admin-ajax.php gets loaded, which of course happens when you try to upload an avatar, which happens via AJAX by default.

    So the solution is pretty simple – just check if the current request is trying to get admin-ajax.php and if not, do your redirect.

    Maybe this post will help somebody with the same problem. If somebody has a smoother approach to this, ill be glad to know. 🙂

    /// Block admin access
    function psinside_no_admin_access(){
        $redirect = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : home_url( '/' );
        global $current_user;
        $user_roles = $current_user->roles;
        $user_role = array_shift($user_roles);
    		($user_role != 'administrator' && $user_role != 'editor')
    		($_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php')
            exit( wp_redirect( $redirect ) );
    add_action( 'admin_init', 'psinside_no_admin_access', 100 );



    I now found this thread which seems to be the source of my problem.

    Trying it out now. Sadly its closed and even sadder, there is no “solution”.

    If this thread is correct, then the problem occurs because of a redirect that forbids “regular users” to enter WP Admin.

    Does anybody have a solution for this?

Viewing 3 replies - 1 through 3 (of 3 total)
Skip to toolbar