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

Send along login credentials with comment content

You can log a user in securely by simply calling wp_signon with the proper credentials. This has to be done before any output is produced, so that WP can set the users cookie properly.

Example:

$user = wp_signon(array('user_login'=>'example', 'user_password' = > 'swordfish'));

That will do a proper login from the front end of the site, set cookies, and return the user object. Then you can set the $commentdata[‘user_id’] = $user->ID and return, and the comment will be dealt with accordingly.

An auth failure will make that return a WP_Error object instead, so use is_wp_error on the result to see if it’s a WP_Error or a WP_User object that you get back.

Related Posts:

  1. Is there a hook that runs after a user logs in?
  2. Is there a hook before the user is authenticated?
  3. Run javascript code after wp_login hook?
  4. How can I do customizations on login, registration and password recovery forms?
  5. Can’t get ID of post that relates to the comment
  6. after login that will redirect user role into a page
  7. Firing a function AFTER redirect
  8. How to get session token of current user in wp_login hook?
  9. Custom action on login and “remember me”
  10. TinyMCE as comment editor – encoding issues
  11. Is it possible to add the_content filter upon login?
  12. Can’t get ID of post that relates to the comment
  13. Updating user meta data from external link, user not logged in
  14. How to add a new link to the default register form’s footer links?
  15. Does wp_login hook fire on user registration?
  16. Changing login url
  17. is_user_logged_in() doesn’t work after custom login and redirect
  18. Is there a way to send HTML formatted emails with WordPress’ wp_mail() function?
  19. How to get WordPress’ hooks/actions run sequence?
  20. Where can I find a list of WordPress hooks?
  21. Is there a save_post hook for custom post types?
  22. Where is the right place to register/enqueue scripts & styles
  23. How to know what functions are hooked to an action/filter?
  24. How to hook update_post_meta and delete_post_meta?
  25. Are there any hooks that alter the 404 logic?
  26. Difference between do_action and add_action
  27. WP Cron Doesn’t Execute When Time Elapses
  28. WooCommerce: change display order of product short description and price [closed]
  29. Why do some hooks not work inside class context?
  30. Difference between after_setup_theme and init action hooks?
  31. get $post in init filter or action?
  32. Use wp init hook to call other hooks?
  33. How many times can I hook into the same action?
  34. How do I implement the WordPress Iris picker into my plugin on the front-end?
  35. How to intercept a 404 error
  36. Move excerpt meta box to above content editor
  37. Action hook for custom tax edit
  38. Trigger custom action when setting button pressed
  39. What is “all” in isset($wp_filter[‘all’])
  40. Whats worth using add_action when we can simply use add_filter?
  41. Is there a limit to hook priority?
  42. Please explain how these hooks work
  43. How to change “You must be logged in to post a comment.”
  44. Add_action to wp_head via functions.php
  45. Hook after image is uploaded and image sizes generated
  46. Hook that fires when admin setting is saved
  47. add_action(‘wp_ajax_[action name]’, myfunction) problem
  48. WordPress auto login after registration not working
  49. What is the difference between update_post_meta and update_postmeta hooks?
  50. Hook ‘wp_enqueue_scripts’ priority has no effect
  51. Hook on trash post
  52. Hook *after* user password change?
  53. Auto-retrieve YouTube Image for Thumbnail?
  54. Which hook if user profile information is updated?
  55. How to remove action hook done in a plugin from functions.php in my theme?
  56. Hooks for trashing, deleting, saving, restoring custom post type
  57. Is there a WordPress core & plugins update action hook?
  58. Hook into WordPress update?
  59. trigger save_post event programmatically
  60. Implementing advanced add_* function wrappers
  61. Adding onload to body
  62. My add_action (wp_footer, ‘method’) is not calling?
  63. Do WordPress Core Filenames Work as Hooks?
  64. What is the earliest possible hook for safely using `is_front_page`?
  65. switch_to_blog(): Load textdomain
  66. How to call a REST endpoint when a post is published?
  67. __NAMESPACE__ with register_activation_hook
  68. Init action hook running late after PayPal’s return url?
  69. Can I hook inside another hook?
  70. Adding function directly vs using hook in function.php
  71. Are hooks called synchronously?
  72. How to check if which hook triggered the call to a function?
  73. How can I send to multiple Contact Form 7 recipients based on form input? [closed]
  74. Hook into wp_head(); in a plugin
  75. Send data to 3rd party api with wp_remote_post on wp_login
  76. is it possible to get the hook name in add_action?
  77. Hook for URL Request
  78. How do I flush the rules after saving settings using the Settings API?
  79. Does anyone have a visual breakdown of core hooks and when they are fired?
  80. How to customize the WP admin default help contents
  81. Hook to edit an column on comments screen?
  82. What is the action hook for save media-form on gallery tab?
  83. What hook is executed just after wp_query has been executed?
  84. Hide gutenberg option blocks
  85. The ‘user_has_cap’ hook seems to take two page loads to trigger
  86. How and where can we request new WordPress hooks to be added?
  87. Detecting post type within init action
  88. Disable block from editor based on post type
  89. WordPress Admin Tooltip hooks
  90. How can I tell if I’m on a login page? [duplicate]
  91. Difference between hooks Plugin_loaded and admin_int?
  92. Wp_update_post: Infinite loop even with remove_action solution, OOP
  93. Hook/notify when any option or setting is added or updated
  94. Is it possible to save/modify a post without calling the “save_post” action hook?
  95. Change the footer text on the login page
  96. Which hooks is this? add_action(‘wp’,
  97. Redirect logged in users if they are on a specific page
  98. Make W3 Total Cache “Empty All Caches” function purge varnish [closed]
  99. Use $query->set multiple times with pre_get_posts?
  100. admin_post hook not called
Categories hooks Tags comments, hooks, login
User Signup in Multisite – Need Plugin or Advice
Authenticating user for custom post type [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