[wp-trac] [WordPress Trac] #28020: get_userdata and wp_get_current_user do not share WP_User instance
WordPress Trac
noreply at wordpress.org
Fri Apr 25 01:51:56 UTC 2014
#28020: get_userdata and wp_get_current_user do not share WP_User instance
--------------------------+-----------------------------
Reporter: rmccue | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Just discovered this fun one.
Steps to reproduce:
{{{
$uid = 3;
// UID for this demo should be a subscriber
wp_set_current_user( $uid );
// $GLOBALS['current_user'] now contains a WP_User instance
$from_userdata = get_userdata( $uid );
// $from_userdata now also contains a WP_User instance, but not the same
one
// Fun times with desynchronisation:
$from_userdata->set_role( 'administrator' );
assert(current_user_can('administrator'));
}}}
(I suspect you can also reproduce by using `wp_update_user` instead of
`get_userdata`)
This is probably due to the fact that we don't use object caching for the
user object instances, which would let us share the instances.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28020>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list