Keep the Subscribes Off the Backend

Another quick function to help with member / subscribers sites that will keep them from even getting to the wordpress admin dashboard after logging in. I’ve modified this from the original version to check if the user used the /wp-admin/ in the url, so that you will still be able to redirect to the login page rather than the home page.

add_action( 'init', 'blockusers_init' );
function blockusers_init() {
  if ( is_login_page() && !is_user_logged_in() ) { NULL; } // allow users to see the wordpress login page
  else {
  if ( is_admin() && !current_user_can( 'administrator' ) && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    wp_redirect( home_url() );
    exit();
  }
 }
}

function is_login_page() {
  if ( $_SERVER['PHP_SELF'] == '/wp-admin/index.php' ) { return true; }
  return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
}

reference: http://premium.wpmudev.org/blog/limit-access-to-your-wordpress-dashboard/

This post also references the plugins Login RedirectWP Hide DashboardRemove Dashboard Access.

Scroll to Top