WordPress.org

Make WordPress Core

Opened 16 months ago

Last modified 7 months ago

#23040 new enhancement

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

Reported by: wpsmith Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Themes Keywords: 2nd-opinion dev-feedback
Focuses: Cc:

Description

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 (1)

class-wp-theme.php.patch (3.1 KB) - added by wpsmith 7 months ago.
Deprecating methods

Download all attachments as: .zip

Change History (7)

comment:2 scribu16 months ago

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

comment:3 scribu16 months ago

  • Type changed from defect (bug) to enhancement

comment:4 nacin16 months 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.

wpsmith7 months ago

Deprecating methods

comment:5 wpsmith7 months 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 months ago by wpsmith (previous) (diff)

comment:6 wpsmith7 months ago

  • Summary changed from Expand __get() method of WP_Theme object to Deprecate magic methods __isset() & __get() method of WP_Theme object
Note: See TracTickets for help on using tickets.