Make WordPress Core

Opened 15 years ago

Closed 11 years ago

Last modified 11 years ago

#19615 closed enhancement (fixed)

Deprecate get_currentuserinfo()

Reported by: scribu Owned by: swissspidy
Priority: normal Milestone: 4.5
Component: Users Version:
Severity: normal Keywords: has-patch commit
Cc: Focuses:

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)

19615.diff​ (2.9 KB ) - added by scribu 15 years ago.
19615.2.diff​ (2.6 KB ) - added by scribu 15 years ago.
19615.3.diff​ (3.6 KB ) - added by swissspidy 11 years ago.
19615.4.diff​ (4.1 KB ) - added by swissspidy 11 years ago.

Download all attachments as: .zip

Change History (32)

#1 @scribu
15 years ago

  • Keywords has-patch added

#2 @scribu
15 years ago

  • Keywords has-patch removed

It seems it won't be so easy, since wp_get_current_user() itself calls get_currentuserinfo().

#3 follow-up: @scribu
15 years ago

  • Keywords has-patch added

19615.2.diff​ moves all the logic from get_currentuserinfo() into wp_get_current_user().

#4 @scribu
15 years ago

  • Component General → Users

#5 in reply to: ↑ 3 @DrewAPicture
15 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

#6 @chriscct7
12 years ago

Is there continued interest in deprecating get currentuserinfo?

#7 @chriscct7
11 years ago

  • Keywords needs-refresh added

#8 @swissspidy
11 years ago

  • Focuses docs added
  • Keywords needs-refresh removed
  • Milestone Awaiting Review → 4.5

Is there continued interest in deprecating get currentuserinfo()?

Yes! For the reasons outlined by scribu.

19615.3.diff​ is an updated patch.

#9 @swissspidy
11 years ago

  • Keywords commit added

#10 @swissspidy
11 years ago

  • Owner set to swissspidy
  • Status new → assigned

#11 @swissspidy
11 years ago

  • Resolution → fixed
  • Status assigned → closed

In 36311:

Users: Deprecate the get_currentuserinfo() pluggable function.

It encourages an ugly pattern like global $userdata; get_currentuserinfo(); in plugins/themes. wp_get_current_user() should be used instead, e.g. $current_user = wp_get_current_user();.

Props scribu for initial patch.
Fixes #19615.

#12 @swissspidy
11 years ago

In 36313:

Users: Always return $current_user in wp_get_current_user(), never a boolean.

Fixes unit tests affected by [36311].

See #19615.

#13 @ocean90
11 years ago

In 36314:

Docs: Fix @return type for wp_get_current_user() after [36313].

See #19615.

#14 follow-up: @johnbillion
11 years ago

  • Focuses docs removed
  • Keywords needs-patch added; has-patch commit removed
  • Resolution fixed
  • Status closed → 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 @swissspidy
11 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 calls get_currentuserinfo() in doing so. This causes an infinite loop because get_currentuserinfo() now calls wp_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.

Last edited 11 years ago by swissspidy (previous) (diff)

#16 @dd32
11 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: @chris@…
11 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 @shazahm1@…
11 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 @georgestephanis
11 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

​https://github.com/Automattic/jetpack/pull/3285

#20 @chris@…
11 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
connections​fixed 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
jetpack​fixed 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 @dd32
11 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 @swissspidy
11 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 @ocean90
11 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 @swissspidy
11 years ago

  • Keywords has-patch added; needs-patch removed

19615.4.diff​ introduces _wp_get_current_user().

#25 @ocean90
11 years ago

  • Keywords commit added

#26 @swissspidy
11 years ago

  • Resolution → fixed
  • Status reopened → closed

In 36651:

Users: Introduce _wp_get_current_user() for improved backward compatibility.

This new helper function is used by the pluggable functions wp_get_current_user() and get_currentuserinfo(), which was previously being called by the former before [36311]. Without it, infinite loops could be caused when plugins implement these functions, as they are now called the other way around.

Fixes #19615.

#27 @DrewAPicture
11 years ago

In 36705:

Docs: Make a few syntactical improvements to the DocBlock for _wp_get_current_user(), introduced in [36651].

Includes a cross reference from the DocBlock for wp_get_current_user(), which itself is pluggable, but the new internal function is not.

See #19615. See #32246.

#28 @DrewAPicture
11 years ago

In 37008:

Docs: Clarify the use of the get_currentuserinfo() for backward compatibility purposes in the DocBlock description for _wp_get_current_user(), introduced in [36651].

See #19615. See #35986.

Note: See TracTickets for help on using tickets.