How to block backend access to subscriber
How can I block WordPress backend access to subscriber, and redirect them to home page?
Insert this code on your plugin:
<?php
/*
* Block backend access to subscriber, and redirect them to home
*
*/
add_action( 'init', 'wpster_blockusers_init' );
function wpster_blockusers_init() {
if ( is_admin() && current_user_can( 'subscriber' ) &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect('/');
exit;
}
}
?>