BlockTemplateUtilsDuplicated::gutenberg_inject_theme_attribute_in_content()
Parses wp_template content and injects the current theme's stylesheet as a theme attribute into each wp_template_part
Метод класса: BlockTemplateUtilsDuplicated{}
Хуков нет.
Возвращает
Строку
. Updated wp_template content.
Использование
$result = BlockTemplateUtilsDuplicated::gutenberg_inject_theme_attribute_in_content( $template_content );
- $template_content(строка) (обязательный)
- serialized wp_template content.
Код BlockTemplateUtilsDuplicated::gutenberg_inject_theme_attribute_in_content() BlockTemplateUtilsDuplicated::gutenberg inject theme attribute in content WC 9.6.1
public static function gutenberg_inject_theme_attribute_in_content( $template_content ) { $has_updated_content = false; $new_content = ''; $template_blocks = parse_blocks( $template_content ); $blocks = self::gutenberg_flatten_blocks( $template_blocks ); foreach ( $blocks as &$block ) { if ( 'core/template-part' === $block['blockName'] && ! isset( $block['attrs']['theme'] ) ) { $block['attrs']['theme'] = wp_get_theme()->get_stylesheet(); $has_updated_content = true; } } if ( $has_updated_content ) { foreach ( $template_blocks as &$block ) { $new_content .= serialize_block( $block ); } return $new_content; } return $template_content; }