WP_Theme::__get( string $offset ): mixed
- Since
- 3.4.0
- Source
wp-includes/class-wp-theme.php:591
Compatibility
- WordPress
- since 3.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$offsetstring- Property to get.
Return value
mixed- Property value.
Performance profile
How much work a call to WP_Theme::__get() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 5–35
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 87.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme::__get() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5–15 | ->get_template_directory() |
| always | 5–17 | ->get_stylesheet_directory() |
| always | 5–19 | ->get_template() |
| always | 5–21 | ->get_stylesheet() |
| always | 5–31 | ->get_theme_root() |
| always | 5–33 | ->get_theme_root_uri() |
| always | 6–30 | ->get() |
!->parent() | 6–14 | ->parent() |
| always | 6–24 | ->get_screenshot() |
| always | 6–28 | ->display() |
| always | 6–35 | ->offsetGet() |
->parent() | 11–19 | ->parent(), ->parent(), ->get() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 87 | 5–35 | 16 | |
| 8.5 | 87 | 5–35 | 16 | |
| 8.4 | 87 | 5–35 | 16 | |
| 8.3 | 87 | 5–35 | 16 | |
| 8.2 | 87 | 5–35 | 16 | 1 more instruction than PHP 8.1 |
| 8.1 | 86 | 5–34 | 16 | |
| 7.4 | 86 | 5–34 | 16 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 11
- WP_Theme::get()Gets a raw, unformatted theme header.
- WP_Theme::parent()Returns reference to the parent theme.
- WP_Theme::get_template_directory()Returns the absolute path to the directory of a theme's "template" files.
- WP_Theme::get_stylesheet_directory()Returns the absolute path to the directory of a theme's "stylesheet" files.
- WP_Theme::get_template()Returns the directory name of the theme's "template" files, inside the theme root.
- WP_Theme::get_stylesheet()Returns the directory name of the theme's "stylesheet" files, inside the theme root.
- WP_Theme::get_screenshot()Returns the main screenshot file for the theme.
- WP_Theme::display()Gets a theme header, formatted and translated for display.
- WP_Theme::get_theme_root()Returns the absolute path to the directory of the theme root.
- WP_Theme::get_theme_root_uri()Returns the URL to the directory of the theme root.
- WP_Theme::offsetGet()Method to implement ArrayAccess for keys formerly returned by get_themes().
Source code
public function __get( $offset ) { switch ( $offset ) { case 'name': case 'title': return $this->get( 'Name' ); case 'version': return $this->get( 'Version' ); case 'parent_theme': return $this->parent() ? $this->parent()->get( 'Name' ) : ''; case 'template_dir': return $this->get_template_directory(); case 'stylesheet_dir': return $this->get_stylesheet_directory(); case 'template': return $this->get_template(); case 'stylesheet': return $this->get_stylesheet(); case 'screenshot': return $this->get_screenshot( 'relative' ); // 'author' and 'description' did not previously return translated data. case 'description': return $this->display( 'Description' ); case 'author': return $this->display( 'Author' ); case 'tags': return $this->get( 'Tags' ); case 'theme_root': return $this->get_theme_root(); case 'theme_root_uri': return $this->get_theme_root_uri(); // For cases where the array was converted to an object. default: return $this->offsetGet( $offset ); } }Changelog
Introduced in 3.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/class-wp-theme.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.