Make WordPress Core

Opened 11 years ago

Last modified 3 years ago

#23040 assigned enhancement

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

Reported by: wpsmith's profile wpsmith Owned by:
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 11 years ago.
Deprecating methods
23040.r1.patch (2.9 KB) - added by wpsmith 10 years ago.

Download all attachments as: .zip

Change History (13)

#2 @scribu
11 years ago

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

#3 @scribu
11 years ago

  • Type changed from defect (bug) to enhancement

#4 @nacin
11 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.

11 years ago

Deprecating methods

#5 @wpsmith
11 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 11 years ago by wpsmith (previous) (diff)

#6 @wpsmith
11 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
10 years ago

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

10 years ago


#8 @wpsmith
10 years ago

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

#9 @chriscct7
8 years ago

  • Keywords needs-refresh added

#10 @swissspidy
7 years ago

  • Keywords dev-feedback removed
  • Owner set to swissspidy
  • Status changed from new to assigned

#11 @swissspidy
3 years ago

  • Owner swissspidy deleted
Note: See TracTickets for help on using tickets.