WP_Theme::offsetGet( mixed $offset ): mixed
- Since
- 3.4.0
- Source
wp-includes/class-wp-theme.php:698
Description
Author, Author Name, Author URI, and Description did not previously return translated data. We are doing so now as it is safe to do. However, as Name and Title could have been used as the key for get_themes(), both remain untranslated for back compatibility. This means that ['Name'] is not ideal, and care should be taken to use $theme::display( 'Name' ) to get a properly translated header.
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
$offsetmixed
Return value
mixed
Performance profile
How much work a call to WP_Theme::offsetGet() 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
- 3–49
- Plugin surface
- None
- Called by
- 1
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 115.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 13 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme::offsetGet() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 3–41 | none |
| always | 5–23 | ->get_template() |
| always | 5–25 | ->get_stylesheet() |
| always | 5–31 | ->get_template_directory() |
| always | 5–33 | ->get_stylesheet_directory() |
| always | 5–39 | ->get_theme_root() |
| always | 5–41 | ->get_theme_root_uri() |
| always | 6–38 | ->get() |
| always | 6–18 | ->display() |
| always | 6–36 | ->get_screenshot() |
!->parent() | 6–44 | ->parent() |
| always | 8–32 | ->get_files() |
1 further outcome, up to 49 instructions
->parent() | 11–49 | ->parent(), ->parent(), ->get() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 115 | 3–49 | 21 | |
| 8.5 | 115 | 3–49 | 21 | |
| 8.4 | 115 | 3–49 | 21 | |
| 8.3 | 115 | 3–49 | 21 | |
| 8.2 | 115 | 3–49 | 21 | |
| 8.1 | 115 | 3–49 | 21 | 1 more instruction than PHP 7.4 |
| 7.4 | 114 | 3–49 | 21 |
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::display()Gets a theme header, formatted and translated for display.
- 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_files()Returns files in the theme's directory.
- 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_screenshot()Returns the main screenshot file for the theme.
- 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::parent()Returns reference to the parent theme.
Used by · 1
- WP_Theme::__get()__get() magic method for properties formerly returned by current_theme_info()
Source code
#[ReturnTypeWillChange] public function offsetGet( $offset ) { switch ( $offset ) { case 'Name': case 'Title': /* * See note above about using translated data. get() is not ideal. * It is only for backward compatibility. Use display(). */ return $this->get( 'Name' ); case 'Author': return $this->display( 'Author' ); case 'Author Name': return $this->display( 'Author', false ); case 'Author URI': return $this->display( 'AuthorURI' ); case 'Description': return $this->display( 'Description' ); case 'Version': case 'Status': return $this->get( $offset ); case 'Template': return $this->get_template(); case 'Stylesheet': return $this->get_stylesheet(); case 'Template Files': return $this->get_files( 'php', 1, true ); case 'Stylesheet Files': return $this->get_files( 'css', 0, false ); case 'Template Dir': return $this->get_template_directory(); case 'Stylesheet Dir': return $this->get_stylesheet_directory(); case 'Screenshot': return $this->get_screenshot( 'relative' ); case 'Tags': return $this->get( 'Tags' ); case 'Theme Root': return $this->get_theme_root(); case 'Theme Root URI': return $this->get_theme_root_uri(); case 'Parent Theme': return $this->parent() ? $this->parent()->get( 'Name' ) : ''; default: return null; } }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.