L
L
labyrinths2015-12-26 16:54:12
WordPress
labyrinths, 2015-12-26 16:54:12

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

1 answer(s)
M
Max Arkov, 2016-06-15
@uvdp

Like this:

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question