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

How to authenticate/verify login credentials & check for user meta without logging in?

You could do this with a low-priority authenticate filter. I’m surprised there aren’t more appropriate hooks in the login process, but I can’t see one. (There is already an example of a filter like this though: wp_authenticate_spam_check.)

If the value the filter is given is a user, that means a previous filter has accepted the username & password. We can then perform our check and then either return the user if good or an error if not:

function authenticate_reject_account_status_pending( $user, $username, $password ) {
    if ( $user instanceof WP_User ) {
        if ( $user[ 'account_status' ] === 'pending' ) {
            return new WP_Error( 'user_is_pending',
                __( 'Account is pending approval. Please contact support for help.' )
            );
        }
    }

    return $user;
}
add_filter( 'authenticate', 'authenticate_reject_account_status_pending', 999999, 3 );

I have not tested this, but the general pattern should work even if this code doesn’t. This runs before the cookie is created etc.

Related Posts:

  1. WordPress auto login after registration not working
  2. My custom page template with is_user_logged_in() does not detect that I’m logged in
  3. Is possible to allow user to login with different role?
  4. WordPress Login Customization for External Authentication
  5. How do you manage your pages or functions that require logged-in users?
  6. How to allow access based on the user meta flag
  7. How to change default username field after login
  8. The same session information for peer users on two different WordPress servers
  9. Check for empty username or password on login
  10. Securely log in a user without a password using a link?
  11. WordPress – Security Question at Login from User’s Meta Data
  12. How to track all users logged into a site?
  13. Replacing the WordPress password validation
  14. Disable WordPress 3.6 idle logout / login modal window / session expiration
  15. Allow up to 5 Concurrent Login Sessions
  16. Multi-steps WordPress registration : in 4 steps how to?
  17. Why does is_user_logged_in() return false after redirect from another site?
  18. Pre-populate Username Field
  19. How to keep track of user logins?
  20. Get user info outside WordPress
  21. Authenticate user using Hashed Password in MySQL Query and C#
  22. How can I secure a WordPress blog using OpenID from a single provider?
  23. Is it possible to get a user with just the password field?
  24. Redirect after login based on user role (custom login page)
  25. Check for user meta data at Login
  26. Redirect User to Homepage if no other redirect is specified
  27. Use phpbb user database for WordPress
  28. WordPress to use Drupal users’ credentials
  29. Authenticate with a Rails app?
  30. Share user table from WP with Drupal
  31. How can I allow password reset based on logins containing the @ character?
  32. A way to count logged in users and display count?
  33. stop login if user_status equal zero
  34. WordPress Authentication Middleware
  35. wp_login_form() passing user ID into URL on redirect?
  36. How do i make my wordpress website private?
  37. Redirect user to login before viewing custom post
  38. Change the user_login at registration
  39. Max no of simultaneous active sessions for a single user
  40. Rest API code to get ID of current user not working: get_current_user_id() gives 0
  41. When I try to login in wordpress it is showing “USER Doesn’t Exists”
  42. Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
  43. Redirect subscribers to last viewed page after log-in
  44. wordpress disable login for unverified user
  45. Reset Password policy
  46. Rewrite Rules and Login Issue
  47. How can I authenticate user credentials against a WordPress instance?
  48. OAuth 2 and saving the authenticated user
  49. Use WordPress Login for a non-wordpress site
  50. WP not logging in at first time
  51. Allow users to create post without logging in?
  52. Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
  53. New user form rejected because “passwords don’t match”—but there’s only one password field
  54. Is there any action /filter hook I can use to disable login for some user role?
  55. How to check User Role and redirect to specific page according to Role when login in WordPress?
  56. REST API: wp_get_current_user not working on second call
  57. Display video on homepage for users who have not logged in
  58. Possibility to login without password
  59. How can i login with user’s password in WordPress being an admin?
  60. Delete a user from frontend
  61. Where is the php file, that does the checks for login information?
  62. Check if user is logged in via JS? [duplicate]
  63. Use members from 1 site on another one
  64. Can I edit the database to change a login?
  65. how redirect users to custom login page when “login to reply” is clicked? [duplicate]
  66. User(s) already exists show error please provide a valid username
  67. Show errormessages on wrong username/password on custom loginform?
  68. wp_generate_password sets password but can’t login using created password
  69. add class to element if user is not logged in [closed]
  70. How to verify which WordPress user requested the API in ASP .NET Core?
  71. Need to use WordPress page as authentication for different service
  72. Is there a way to call via javascript if a user is logged-in on a static html file?
  73. Restricting wordpress login sessions for a web app
  74. Authentication between two different sites using the WordPress login cookie
  75. Use WP cookie to authentificate user on an external app
  76. How to connect wordpress user with my own APP user?
  77. Custom user roles are unable to login
  78. Disable emails for new user registration
  79. WP users cant reset password
  80. $user_login is not working if author has only 1 post
  81. Specific Content on pages based on user
  82. user and usermeta table not found
  83. throttle/limit a logged in user’s http requests to specific page on a per day basis
  84. custom login form, guide me
  85. Changing user_login ends current session
  86. Current User Seeing Another Logged In User Info
  87. Redirect based on log-in status per JavaScript
  88. Integrating Facebook Registration (and Login) on a WordPress page
  89. determine active user browser at the same time
  90. Cant edit profile from frontend
  91. Allow Html pages for users with specific roles
  92. New users not showing up in Post -> Edit
  93. How can i change the name order in the admin?
  94. Filters on Login Page
  95. How to let the users edit their user names?
  96. Secondary Menu and Logged In Users
  97. is_user_logged_in function in a sidebar not working
  98. WP_User object behaving strangely when used inside Admin Panel?
  99. Redirect default login page to a custom page [duplicate]
  100. Validate user meta and redirect
Categories users Tags authentication, login, users, wp-login-form
WordPress 6.1.1 does not upload the .WEBP images but with old browser upload does it correct
save all acf options in one meta_value [closed]

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

  • Disable image compression for WebP
  • At what stage does wp_ajax hooks gets applied during WordPress request?
  • How to create specific wordpress Table
  • How to get variable from other function inside class function using add_action for Ajax call
  • Some images not loading after changing IP on local wordpress install
  • search posts by POST ID
  • Elementor Contact Form Submit button has empty class
  • Duplicate Slugs on multilingual site (with Polylang)
  • Timeline from diferent wordpress api urls endpoint works, but diferent date
  • $attributes not defined in block.json PHP template for ACF blocks
© 2023 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