[wp-trac] [WordPress Trac] #39385: Set $current_user global in wp_signon() after successful authentication
WordPress Trac
noreply at wordpress.org
Fri Dec 23 23:12:01 UTC 2016
#39385: Set $current_user global in wp_signon() after successful authentication
------------------------------------+-----------------------------
Reporter: fjarrett | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Login and Registration | Version: trunk
Severity: normal | Keywords:
Focuses: |
------------------------------------+-----------------------------
The `$current_user` global should be set after successful authentication
inside `wp_signon()` instead of waiting for the next load of WordPress.
Although the `$user_login` string and `$user` object are passed through
the `wp_login` hook, there are some functions that don't allow user
parameters and rely solely on `get_current_user_id()`, such as
`wp_destroy_other_sessions()`.
This is easy enough to work around, but it seems reasonable to expect that
user-related function calls should "just work" at any point after
authentication.
{{{#!php
<?php
add_action( 'wp_login', function ( $user_login, $user ) {
var_dump( get_current_user_id() ); // int(0)
$GLOBALS['current_user'] = $user;
var_dump( get_current_user_id() ); // int(1)
exit;
}, 10, 2 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39385>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list