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?
- Is there any plugin development framework
- Plugin – create a page without it appearing in the side menu
- Is wp-content/install.php a Drop-in?
- Handling results from data hooked into admin_post
- How to write testable classes in WordPress
- get_template_part from plugin
- Edit or Remove Plugin .htaccess Using The Admin Panel
- WordPress scheduled task is called but not executed
- How to create collections that are edited in admin?
- Get list of available wordpress actions
- How can i list current author’s categories?
- When is it too late to call the action wp_enqueue_scripts?
- Use js script from one plugin in another plugin
- Rest Api How to get results of child categories with one api call
- Build dynamic page from cURL (HTML page) response with plugin
- How to store accumulate multiple option values in a single array using Options_API
- Add Post and Comments menu no longer visible
- template_redirect for single posts w/ custom fields
- can I prevent WP users (even admin) from deleting custom categories?
- How to deal with equal & similar arguments for a function?
- What parameter should I pass to wp_enqueue_style to depend on the themes stylesheet?
- How do I obtain a list of categories assigned to the current post?
- Modify hard-coded conditionals for roles to custom roles
- Callback is not called in add_settings_field() when passed as part of an array, but recognises that it’s there. It’s passed Class to Class using OOP
- Plugin translations not installed but… strings are translated!
- Secure Pages Best Practice
- Does wp_login only trigger before an user signs in into the admin panel?
- How to access noticeOperations from withNotices
- Putting a resized image into media library with wp_get_image_editor(
- Using ReactJS in the WordPress admin for plugin development
- Thickbox doesn’t respect dimensions when used in admin [duplicate]
- wp_nonce_field displaying twice
- jQuery in WordPress Plugin
- Why is my plugin version 0.1?
- WP Plugin Running before jQuery
- How to include jQuery into my plugin so I can use it on plugin page?
- Apply function to update_option Variable
- WordPress multisite,use same cookies across all website?
- How to make and save custom form in custom plugin page?
- How to save post meta as an array in Gutenberg?
- WordPress Gutenberg InnerBlocks renderAppender not showing with template
- Duplicate shipping method logic to another shipping method [closed]
- REST Endpoint API 404
- How to disable a jQuery plugin on WordPress plugin page
- Does WordPress default CSS have Grids?
- Plugin to create Posts and Forums then choose category and parent forum
- Adding Permalink to Slides with ‘Simple Nivo Slider’ plugin?
- How to add a new taxonomy link to the admin menu
- Many Single Sites, One Plugin directory – adjust plugins_url()
- insufficient permissions; coding an action for plugin governed by custom capability
- My plugin creates custom widgets, How can I programatically add them to existing sidebar widget areas?
- Make a php array load faster
- Count products with custom metadata field in an order
- Include external po file for 3th party plugin to theme
- Adding the image selector/uploader to an admin back page
- setTimeout not working in jquery
- Woocommerce Product finder feature on home page
- How do I show the HTML descrption in wordpress photo gallery for my individual gallery pages?
- Javascript scroll eventHandler only working when I’m logged in in WordPress
- WordPress Reset password Strength set to medium
- Add language localisation to javascript alert?
- redirect_to how to make it simply work with get parameter or similar?
- cancel place order proccess
- How I can give access to my custom plugin for editor roles user?
- Testing Plugins for Multisite
- WP: adding Javascript to specific woo commerce pages
- Calling dynamic_sidebar in plugin gives error
- How to add chunk of php, html, and sql code to variable an append to $content
- edit-tags.php in plugin admin menu hides when is the active page
- Best way to handle a form post in plugin
- How To Remove The Filter That Adds JetPack Related Content To Dom [closed]
- Fixing plugin for wpdb::prepare
- Can I use an array to create multiple tables?
- Anyway to prevent admin from seeing other admin’s product?
- Bulk post approval and publishing doesn’t work