• nilssonline

    (@nilssonline)


    Hello, I’ve been useíng this code to block everyone that’s not an admin user from the admin area.

    add_action( 'init', 'blockusers_init' );
    function blockusers_init() {
        if ( is_admin() && ! current_user_can( 'administrator' )  && 
           ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
            wp_redirect( home_url() );
            exit;
        }
    }

    But with WP version 6.1.1 The code is no longer works. It redirects the users too many times so the site break. Can anyone help me with this?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Still works on my site (6.1.1, 2021 theme). Perhaps you have other redirect code that’s causing the infinite loop in combination with your code? Try switching to 2021 theme and deactivating all plugins. Temporarily add your code to the theme’s functions.php. Also ensure your .htaccess is only doing the default rewrites.

    Your code should then work. Restore your normal theme and plugins, one at a time (moving your code to the current theme). When the problem recurs, the last activated module is the cause.

Viewing 1 replies (of 1 total)
  • The topic ‘Blocking users from admin is no longer working’ is closed to new replies.