Could you please correct the code is_admin()

I have this code in my function.php:

add_action( 'init', 'blockusers_init' );
function blockusers_init() { 
    if ( is_admin()  ! current_user_can( 'administrator' )  ! ( defined( 'DOING_AJAX' )  DOING_AJAX ) ) {
        wp_redirect( 'http://madeeasy-online.com/zhile-2/dobavit-obyavlenie/', 302);
        exit;
    }
}

But I want 'moderator' to reach the admin-panel. What should I add to the code?

Thank in advance, Sv

Topic allowedtags functions Wordpress

Category Web


What is a moderator? A custom user role? If yes, then:

add_action( 'init', 'blockusers_init' );
function blockusers_init() { 
    if ( is_admin() && (!current_user_can( 'administrator' ) || !current_user_can( 'moderator' ) ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
        wp_redirect( 'http://madeeasy-online.com/zhile-2/dobavit-obyavlenie/', 302);
        exit;
    }
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.