Retrieves the content of a registered block pattern.
Parameters
$pattern_namestringrequired- Block pattern name including namespace.
$outside_init_onlybooloptional- Return only patterns registered outside the
initaction.Default:
false
Source
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
| Version | Description |
|---|---|
| 6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.