Make WordPress Core

Opened 8 years ago

Last modified 4 years ago

#23040 assigned enhancement

Deprecate magic methods __isset() & __get() method of WP_Theme object

Reported by: wpsmith Owned by: swissspidy
Milestone: Future Release Priority: normal
Severity: normal Version: 3.4
Component: Themes Keywords: has-patch needs-refresh
Focuses: Cc:


Currently, a user can do the following:

$theme   = wp_get_theme();
$version = $theme->Version;
$name    = $theme->Name;
$author  = $theme->Author;
$version = $theme->Version;

So, when I tried to get the other data in the same method, I was getting nothing. However, to get the other data, one must do this:

$theme->{'Author URI'}; // per Codex;
$theme->get( 'AuthorURI' ); // $theme->AuthorURI doesn't work
$theme->get( 'ThemeURI' ); // $theme->ThemeURI & $theme->{'Theme URI'}; doesn't work
$theme->get( 'TextDomain' ); // $theme->TextDomain & $theme->{'Text Domain'}; doesn't work

get() is a great method to get the other data; however, shouldn't we make this consistent for developers?

Attachments (2)

class-wp-theme.php.patch (3.1 KB) - added by wpsmith 7 years ago.
Deprecating methods
23040.r1.patch (2.9 KB) - added by wpsmith 6 years ago.

Download all attachments as: .zip

Change History (12)

#1 in reply to: ↑ description @wpsmith
8 years ago

Updated the Codex Examples

#2 @scribu
8 years ago

  • Summary changed from Expand use of WP_Theme object to Expand __get() method of WP_Theme object

#3 @scribu
8 years ago

  • Type changed from defect (bug) to enhancement

#4 @nacin
8 years ago

The doc block for __get() says it is "for properties formerly returned by current_theme_info()". What it should also mention is this is deprecated functionality. So is offsetExists(), which implements ArrayAccess.

get() and display() are the proper methods to use. The property ($theme->property) and key ($theme['property']) ways of getting data should realistically be deprecated, as they have ambiguous and inconsistent behavior.

7 years ago

Deprecating methods

#5 @wpsmith
7 years ago

Updated Codex to only use the get() method. Added _doing_it_wrong() notifications to the magic methods __isset() & __get() and _deprecated_function() notification to offsetExists().

Last edited 7 years ago by wpsmith (previous) (diff)

#6 @wpsmith
7 years ago

  • Summary changed from Expand __get() method of WP_Theme object to Deprecate magic methods __isset() & __get() method of WP_Theme object

#7 @obenland
6 years ago

  • Keywords needs-refresh added; 2nd-opinion dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release
  • Version set to 3.4

6 years ago


#8 @wpsmith
6 years ago

  • Keywords dev-feedback has-patch added; needs-refresh removed

#9 @chriscct7
5 years ago

  • Keywords needs-refresh added

#10 @swissspidy
4 years ago

  • Keywords dev-feedback removed
  • Owner set to swissspidy
  • Status changed from new to assigned
Note: See TracTickets for help on using tickets.