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 do I validate extra pin field on my WordPress login form page?

I’m assuming that where you said “I need help to validate/connect the new custom field to a data column in wp_users called serials” that you actually meant wp_usermeta field where the meta key is “serials”.

To validate any additional fields as part of the login, you use the wp_authenticate_user filter.

Start by checking to see if $user is a WP error, and if it is, there’s no point in continuing as the login failed anyway. If it’s not an error, move on to check if your custom field is empty as you’ll want to make sure it’s filled out. If the field is empty, return an error.

Lastly, if it’s a valid user and the value is given in the field, then retrieve the db value (as mentioned above, assuming this is a user meta key in wp_usermeta since there are not custom fields in wp_users). If comparing the values fails, return an error.

add_filter( 'wp_authenticate_user', 'my_validate_pin', 10, 2 );
function my_validate_pin( $user, $password ) {

    // Validate PIN if we're not already in an error.
    if ( ! is_wp_error( $user ) ) {
        $pin = get_user_meta( $user->ID, 'serials', true );

        // Error if field is empty.
        if ( ! isset( $_POST['my_extra_field_name'] ) ) {
            remove_action( 'authenticate', 'wp_authenticate_username_password', 20 );
            $user = new WP_Error( 'failed', __("<strong>ERROR</strong>: Must include PIN") );
        }

        // Assuming you're looking for form value to match the db value.
        if ( $pin != $_POST['my_extra_field_name'] ) {
            // If values don't match, return error
            remove_action( 'authenticate', 'wp_authenticate_username_password', 20 );
            $user = new WP_Error( 'failed', __("<strong>ERROR</strong>: Invalid PIN") );
        }

    }

    return $user;
}

Related Posts:

  1. Hiding the WordPress login and password fields from login page
  2. Can someone explain what wp_session_tokens are, and what are they used for?
  3. Init action hook running late after PayPal’s return url?
  4. Preferred way to include Advanced Custom Fields in a plugin?
  5. How to check WordPress website username and password is correct
  6. Log in from one wordpress website to another wordpress website
  7. Problems after wp_set_password() containing an apostrophe
  8. Two-step login process – Is it possible?
  9. How do I approach removing menu items on the fly based on settings in my plugin?
  10. Is there any way to check for user login and send him to login?
  11. Why is my javascript not invoked in my hooks except wp_head?
  12. Proper way to pass credentials in a custom login form to avoid “headers already sent”
  13. External Authentication, session_tokens not destroyed on logout
  14. Verify if user is wordpress logged in from another app since wordpress 4.0
  15. Where can i find wordpress auto update code flows?
  16. How to customize login process
  17. wp_insert_user() function password never match
  18. Does wp_login only trigger before an user signs in into the admin panel?
  19. Logout users upon login, based on caps/role?
  20. Elementor custom Query with ACF fields to show matching woocommerce products custom fields
  21. How to Bind one post object Type with other postobject Type in Advanced Custom field [closed]
  22. Is it possible to make sure that only my plugins output is shown to the enduser?
  23. Custom login doesn’t work properly
  24. Password field is empty when using wp_signon();
  25. Plugin Development for registered users
  26. Enqueue script globally
  27. WP Multisite login not working on one subsite. Possibly cookies/ history issue?
  28. Alternative functions for mysql_free_result and mysql_ping in wordpress functions
  29. Can we intercept user_login and user_pass from a wp_login_form?
  30. How to redirect home page to another page after login for all user?
  31. How to share user data across multiple WordPress websites?
  32. How to call function from another plugin?
  33. Is it possible for two WordPress plugins to share the same code base?
  34. Attaching Image-file to userId
  35. Allowing duplicating users with same user_login and user_email
  36. How to Login a User inside a Plugin and Redirect to page?
  37. Using custom IDP with WP
  38. ACF Field value in wordpress login message filter
  39. how to add security questions on wp-registration page and validate it
  40. using wordpress acf shortcods in tables goes outside the table
  41. Code for cron to delete posts that contain specific expression (e.g. “unable to fetch” every 30 minutes
  42. User avatar-ACF fields
  43. redirect_to how to make it simply work with get parameter or similar?
  44. How to create session for user which is not an admin user
  45. Redirect default login page to a custom page [duplicate]
  46. Multiple Users Logged In Causing Incorrect Account Returned
  47. Get user logged in status from within a plugin. $current_user not defined
  48. Need edit profile link in the menu for logged in users
  49. Create a Custom Login System in WordPress [closed]
  50. how can I insert a link on login page
  51. user can login from single account detail from multiple locations(computer) at the same time [closed]
  52. Advanced Custom Fields conflicting with custom plugin when saving custom field
  53. What’s wrong in the WordPress Meta Box Generator code?
  54. Developing an IP lookup function using an API
  55. Load images from CDN and custom features to “Add Media” dialogue
  56. how to works woocommerce cart hash
  57. WordPress – Custom permalinks for advanced custom fields (ACF) using post type taxonomy
  58. Objective Best Practices for Plugin Development? [closed]
  59. add_menu_page() with different name for first submenu item
  60. Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
  61. How to include PHP files in plugins the correct way
  62. How can I add an image upload field directly to a custom write panel?
  63. A tool to analyze rewrite rules? [closed]
  64. Difference Between Filter and Action Hooks?
  65. framework for plugin/theme options panel? [closed]
  66. Creating a table in the admin-style?
  67. How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
  68. Settings API with arrays example
  69. How to get the path to the current theme?
  70. How to make a plugin require another plugin?
  71. ajaxurl not defined on front end
  72. What process do you use for WordPress development? [closed]
  73. What’s the difference between term_id and term_taxonomy_id
  74. Should I use wpdb prepare?
  75. Why does WordPress use outdated jQuery v1.12.4?
  76. Post meta vs separate database tables
  77. Is there any plugin development framework
  78. Is it possible to reuse wp.media.editor Modal for dialogs other than media
  79. How to add a javascript snippet to the footer that requires jQuery
  80. Enhance Media Manager for Gallery
  81. How do I create a custom role capability?
  82. How do I add CSS options to my plugin without using inline styles?
  83. How do i best handle custom plugin page actions?
  84. Adding Custom Text Patterns in the WP 4.5 Visual Editor
  85. Automatically determine minimum WordPress version required for a plugin?
  86. How can I redirect user after entering wrong password?
  87. What is the advantage of using wp_mail?
  88. How to make a WordPress plugin translation ready?
  89. How many times will this code run? (or, how rich is grandma?)
  90. How to create an API for my plugin?
  91. Is it ever okay to include inline CSS in plugins?
  92. Plugins in symlinked directories?
  93. How to override existing plugin action with new action
  94. How to include a file using get_template_part() in a plugin?
  95. Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
  96. How to store username and password to API in wordpress option DB?
  97. body_class hook for admin pages
  98. “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
  99. Is it mandatory to use $wpdb->prefix in custom tables
  100. Which hook should be used to add an action containing a redirect?
Categories plugin-development Tags advanced-custom-fields, code, login, plugin-development, wp-login-form
Duplicate shipping method logic to another shipping method [closed]
not sending correct link to set the password in registration email [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

  • 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