This is because of your plugin code is executed much earlier, than wp-login.php. You can read about WordPress loading sequence here, for example.
To behave properly, your code must be executed in ‘wp_login’ hook:
add_action( 'wp_login', 'wp_login_action', 10, 2 );
function wp_login_action( $user_login, $user ) {
current_user = wp_get_current_user();
print_r($current_user);
}
Related Posts:
- Is get_option() faster than accessing get_transient()?
- Best practices for using the transients API
- Trouble with Transient API when W3TC is activated [closed]
- How to make dynamically-generated content searchable in WordPress?
- How can I free up the memory used by update_post_meta?
- How can I render shortcode so that its not cached by Caching plugins?
- Does WordPress’s HTTP API use any caching?
- Will cron job run if page loaded is being served from cache?
- Is using WP Transients to save external data for a plugin the best/right way?
- Cache directory needed for plugin
- Clearing cached plugin data if it is using an external object cache
- Make WordPress cache permanent for some pages until edited
- Will setcookie work if there is a cache plugin installed?
- Maximum lifetime for nonce
- Clearing caches on plugin uninstall
- How to implement filesystem cache in WordPress
- Is using custom table to suit business needs instead of transients a big hit to page load speed?
- Caching the_content calls
- Service Worker Uncaught (in promise) DOMException
- Should I use wp-content/cache or [PLUGIN_DIR]/cache?
- How can I control if post updated
- Undefined cache functions in my custom plugin
- Is it possible to restore an expired transient?
- Plugin files not updated (cache cleared)
- Does WP REST API cache internally executed (rest_do_request) requests?
- Best way to abort plugin in case of insufficient PHP version?
- What do you think about custom designed plugin/theme options UIs?
- Is it necessary to bump a plug-in’s version if you’re just updating the “Tested up to” attribute?
- Adding Widget form fields dynamically
- Optimize shortcode callbacks
- Custom action button in Gutenberg editor (post_submitbox_misc_actions – equivalent)
- Modifying the way WP sets cookies
- add_action with a class method is causing fatal errors
- Include third party Javascript library which is not included in WordPress
- Update a Plugin while maintaining back compatibility: general
- Do I need to use WP_Filesystem when creating a downloadable file on the fly?
- When wp_schedule_event action has two possible directions, how to avoid an infinite loop?
- How to get vim to autocomplete WordPress API functions?
- Not sure the best way to save custom plugin data
- The ideal place for storing persistent PHP objects
- How do I make specific plugin functionality apply to different sites in a network?
- Plugin development with unit tests
- Change WordPress.org hosted plugin readme.txt
- get_posts / WP_Query Memory size of 134217728 bytes exhausted
- What is a settings group actually for?
- WP_Error handles errors, but how can I show success with a message?
- The changes I make to an external JS file of my WP plugin are only applied after I clear my browser’s cache
- How does gettext works for translating readme file of plugin?
- How to debug WordPress correctly?
- `wp_set_script_translations` with `wp.i18n` does not return translated strings in simple plugin
- Sessions not creating correctly in custom function
- How to add multiple copies of a widget from “available widgets”
- Problem with `wp_mail()`
- How to add meta boxes to the ‘Add new post’ screen?
- Load WooCommerce templates from my plugin folder first
- How to determine wordpress base path when wordpress core is not loaded
- How do I approach removing menu items on the fly based on settings in my plugin?
- Can I use core’s “or Link to Existing Content” feature in my plugin?
- add_menu_page() with function inside a class [duplicate]
- Plugin with specific admin menu icon
- Overwrite default XMLRPC function from plugin
- Cannot modify header information – headers already sent by pluggable.php
- htmlentities and editing text
- Gutenberg registerFormatType with Multiple Classes
- Translate strings not recognised in plugin
- Best way to notify WordPress plugin users of new release candidates for beta testing?
- How to update total price of completed order in woocommerce? [closed]
- Print WordPress username id inside JavaScript
- How do I add a custom sublevel menu specified in one directory to a custom top level menu specified in another directory?
- How to Download and install plugin database remotely
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Should I always prefer esc_attr_e & esc_html_e instead of _e?
- WordPress add_admin_page not working even parameters are correct?
- How to use WP_Term with (menu) argument in the wp_nav_menu?
- Turn off Admin Bar (Toolbar) in backend – no easy way
- Preview Changes button missing on custom post type page since updating to 3.4
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- Communicate between plugins
- When to use add_settings_section vs just register_setting?
- WP_Editor – Saving Value into Plugin Option – Stripping HTML
- How to customize login process
- How should I store a log for my plugin
- $paged always 0 on plugin’s custom page
- Adding more text to a post, after it was published
- How to modify the comments to be displayed in a post?
- what is the difference between these phares?
- WP_Query filters
- SSL certificate verify failed
- Is there a way in which I can compare product id with the order id to display content on front end before placing the order? [closed]
- Video Security just like facebook [closed]
- Email verification for new users
- Find Any Theme’s page.php File
- WP Job Manager – Show recent jobs as cards
- Admin Menu for New Post
- Elementor Top-Bar
- Is it possible to add Custom Dashboard Widgets to Custom Admin Menu Page?
- WordPress – Custom permalinks for advanced custom fields (ACF) using post type taxonomy
- Insert Button in to the Block Editor (Header) Toolbar
- Customize Message
- My wordpress plugin defaults to English (US) I would like it to default to English (UK)