Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Keep Logged in Users out of Admin Panel

You can remove the read capability from subscribers, which is what gives them access to the dashboard. This is best done with an activation hook on a plugin — it only needs to be done once.

<?php
register_activation_hook( __FILE__, 'wpse43054_activation' );
function wpse43054_activation() 
{
    $role = get_role( 'subscriber' );
    if( $role ) $role->remove_cap( 'read' );
}

And, of course, you probably want to give that capability back on plugin deactivation.

<?php
register_deactivation_hook( __FILE__, 'wpse43054_deactivation' );
function wpse43054_deactivation() 
{
    $role = get_role( 'subscriber' );
    if( $role ) $role->add_cap( 'read' );
}

Finally, you can hook into init and redirect folks if they are logged in, try to access the admin area and don’t have the read capability.

<?php
add_action( 'init', 'wpse43054_maybe_redirect' );
function wpse43054_maybe_redirect() 
{
    if( is_admin() && ! current_user_can( 'read' ) )
    {
        wp_redirect( home_url(), 302 );
        exit();
    }
}

You’ll also probably want to remove the admin bar for users with a read capability. You can do that by hooking into get_user_metadata and hijacking the check for the user meta value for show_admin_bar_front.

<?php
add_filter( 'get_user_metadata', 'wpse43054_hijack_admin_bar', 10, 3 );
function wpse43054_hijack_admin_bar( $null, $user_id, $key )
{
    if( 'show_admin_bar_front' != $key ) return null;
    if( ! current_user_can( 'read' ) ) return 0;
    return null;
}

All that as a plugin.

Related Posts:

  1. How do I enable new account notification emails (to the administrator)?
  2. Want to know who is login Admin/User
  3. How to Change the Default Home Page for the WordPress Dashboard?
  4. Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
  5. Can an admin check passwords of registered users?
  6. WordPress auto login after registration not working
  7. How to obtain the user ID of the current profile being edited in WP-Admin?
  8. Custom admin email for new user registration
  9. Cannot access admin panel
  10. How to remove administrator role in settings -> general -> New User Default Role?
  11. turn off new user registration emails
  12. Hide update messages from non-admin users?
  13. Daily notices of failed login attempts for non-existent admin user
  14. How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
  15. Add extra field when admin create user
  16. Add a custom column in users list page
  17. How to create custom LOGIN and REGISTRATION forms?
  18. Customize Admin Users Screen based on Role
  19. Make certain pages uneditable by editors?
  20. Get user info outside WordPress
  21. wp-admin: Sort users by surname
  22. Add User meta fields, which only admin can edit
  23. How to display only logged in user’s post comments in comments area
  24. How to add multiple existing users to a multisite site?
  25. Add Admin User via SQL
  26. Can you have the users list pre sorted by specific column?
  27. Setting Login with User Name and Password default option for Jetpack Admin Login
  28. How to remove Gravatar from Username column
  29. I keep getting logged out in Firefox
  30. Create a Meta Box in the Admin User Screen?
  31. WordPress to use Drupal users’ credentials
  32. In administration, how do I display comments of a certain user?
  33. New users must comment when requesting username
  34. user-new.php less detailed after WP3.1; how to revert?
  35. Error thrown. Cannot create references to/from string offsets
  36. Protect custom php file with login
  37. $user_id vs. is_user_logged_in()
  38. Get current logged in user under 3.1, re: remove “Howdy”
  39. Add More Fields to Users Pages (Admin Panel)
  40. How to determine if an admin is logged in outside the loop
  41. Manage users custom column add class “num”
  42. Unable to login, old site with previous developer gone
  43. Hide one admin from another admin
  44. User management system similar to wordpress one?
  45. Using shared SSL for login/admin
  46. wp-login behind nginx reverse-proxy inaccessible — bad redirect?
  47. Four columns in the wp_users table
  48. Displaying different in-page content to cliente/admin
  49. Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
  50. Can’t access dashboard as administrator, login as any other level works though
  51. wordpress disable login for unverified user
  52. WordPress Admin Login Redirect Problem
  53. Unable to Access WP Admin or Login buttons after Migration
  54. using rewrites to secure login page
  55. How can I make the user names of commentors clickable links to the user’s profile from the admin comment screen?
  56. Client system for media review?
  57. WordPress administration Over SSL – To Force SSL Logins and SSL Admin Access
  58. Unable to get to the admin panel
  59. I can’t access the login panel on my offline website
  60. Shared account / dual blogging in WordPress
  61. Admin login not working
  62. I’m a super admin and I want to give an admin the ability to add new users…?
  63. Can’t login to my admin area
  64. Does deleting the table users prevent all logins?
  65. Locked out of WordPress website from wrong amount of login attempts
  66. current_user_can(‘administrator’) not working in custom login
  67. Redirect admin 403 “Cheatin uh?” admin pages
  68. Send admin to a different login than users?
  69. Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
  70. How should I setup the “Users” area to hand over to a client?
  71. How to show a custom notification to a specific user?
  72. Control Users listed in Users List on dashboard
  73. Remove iPhone detection on login page
  74. How should I change the username of or delete the admin user?
  75. Prevent Registration Where Role is None?
  76. Extending the user profile [closed]
  77. Any known plugins for master admin login to edit all on front end?
  78. define two login page url
  79. Allowing duplicating users with same user_login and user_email
  80. Login to admin by frontend form?
  81. Error “Sorry, you are not allowed to access this page”
  82. I can’t access login page
  83. Hide top admin panel for non admin and non editors
  84. When admin approves a registered user, I don’t want to send a notification email to users
  85. Is it possible to create a custom admin page for users?
  86. Admins loggin in to our wordpress site default to the admin page
  87. Custom redirection when managing users in admin
  88. Different role for free and pro users in wordpress without using bbpress
  89. WordPress login not working
  90. Login to Admin Dashboard Problem
  91. WordPress login process is hanging
  92. WordPress “Hide WP” Gives Me Error After Admin Login [closed]
  93. Scripts are not called until I login from wordpress backend
  94. Disable wp-admin log on lightbox overlay
  95. How to cancel redirection to admin side
  96. Integrating Facebook Registration (and Login) on a WordPress page
  97. Can’t access my wp admin: captcha images invisible, gives me error message
  98. You do not have permission to access this document on form submit
  99. Does wp_login hook fire on user registration?
  100. 2FA for admin login only, is it doable?
Categories admin Tags admin, login, user-registration, users
Deregister multiple scripts using a function?
Is there a way to visualize / print out which templates were used to render a given piece of UI?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress