Answer the question
In order to leave comments, you need to log in
How to hide access to the admin panel to everyone except editors and administrators?
Guys, I hid access to the admin panel to everyone except the administrator. When you try to go to wp-login and wp-admin, there is a redirect to the main site. How can I add editor rights to this code so that it can get there too?
<?php
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;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question