WP_Block_Patterns_Registry::get_content
Retrieves the content of a registered block pattern.
Method of the class: WP_Block_Patterns_Registry{}
No Hooks.
Returns
String. The content of the block pattern.
Usage
// private - for code of main (parent) class only $result = $this->get_content( $pattern_name, $outside_init_only );
- $pattern_name(string) (required)
- Block pattern name including namespace.
- $outside_init_only(true|false)
- Return only patterns registered outside the
initaction.
Default:false
Changelog
| Since 6.5.0 | Introduced. |
WP_Block_Patterns_Registry::get_content() WP Block Patterns Registry::get content code WP 7.0.4
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'];
}