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

Custom login doesn’t work properly

Here is my working solution:

function custom_login() {
    if(!empty($_POST['user_login']) && !empty($_POST['user_pass'])){
        $login_data = array();
        $login_data['user_login'] = sanitize_user($_POST['user_login']);
        $login_data['user_password'] = esc_attr($_POST['user_pass']);
        $login_data['rememberme'] = true;
        $nonce = $_REQUEST['_wpnonce'];

        $user = wp_signon( $login_data, false );

        global $user_ID;
        // Check whether the user is already logged in and the nonce is verified
        if ( !$user_ID && !wp_verify_nonce( $nonce, 'wp_login' ) ) {
            exit;
        } else {
            if ( is_wp_error($user) ) {
                echo $user->get_error_message();
            } else {
                wp_clear_auth_cookie();
                do_action('wp_login', $user->ID);
                wp_set_current_user($user->ID);
                wp_set_auth_cookie($user->ID, true);
                wp_safe_redirect(home_url());
                exit;
            }
        }
    }
}

Related Posts:

  1. wp_nonce_field displaying twice
  2. PHP error with shortcode handler from a class
  3. Add self-closing shortcode button to TinyMCE in WP 4.6
  4. Optimize shortcode callbacks
  5. Nonces can be reused multiple times? Bug / Security issue?
  6. How would I create a plugin for my shortcodes?
  7. How to prevent newline from appearing in shortcode?
  8. Shortcode adding p and br tags
  9. What is nonce and how to use it with Ajax in WordPress? [duplicate]
  10. Are shortcodes case-sensitive?
  11. Enqueue script only when shortcode is used, with WP Plugin Boilerplate
  12. Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
  13. Nonce in settings API with tabbed navigation
  14. WordPress REST API call generates nonce twice on every call
  15. How to make WordPress use non-greedy shortcode parsing?
  16. Multiple Parameters for a Shortcode
  17. How do I make specific plugin functionality apply to different sites in a network?
  18. Shortcodes, output buffering, and WordPress functions
  19. Filter on the_content ignores shortcodes
  20. stray elements
  21. Pass javascript result to shortcode executer function
  22. Front-End Form Submission in Shortcode
  23. How to get shortcode to work inside a foreach loop called within a shortcode?
  24. Get returned variable from a function to add_shortcode function
  25. What is rich_editing?
  26. Why is my shortcode not working
  27. Confusion on WP Nonce usage in my Plugin
  28. Error : “Updating failed: The response is not a valid JSON response” with custom shortcode
  29. On plugin deactivation hide its shortcode
  30. Can’t get JS code to work with shortcode
  31. add_shortcode is not working [duplicate]
  32. WordPress password reset – why post rp_key?
  33. How can I render shortcode so that its not cached by Caching plugins?
  34. Is it possible to delay execution of shortcode output callback?
  35. Processing shortcodes in groups (separated by line breaks)?
  36. Verify Nonce returns false – Request Nonce returns correct value
  37. How do I write a shortcode that opens and closes?
  38. Using a Shortcode to Replace Themes Stylesheet?
  39. Why is my javascript not invoked in my hooks except wp_head?
  40. Gutenberg Block showing invalid content on edit
  41. Creating a shortcode, but getting tied up with OOP and Classes?
  42. Storing product price data in the database
  43. What is the best way to embed an JS App in a WordPress Page?
  44. Maximum lifetime for nonce
  45. What is the proper way to include Bootstrap when executing a shortcode
  46. Auto gallery from folder contents
  47. Secure Pages Best Practice
  48. Adding option to Gallery shortcode
  49. add_shortcode() not working inside of function
  50. Passing nonce at admin menu link
  51. Is nonce in PHP form and Ajax both necessary?
  52. Asynchronously render shortcodes in TinyMCE visual editor
  53. Is using custom table to suit business needs instead of transients a big hit to page load speed?
  54. Run Shortcode of post’s custom field in functions.php / Plugin
  55. Shortcode returning localized HTML part
  56. Hide shortcodes “code” when using the “editor” the same as wordpress do with “gallery”
  57. Enumerating shortcode attributes in JavaScript
  58. Wrap text around shortcode
  59. How to handle shortcodes through plugin
  60. Using a custom shortcode from within the template of a shortcode plugin
  61. When echoing my own shortcode, it keeps adding a 1 at the end of my blogpost
  62. Automating the process of shortcode generation in a plugin – how is it done?
  63. Create Widget or Enable Shortcodes in Sidebar
  64. The Correct Way to Use Nonce Field without Settings API
  65. Can we intercept user_login and user_pass from a wp_login_form?
  66. shortcode executed in the page editor
  67. Shortcode not appearing when used as post content in wp_insert_post() or possibly, shortcode not being registered at all
  68. How to make my shortcode load scripts and styles, from within the plugin?
  69. How to display the categories on page using shortcode?
  70. Shortcode conflicts
  71. How to use nonce
  72. How to create ShortCode
  73. Where to use nonce
  74. How do I validate extra pin field on my WordPress login form page?
  75. How to display the specific post content by using POST ID
  76. How to output functions from plugin inside theme
  77. add_filter img_caption_shortcode not implemented
  78. shortcode tags not working in do_shortcode
  79. How to insert HTML/CSS/JS into my iframe plugin?
  80. Including template in shortcodes
  81. Form submission to another page returning 404 error [duplicate]
  82. Passing values between enclosing and enclosed shortcodes
  83. post content and shortcode content displaying out of order
  84. Font size of HTML content
  85. Cannot output plugin twice with shortcode
  86. Paragraph Tags removed when contents are only a shortcode
  87. How to call a function from a shortcode function in an oop plugin
  88. WP_List_Table Inside Metabox With Bulk Actions Not Working on Submit
  89. WPGut – Updating failed and shortcode?
  90. How to write a custom shortcode name book?
  91. By adding “?login – failed” code unable to access my dashboard
  92. How can I pass WP_Query results to a plugin?
  93. Hiding the WordPress login and password fields from login page
  94. How can we stop showing short code in create or edit post section
  95. Shortcode content is not showing. Only the [shortcode-tag] is showing
  96. how to add security questions on wp-registration page and validate it
  97. Including content into an add_shortcode() function
  98. Pass javascript result to shortcode executer function
  99. Some data has already been output, can’t send PDF file – fpdf issue in WordPress
  100. How do I make two shortcode use the same id and increment it when I use them multiple times?
Categories plugin-development Tags authorization, nonce, plugin-development, shortcode, wp-login-form
How can I hardcode template selection?
result from custom filter admin table list backend does not work

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