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

Lock out all WordPress Administrators except two specific users

|| means OR.
Your code will never allow $current_user to proceed because one of the OR conditions will fail.
Try using AND && instead:

if ( ($current_user->user_login != 'john') && ($current_user->user_login != 'sheila' ) ) {

Related Posts:

  1. Private page protected with username and password
  2. Separate registration and login for different roles
  3. How reduce wordpress login session timeout time?
  4. Disallow user from editing their own profile information
  5. add the user name to menu when user is logged in [closed]
  6. How long do users stay logged in if they DON’T check remember me?
  7. how to logout user on browser tab or window closes
  8. Custom Connect to Facebook, problem logging in/logging out
  9. Preexisting login to change to logout link in sub menu
  10. Restricting frontend acess based on user role otherwise redirect to login form
  11. Deny a user role to log in after register
  12. How to integrate external user tables with WP?
  13. Allow Users Only Edit Their Profile?
  14. Logout users upon login, based on caps/role?
  15. Session Experies and Get Logged Out Within Few Minutes
  16. WordPress error on log out ‘Not Permitted’ and can’t log out
  17. Set Default User Role
  18. Add logout link when logged in, make it disappear when logged out?
  19. Generate email on meta value update
  20. How to remove ‘wordpress…’ text from page titles in tabs
  21. Invalidate username if it contains @ symbol
  22. WordPress Login redirection according to user role
  23. Display first name instead of username
  24. Prevent Subscriber Role to login
  25. WordPress not logged in locally with correct username and password
  26. Can I protect a type of content site-wide with a single password?
  27. Login Based on ip
  28. URL Restrictions? Need only people who are logged in AND have a specific role (or roles) to access all pages for a site
  29. Make WordPress User Name be the Company Name when Registering (not the default ‘first name’ last name’ email address’)
  30. Custom failed login error messages for users based on user role?
  31. Problem with is_user_logged_in() function in some pages
  32. Custom user roles are unable to login
  33. Why deleting/removing cookies in WordPress does not log me out from admin?
  34. User login without username, only password
  35. wp_logout logging everyone out instead of just the user that clicked the logout link!
  36. Cannot login with correct username and password anymore
  37. Username character requirements
  38. Inconsistent login state
  39. Can i hide a dynamically created div to logged out users?
  40. In Django, how do I know the currently logged-in user?
  41. Can I programmatically login a user without a password?
  42. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  43. Is there any way to rename or hide wp-login.php?
  44. How to login with email only no username?
  45. How can I redirect user after entering wrong password?
  46. Increase of failed login attempts, brute force attacks? [closed]
  47. Login page ERROR: Cookies are blocked due to unexpected output
  48. SSO / authentication integration with external ‘directory service’
  49. Preventing session timeout
  50. How to prefill WordPress registration with social details
  51. Check for correct username on custom login form
  52. I can’t access my site via wp-admin
  53. ‘Password field is empty’ error when using autofill in Chrome
  54. Removing username from the ‘wordpress_logged_in’ cookie
  55. How to show ‘login error’ and ‘lost password’ on my template page?
  56. What is $interim_login?
  57. Custom login form
  58. How to prefill the username/password fields on the login page
  59. wp_signon returns user, but the user is not logged in
  60. Adding extra authentication field in login page
  61. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  62. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  63. wp_signon() does not authenticate user guidance needed
  64. What exactly is ReAuth?
  65. What are the differences between wp_users and wp_usermeta tables?
  66. Login members using web services
  67. Make my wordpress blog remember my login “forever”
  68. How to check in timber if user is loggedin?
  69. How do I change the language of only the login page?
  70. Disable WordPress 3.6 idle logout / login modal window / session expiration
  71. How to change the default logout link on WordPress Admin
  72. Stop WordPress from logging me out (need to keep me logged in)
  73. Woocommerce registration page [closed]
  74. How to disable autocomplete on the wp-login.php page
  75. Share login data/cookies between multiple installations
  76. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  77. How to pass users back and forth using session data?
  78. How do I change the logo on the login page?
  79. Why does WordPress hide the reset password key from the URL?
  80. Is it possible to sign in with user_email in WordPress?
  81. How to use current_user_can()?
  82. Avoid to load default WP styles in login screen
  83. WordPress registration message
  84. How to fake a WordPress login?
  85. how to display the wordpress login and register forms on a page?
  86. Does wp_logout_url() destroy a session? (Logging out question)
  87. How can I send a welcome email to a user AFTER they login for the first time?
  88. Can not login with correct username and password
  89. Website Visible only to Registered users
  90. How can i increase the login expiration length?
  91. How do I use add_action from a class method?
  92. How to remove the WordPress logo from login and register page?
  93. How can I add a custom script to footer of login page?
  94. Brute force attack?
  95. Customize wp_new_user_notification_email()
  96. Need to execute a cron job
  97. Masking logout URL
  98. Login email after registration never sent or received
  99. How can I create a separate blog that is private?
  100. How to keep always logged in development environment
Categories login Tags login, logout, user-roles, username
Search WordPress using static html page
How to get featured image in WP rest api

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