[buddypress-trac] [BuddyPress Trac] #7658: Use WP functions to retrieve current user ID.

buddypress-trac noreply at wordpress.org
Wed Jan 17 18:28:33 UTC 2018

#7658: Use WP functions to retrieve current user ID.
 Reporter:  dcavins       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Core          |    Version:  2.9.2
 Severity:  normal        |   Keywords:
 In BuddyPress, we store the current user ID in the `$bp` global. The
 function `bp_loggedin_user_id()` then refers to this value. I wonder if
 there's any value in storing this value, and if instead we should let WP
 handle the current user ID, and simplify `bp_loggedin_user_id()` to call
 `get_current_user_id()` and pass it through the `bp_loggedin_user_id`

 One case in particular caused me to look more into this. When making a WP
 REST API request, if the request doesn't include a valid nonce, the
 current user is downgraded to "not logged in" status. However, because BP
 has already stashed the current user ID before the downgrade happens in
 `rest_cookie_check_errors()`, `bp_loggedin_user_id()` doesn't match the
 value of `get_current_user_id()`. The return values of these functions
 looks like this, for instance:

 bp_loggedin_user_id: 1
 get_current_user_id: 0

 On the other hand, it's pretty handy for cookie authentication to continue
 to work.

 Thanks for your thoughts on how best to resolve this inconsistency.

Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7658>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac

More information about the buddypress-trac mailing list