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

Should `wp_login` be used since it’s deprecated?

No, you shouldn’t, it’s deprecated

I don’t think wp_signon() can fill my needs in the same way wp_login() can

It does the exact same thing, but with a few new features

I read this runs after the login of a user and contains 2 parameter of which one is the username. With the username I can figure out their role.

You still need that username to call wp_login in the first place, the primary difference with wp_signon is that it’s passed inside a credentials array, rather than directly as a parameter.

If you had referred to the documentation, you’d have found a simple example taken from the codex:

$creds = array(
    'user_login'    => 'example',
    'user_password' => 'plaintextpw',
    'remember'      => true
);

$user = wp_signon( $creds, false );

if ( is_wp_error( $user ) ) {
    echo $user->get_error_message();
}

Also note:

Note: wp_signon() doesn’t handle setting the current user. This means that if the function is called before the ‘init’ hook is fired, is_user_logged_in() will evaluate as false until that point. If is_user_logged_in() is needed in conjunction with wp_signon(), wp_set_current_user() should be called explicitly.

A confusing point about your question

The question remains, should I use the wp_login() hook?

wp_login() is not a hook, it’s an actual function, and it’s the function that is deprecated. The hook is not deprecated, and muddling the two is confusing

Your Actual Question, and The One You Should Have Asked

I have a script that I’d like to run when somebody logs in, how do I do this and how do I get the users role?

By specifically asking about your attempted solution, you’ve constrained and limited the number of answers you could have gotten.

For example, wp_signon is called by wp_login, and the wp_login hook is triggered by wp_signon too:

add_action( 'wp_login', function( $username, \WP_User $user) {
    // the user object has all the information you need, the username is probably not that useful. Anything you do via the username will just fetch the `$user` that you've just been given
}, 10, 2 );

Reading the documentation here:

https://developer.wordpress.org/reference/hooks/wp_login/

We see the following:

Used By #Used By
wp-includes/user.php: wp_signon()

Related Posts:

  1. what is correct way to hook when update post
  2. Check php version before theme activation
  3. Change the footer text on the login page
  4. How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
  5. How to Remove a Filter from the Admin List Table?
  6. Hooking new functions to actions + passing parameters
  7. Find variables available at a given hook
  8. Delete option value from array using update_option()
  9. action hook wp_head higher priority as all other plugins/hooks
  10. Remove an action hook within a Class
  11. How to pass arguments to add_action() or retrieve return value of called function?
  12. Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
  13. Set meta field to publish date + 2 weeks
  14. Adding widgets to my plugin page instead of WordPress dashboard
  15. Adding function to Genesis genesis_header [closed]
  16. Modify custom field input data before creating a new post
  17. How to catch wordpress post ID when it’s published
  18. WordPress redirect redirecting too many times or not at all
  19. Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
  20. How to pass hook variable to function?
  21. Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
  22. Get original value in save_post action hooka
  23. How do I remove an action hook inside a class that is called by another class?
  24. Hook into all password resets in WordPress and get password before hashing?
  25. WordPress HTML Helper
  26. How to add custom checkout field in user details mail template
  27. Cannot modify header information – headers already sent
  28. How to change wp-admin and wp-login urls
  29. Is there a hook that I can use when a fatal error occurs?
  30. Reload part of checkout on changed shipping method
  31. Trying to build simple deposit code that hooks into woocommerce
  32. Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
  33. Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
  34. Remove metabox from WordPress menu editor page?
  35. Add a product to checkout via form
  36. Trying to place a custom field after the total section in the checkout page in woocommerce
  37. How to debug my custom login form looping intermittently
  38. Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
  39. Why ajax doesn’t work on certain wordpress hooks?
  40. Remove a div from RSS feed
  41. Is it possible to intercept all ajax requests and get the parameters and the returns?
  42. user_profile_update_errors hook not executing
  43. How to add an arrow to menu items has submenus
  44. WordPress Gravatar filter is removing my custom attributes
  45. Error in custom php function doesn’t exist
  46. Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
  47. Don’t insert if permalink is the same?
  48. Return a numerical function value in Customizer controls
  49. getting logged in user info (wp-load.php) from parent directory
  50. action theme mailchimp subscriber fields
  51. edit_comment_link is not showing for comment author
  52. how to make custom ajax handler?
  53. Are all hooks/functions tied to Kses meant for sanitization?
  54. Problem with login form
  55. Login to wordpress by clicking a link and specifying usernaname and password in url
  56. Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose
  57. jQuery code not working when included in functions.php
  58. Log in / Log Out Custom Button
  59. Is it possible to add the_content filter upon login?
  60. Why does wp_head hook my functions to the beginning of my source code?
  61. add_action taking an array with the 2nd argument?
  62. Pass argument to event hook
  63. How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
  64. How to redirect users based on role and content of redirect_to?
  65. Change CSS based on is_user_logged_in
  66. How to display login form anywhere, when user isn’t logged in, without redirecting?
  67. How to show a users bio on a page
  68. How can I open up my administrative panel to everyone?
  69. Override a function defined in wp-includes/comment-template.php
  70. Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
  71. Password minimum length in personal subscription [closed]
  72. How to use a custom hook
  73. Nested “do” and “add” Actions is possible?
  74. Run a code only on theme activation only during first activation
  75. Change order of custom submenu link in WP Admin?
  76. Theme activation hook in php class
  77. Theme not calling Jquery properly
  78. Are there action hooks for comments?
  79. How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
  80. Get access to variable from previous pageview, excluding ajax-calls
  81. Why does the post_type_link hook everything twice?
  82. How can I add a new row in a separate database when someone registers via WordPress?
  83. How to have different site identity logos on each page on Astra Theme [closed]
  84. How can I hook into the wp_mail function used by BackWPup?
  85. How to pass argument to add_action while the method is inside a class?
  86. Display attribute on shop page after the title
  87. One account with multiple logins
  88. Get user custom field value on function.php
  89. Lost in trying to create user database system
  90. Send notification email to admin for every new post published
  91. Adding function to child theme’s function.php
  92. Comapare get_user_meta value
  93. Shortcode to log user into current URL
  94. Action Hook Inside WordPress Plugin Shortcode
  95. PHP getting error when trying to access WP-Admin Dashboard
  96. I installed WordPress locally now how do I login?
  97. Dynamically adding filters
  98. If user is logged in not working
  99. Woocommerce custom Plugin in wordpress [closed]
  100. Change homepage content if user is logged in – BuddyPress
Categories PHP Tags actions, hooks, login, php
Translation plugin to translate another plugins
FLUSH_REWRITE_RULES – after or before REGISTER_POST_TYPE?

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