[wp-trac] [WordPress Trac] #28020: get_userdata and wp_get_current_user do not share WP_User instance

WordPress Trac noreply at wordpress.org
Sun Aug 4 09:00:35 UTC 2019


#28020: get_userdata and wp_get_current_user do not share WP_User instance
--------------------------------------+---------------------
 Reporter:  rmccue                    |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:
Component:  Users                     |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------

Comment (by donmhico):

 My first patch,
 [https://core.trac.wordpress.org/attachment/ticket/28020/28020.diff
 28020.diff], doesn't work. I found out that the code:

 {{{#!php
 if ( get_current_user_id() == $userdata->ID ) {
     return wp_get_current_user();
 }
 }}}

 If placed inside `get_user_by()`, makes the WP run in an infinite loop.
 It's because `wp_get_current_user()` has the code

 {{{#!php
 $user_id = apply_filters( 'determine_current_user', false );
 }}}

 Which, if we dive deeper, invokes the function `wp_validate_auth_cookie()`
 that also uses `get_user_by()` creating the infinite loop error.

 So instead, I found out that directly using the global `$current_user`
 solves the problem. I've attached a new patch,
 [https://core.trac.wordpress.org/attachment/ticket/28020/28020.1.diff
 28020.1.diff], that includes the fix.

 @rmccue - You're not kidding. It's extremely annoying and insane to debug.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/28020#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list