Opened 6 years ago
Closed 6 years ago
#46019 closed defect (bug) (invalid)
Themes using get_users() appear to change the current user
Reported by: | lordmatt | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | trivial | Version: | 5.0.3 |
Component: | Users | Keywords: | |
Focuses: | Cc: |
Description
I have observed get_users() used to iterate through users (to make a list of current contributors) also changes the current user which causes the wrong user to be shown in the WP toolbar.
Change History (4)
#2
@
6 years ago
- Severity changed from normal to minor
You are right. I had second thoughts after I filed this ticket. I went back to the theme where I last saw the issue. It is used on wordpress.com so I assumed the code was solid.
I had created a watch array which checked the current user ID at the start and end of the template. It was different. By adding that a few more times I was able to see that get_users()
is, as you say, innocent. The change happened after foreach ( $all_users as $current_user ) {...}
I did not find any documentation on it but I suspect that maybe $current_user
is a global? Which is odd as $current_user
is the variable used in code examples. Changing this var throughout the theme to $my_current_user
removed the bug. I have left a support request for the theme author(s) so they can apply my changes.
Should $current_user
be a global - or at least something that can be changed within the loop?
#3
@
6 years ago
- Severity changed from minor to trivial
Did some digging. Back c.2012 or before $current_user
was a global (and still is for backwards compatibility). The true bug here, then is maybe that the WP toolbar depends on it? Is it worth posting a separate ticket for that? I don't want to overstep my bounds here.
Hi and welcome to Trac!
As far as I can see, neither
get_users()
norWP_User_Query
touch the$current_user
global which is used bywp_get_current_user()
or any other related globals, for that matter. Which means there shouldn't be such side effects.Does this still happen when running code in one of the default themes with no plugins active? Can you perhaps share the code you're using?