#19615 closed enhancement (fixed)
Deprecate get_currentuserinfo()
Reported by: | scribu | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Users | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
get_currentuserinfo()
is a pluggable function that encourages an ugly pattern in theme files:
global $userdata; get_currentuserinfo();
It can easily be replaced with this:
$current_user = wp_get_current_user();
Attachments (4)
Change History (32)
#3
follow-up:
↓ 5
@
13 years ago
- Keywords has-patch added
19615.2.diff moves all the logic from get_currentuserinfo() into wp_get_current_user().
#5
in reply to:
↑ 3
@
13 years ago
Replying to scribu:
19615.2.diff moves all the logic from get_currentuserinfo() into wp_get_current_user().
Sounds good to me. +1
#8
@
9 years ago
- Focuses docs added
- Keywords needs-refresh removed
- Milestone changed from Awaiting Review to 4.5
Is there continued interest in deprecating
get currentuserinfo()
?
Yes! For the reasons outlined by scribu.
19615.3.diff is an updated patch.
#14
follow-up:
↓ 15
@
9 years ago
- Focuses docs removed
- Keywords needs-patch added; has-patch commit removed
- Resolution fixed deleted
- Status changed from closed to reopened
[36311] is causing a fatal error on one of my sites.
A plugin on the site defines the wp_get_current_user()
function (as it's pluggable) and calls get_currentuserinfo()
in doing so. This causes an infinite loop because get_currentuserinfo()
now calls wp_get_current_user()
.
#15
in reply to:
↑ 14
@
9 years ago
Replying to johnbillion:
[36311] is causing a fatal error on one of my sites.
A plugin on the site defines the
wp_get_current_user()
function (as it's pluggable) and callsget_currentuserinfo()
in doing so. This causes an infinite loop becauseget_currentuserinfo()
now callswp_get_current_user()
.
Sigh :/
What do you think of making get_currentuserinfo()
behave as before, i.e. being basically a duplicate of wp_get_current_user()
? Not an exact duplicate of course, just so that the functions don't rely on each other.
#16
@
9 years ago
Another option would be to do something like:
if not exists function get_currentuserinfo() return _core_func_wp_get_current_user() if not exists function wp_get_current_user() return _core_func_wp_get_current_user() function _core_func_wp_get_current_user() { // The actual logic. }
#17
follow-up:
↓ 19
@
9 years ago
I get that the pattern is ugly but it is actually the pattern that's still (as of this posting) the one that's shown on the codex. This just seems like change for the sake of change. If a change needs to be made I think I'd like to see @dd32's recommendation done.
A quick grep on my server shows the following 19 plugins that use this function (some might not be recently updated although I can't imagine anyone would have swapped this out)
all-in-one-event-calendar
all-in-one-seo-pack
bbpress
connections
contact-form-7-modules
duplicate-post
gigpress
google-analytics-for-wordpress
jetpack
js_composer
js_composer_theme
LayerSlider
nextgen-gallery
share-this
templatera
user-role-editor
user-role-editor-pro
usernoise
wp-to-twitter
We're also seeing this in several pre-built themes like Avada and Jupiter.
There is at least one plugin that actually "plugged" it and that's URL Auth although it was last updated 5 years ago.
#18
@
9 years ago
@chris@…
Just an fyi, Connections, removes use of the get_currentuserinfo() function in the most recent released version.
#19
in reply to:
↑ 17
@
9 years ago
Replying to chris@…:
jetpack
We got a pull from @rachelbaker and merged it in two days ago, and it's already shipped out with our current release of 3.9.0
#20
@
9 years ago
Thanks @georgestephanis and @shazahm1@…! I've found some more servers to grep and have this list of plugins so far. Many of these haven't been touched in years (one is 11 years old) and I imagine aren't installed too much.
adresses-maps-pages-et-categories
all-in-one-event-calendar
all-in-one-seo-pack
altstats
apocalypse-meow
bainternet-posts-creation-limits
bbpress
bp-new-ui
buddypress-update-email-reminder-lightbox
cardoza-wordpress-poll
connectionsfixed in 8.5.8
contact-form-7-modules
cryptopoints-manager
dragons-printhint
duplicate-post
easy-chitika-lite
email-queue
formbuilder
gigpress
google-analytics-for-wordpress
google-maps-builder
hreview-support-for-editor
insert-html-snippet
javascript-chat-for-wordpress
jetpackfixed in 3.9.0
js_composer
js_composer_theme
LayerSlider
livehelpnow-help-desk
moderate-selected-posts
newsletter
nextgen-gallery
pegleg-ratings
rate-it
revver-wordpress-video-plugin
share-this
shortcodes-ui
sola-support-tickets
td-ticket-system
templatera
user-control
user-role-editor
user-role-editor-pro
usernoise
woocommerce-newsletter-signup
woodiscuz-woocommerce-comments
wordpress-restrictions
wordpress-seo-plugin
wordpress-ticket-plugin
wp-artists-lite
wp-live-chat-support
wp-swimteam
wp-to-twitter
wpcb
wplistcal
#21
@
9 years ago
Chris - Plugins using deprecated functionality is OK, just because we've deprecated it, it doesn't mean it's going to stop working next week. All plugins using it will get updated over time, and if they're not, they'll keep working, just with a deprecated notice to any developers using it.
Just because plugins use a function, that's not good grounds not to deprecate it either.
The only pending question here is if there's any BC breaks, and the fatal error mentioned seems like the only one I can see - that can be fixed by doing something like what I suggested (as these are legacy pluggable functions)
#22
@
9 years ago
Have there been any other reports of fatals besides the case John mentioned?
A partial revert as suggested would prevent this, just like a new separate function would, too. I personally prefer the former.
#23
@
9 years ago
I like the idea of comment:16:
- get_currentuserinfo() => pluggable-deprecated.php
- wp_get_current_user() => pluggable.php
- _wp_get_current_user() => user.php
#24
@
9 years ago
- Keywords has-patch added; needs-patch removed
19615.4.diff introduces _wp_get_current_user()
.
It seems it won't be so easy, since wp_get_current_user() itself calls get_currentuserinfo().