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 customize login process

You can use this function in functions.php of your current theme
It will show an extra field on login form

###################Code starts here ###################
<?php

add_action('login_form', 'add_login_field');
function add_login_field()
{
?>    
  <p>
      <label for="user_pass">My Input<br>
      <input type="text" name="my_name" value=""/>
  </p>
<?php  
}

function do_anything($user) {
    //do stuff

   $userdata= $user = get_userdatabylogin($user);
   $user_id = $userdata->ID;

   $my_name = $_POST['my_name'];



   add_user_meta( $user_id, 'my_name', $my_name);

}

add_action('wp_login', 'do_anything');
?>
############## CODE ENDS HERE ###################

The above code will create an extra field on the login form .
This value will be posted with other values that can be received in “do_anything($user)” function. Finally this value can be saved as User meta.

Part 2=======================================================================

add_action('login_form', 'add_login_field');
function add_login_field()
{

?>    
       <p>
  <label for="user_pass">My Input<br>
  <input type="text" name="my_name" value=""/>
 </p>


 <?     
    }

function do_anything($user) {

    //do stuff

   $userdata= $user = get_userdatabylogin($user);
   $user_id = $userdata->ID;

   $my_name = $_POST['my_name'];


add_user_meta( $user_id, 'my_name', $my_name);
}
add_action('wp_login', 'do_anything');


add_filter('authenticate', 'check_login', 10, 3);

function check_login($user, $username, $password) {
  global $wpdb;  
if(isset($_POST['my_name']) && trim($_POST['my_name'])!="")
{
    $customfield    =   $_POST['my_name'];
$UsermetaData = $wpdb->get_results("SELECT *FROM  wp_usermeta WHERE meta_value="$customfield"");
$user = get_user_by('id', $UsermetaData[0]->user_id );

// Redirect URL //

if ( !is_wp_error( $user ) )
{
    wp_clear_auth_cookie();
    wp_set_current_user ( $user->ID );
    wp_set_auth_cookie  ( $user->ID );

    $redirect_to = user_admin_url();
    wp_safe_redirect( $redirect_to );
    exit();
}
return $user;
}

}

Please check this code snippet. Also you need to modify the code as per requirements. Make sure “my_name” field remain unique and it will not be updated every time on log in.

Related Posts:

  1. Can someone explain what wp_session_tokens are, and what are they used for?
  2. Init action hook running late after PayPal’s return url?
  3. How to check WordPress website username and password is correct
  4. Log in from one wordpress website to another wordpress website
  5. Problems after wp_set_password() containing an apostrophe
  6. Two-step login process – Is it possible?
  7. How do I approach removing menu items on the fly based on settings in my plugin?
  8. Is there any way to check for user login and send him to login?
  9. Proper way to pass credentials in a custom login form to avoid “headers already sent”
  10. External Authentication, session_tokens not destroyed on logout
  11. Verify if user is wordpress logged in from another app since wordpress 4.0
  12. wp_insert_user() function password never match
  13. Does wp_login only trigger before an user signs in into the admin panel?
  14. Logout users upon login, based on caps/role?
  15. Is it possible to make sure that only my plugins output is shown to the enduser?
  16. Password field is empty when using wp_signon();
  17. Plugin Development for registered users
  18. Enqueue script globally
  19. WP Multisite login not working on one subsite. Possibly cookies/ history issue?
  20. How do I validate extra pin field on my WordPress login form page?
  21. How to redirect home page to another page after login for all user?
  22. How to share user data across multiple WordPress websites?
  23. Allowing duplicating users with same user_login and user_email
  24. How to Login a User inside a Plugin and Redirect to page?
  25. Using custom IDP with WP
  26. Hiding the WordPress login and password fields from login page
  27. redirect_to how to make it simply work with get parameter or similar?
  28. Multiple Users Logged In Causing Incorrect Account Returned
  29. Get user logged in status from within a plugin. $current_user not defined
  30. Need edit profile link in the menu for logged in users
  31. Create a Custom Login System in WordPress [closed]
  32. how can I insert a link on login page
  33. user can login from single account detail from multiple locations(computer) at the same time [closed]
  34. how to works woocommerce cart hash
  35. Objective Best Practices for Plugin Development? [closed]
  36. add_menu_page() with different name for first submenu item
  37. Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
  38. How to include PHP files in plugins the correct way
  39. How can I add an image upload field directly to a custom write panel?
  40. A tool to analyze rewrite rules? [closed]
  41. Difference Between Filter and Action Hooks?
  42. framework for plugin/theme options panel? [closed]
  43. Creating a table in the admin-style?
  44. 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?
  45. Settings API with arrays example
  46. How to get the path to the current theme?
  47. How to make a plugin require another plugin?
  48. ajaxurl not defined on front end
  49. What process do you use for WordPress development? [closed]
  50. What’s the difference between term_id and term_taxonomy_id
  51. Should I use wpdb prepare?
  52. Why does WordPress use outdated jQuery v1.12.4?
  53. Post meta vs separate database tables
  54. Is there any plugin development framework
  55. Is it possible to reuse wp.media.editor Modal for dialogs other than media
  56. How to add a javascript snippet to the footer that requires jQuery
  57. Enhance Media Manager for Gallery
  58. How do I create a custom role capability?
  59. How do I add CSS options to my plugin without using inline styles?
  60. How do i best handle custom plugin page actions?
  61. Adding Custom Text Patterns in the WP 4.5 Visual Editor
  62. Automatically determine minimum WordPress version required for a plugin?
  63. What is the advantage of using wp_mail?
  64. How to make a WordPress plugin translation ready?
  65. How many times will this code run? (or, how rich is grandma?)
  66. How to create an API for my plugin?
  67. Is it ever okay to include inline CSS in plugins?
  68. Plugins in symlinked directories?
  69. How to override existing plugin action with new action
  70. How to include a file using get_template_part() in a plugin?
  71. Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
  72. How to store username and password to API in wordpress option DB?
  73. body_class hook for admin pages
  74. “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
  75. Is it mandatory to use $wpdb->prefix in custom tables
  76. Which hook should be used to add an action containing a redirect?
  77. add_action hook for completely new post?
  78. Why does WordPress add 0 (zero) to an Ajax response?
  79. What should I use instead of WP_CONTENT_DIR and WP_PLUGIN_DIR?
  80. How to enqueue JavaScripts in a plugin
  81. In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
  82. Plugin Form Submission Best Practice
  83. How to redirect to settings page once the plugin is activated?
  84. Is get_option function cached?
  85. Should Plugin Folders Include a Blank index.php File?
  86. Unit testing for plugin development
  87. Methods of Integrating Plugin Data with Themes
  88. What is the wordpress wp-includes folder for?
  89. WordPress Update Plugin Hook/Action? Since 3.9
  90. How to include jQuery and JavaScript files correctly?
  91. How come `wp_options` table does not have an index on `autoload`?
  92. PHP error with shortcode handler from a class
  93. Update Option Stored in Multi-Dimensional Array
  94. check if Gutenberg is currently in use
  95. Best way to abort plugin in case of insufficient PHP version?
  96. WordPress Plugin Development – Headers Already Sent Message
  97. WP 3.3 How to Add Menu Items to the Admin Bar?
  98. dbDelta not creating tables
  99. Custom Widget function in Plugin not working?
  100. Passing arguments to a admin menu page callback?
Categories plugin-development Tags login, plugin-development
Custom Gallery HTML only working when images are attached to post/page
$wpdb doesn’t like to store arrays

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