WP_Block_Patterns_Registry::get_content( string $pattern_name, bool $outside_init_only = false ): string
- Since
- 6.5.0
- Source
wp-includes/class-wp-block-patterns-registry.php:170
Compatibility
- WordPress
- since 6.5.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
$pattern_namestring- Block pattern name including namespace.
$outside_init_onlybooloptional- Return only patterns registered outside the
initaction. Default false.Default:false
Return value
string- The content of the block pattern.
Performance profile
How much work a call to WP_Block_Patterns_Registry::get_content() 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
- Heavy
- Scaling
- Constant
- Instructions
- 21–67
- Plugin surface
- None
- Called by
- 2
Reads or writes the filesystem via is_file().
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 70.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- filesystemfilesystem access
is_file()called directly
What one call costs · 32 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Block_Patterns_Registry::get_content() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 21–27 | none |
| always | 26–32 | realpath() |
!is_string($file_path) && is_object($file_path) | 28–32 | method_exists() |
!isset($value) && is_string($pattern_path) && str_ends_with() && !is_file() | 32–36 | str_ends_with(), is_file() |
!isset($value) && is_string($pattern_path) && !str_ends_with() | 33–37 | str_ends_with(), str_ends_with() |
!is_string($file_path) && is_object($file_path) | 33–37 | method_exists(), realpath() |
!isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && !is_readable() | 36–40 | str_ends_with(), is_file(), is_readable() |
!isset($value) && is_string($pattern_path) && !is_file() | 37–41 | str_ends_with(), str_ends_with(), is_file() |
!isset($value) && is_string($pattern_path) && str_ends_with() && !is_file() | 37–41 | realpath(), str_ends_with(), is_file() |
!isset($value) && is_string($pattern_path) && !str_ends_with() | 38–42 | realpath(), str_ends_with(), str_ends_with() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && str_ends_with() && !is_file() | 39–41 | method_exists(), str_ends_with(), is_file() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && !str_ends_with() | 40–42 | method_exists(), str_ends_with(), str_ends_with() |
20 further outcomes, up to 67 instructions
!isset($value) && is_string($pattern_path) && is_file() && !is_readable() | 41–45 | str_ends_with(), str_ends_with(), is_file(), is_readable() |
!isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && !is_readable() | 41–45 | realpath(), str_ends_with(), is_file(), is_readable() |
!isset($value) && is_string($pattern_path) && !is_file() | 42–46 | realpath(), str_ends_with(), str_ends_with(), is_file() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && !is_readable() | 43–45 | method_exists(), str_ends_with(), is_file(), is_readable() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && !is_file() | 44–46 | method_exists(), str_ends_with(), str_ends_with(), is_file() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && str_ends_with() && !is_file() | 44–46 | method_exists(), realpath(), str_ends_with(), is_file() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && !str_ends_with() | 45–47 | method_exists(), realpath(), str_ends_with(), str_ends_with() |
!isset($value) && is_string($pattern_path) && is_file() && !is_readable() | 46–50 | realpath(), str_ends_with(), str_ends_with(), is_file(), is_readable() |
!isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && is_readable() | 48–52 | str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && is_file() && !is_readable() | 48–50 | method_exists(), str_ends_with(), str_ends_with(), is_file(), is_readable() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && !is_readable() | 48–50 | method_exists(), realpath(), str_ends_with(), is_file(), is_readable() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && !is_file() | 49–51 | method_exists(), realpath(), str_ends_with(), str_ends_with(), is_file() |
!isset($value) && is_string($pattern_path) && is_file() && is_readable() | 53–57 | str_ends_with(), str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
!isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && is_readable() | 53–57 | realpath(), str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && is_file() && !is_readable() | 53–55 | method_exists(), realpath(), str_ends_with(), str_ends_with(), is_file(), is_readable() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && is_readable() | 55–57 | method_exists(), str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
!isset($value) && is_string($pattern_path) && is_file() && is_readable() | 58–62 | realpath(), str_ends_with(), str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && is_file() && is_readable() | 60–62 | method_exists(), str_ends_with(), str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && str_ends_with() && is_file() && is_readable() | 60–62 | method_exists(), realpath(), str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
!is_string($file_path) && is_object($file_path) && !isset($value) && is_string($pattern_path) && is_file() && is_readable() | 65–67 | method_exists(), realpath(), str_ends_with(), str_ends_with(), is_file(), is_readable(), ob_start(), ob_get_clean() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 69 | 21–66 | 11 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 70 | 21–67 | 11 | |
| 8.4 | 70 | 21–67 | 11 | |
| 8.3 | 70 | 21–67 | 11 | |
| 8.2 | 70 | 21–67 | 11 | |
| 8.1 | 70 | 21–67 | 11 | |
| 7.4 | 70 | 21–67 | 11 |
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 · 1
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
Used by · 2
- WP_Block_Patterns_Registry::get_all_registered()Retrieves all registered block patterns.
- WP_Block_Patterns_Registry::get_registered()Retrieves an array containing the properties of a registered block pattern.
Source code
private function get_content( $pattern_name, $outside_init_only = false ) { if ( $outside_init_only ) { $patterns = &$this->registered_patterns_outside_init; } else { $patterns = &$this->registered_patterns; } $file_path = $patterns[ $pattern_name ]['filePath'] ?? ''; $is_stringy = is_string( $file_path ) || ( is_object( $file_path ) && method_exists( $file_path, '__toString' ) ); $pattern_path = $is_stringy ? realpath( (string) $file_path ) : null; if ( ! isset( $patterns[ $pattern_name ]['content'] ) && is_string( $pattern_path ) && ( str_ends_with( $pattern_path, '.php' ) || str_ends_with( $pattern_path, '.html' ) ) && is_file( $pattern_path ) && is_readable( $pattern_path ) ) { ob_start(); include $patterns[ $pattern_name ]['filePath']; $patterns[ $pattern_name ]['content'] = ob_get_clean(); unset( $patterns[ $pattern_name ]['filePath'] ); } return $patterns[ $pattern_name ]['content']; }Changelog
Introduced in 6.5.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.1.0 tag, from
src/wp-includes/class-wp-block-patterns-registry.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.