Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I do not want the users (role: subscriber) to be able to login via the wp-admin.

How would you suggest I do this ?

share|improve this question
add comment

1 Answer

You can remove the Read capability. That will prevent all access to wp-admin.

function remove_read_wpse_93843(){   
  remove_cap( 'subscriber', 'read' );
}
add_action( 'admin_init', 'remove_read_wpse_93843' );

See the note in the Codex about only needing to run this once.

Then you need to hide the admin bar.

function hide_admin_wpse_93843() {
  if (current_user_can('subscriber')) {
    add_filter('show_admin_bar','__return_false');
  }
}
add_action('wp_head','hide_admin_wpse_93843');

And probably want to redirect subscriber logins:

function redirect_sub_to_home_wpse_93843( $redirect_to, $request, $user ) {
    if ( isset($user->roles) && is_array( $user->roles ) ) {
      if ( in_array( 'subscriber', $user->roles ) ) {
          return home_url( );
      }   
    }
    return $redirect_to;
}
add_filter( 'login_redirect', 'redirect_sub_to_home_wpse_93843', 10, 3 );

Other attempts to access wp-admin will result in the "You do not have sufficient permissions..." almost-white screen.

That is somewhat bare-bones but I think it gets you there.

share|improve this answer
    
Thanks, just what I was looking for. Shall give it a shot now. –  Prakash Raman Mar 29 '13 at 21:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.