WP_Block_Patterns_Registry::get_content
Retrieves the content of a registered block pattern.
Метод класса: WP_Block_Patterns_Registry{}
Хуков нет.
Возвращает
string. The content of the block pattern.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_content( $pattern_name, $outside_init_only );
- $pattern_name(строка) (обязательный)
- Block pattern name including namespace.
- $outside_init_only(true|false)
- Return only patterns registered outside the
initaction.
По умолчанию:false
Список изменений
| С версии 6.5.0 | Введена. |
Код WP_Block_Patterns_Registry::get_content() WP Block Patterns Registry::get content WP 7.1.2
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'];
}