_remove_theme_attribute_in_block_template_content
函数
_remove_theme_attribute_in_block_template_content ( $template_content )
- Access
- Private
- 参数
-
-
(string)
$template_content
Serialized block template content.- Required: 是
-
(string)
- 返回值
-
- (string) Updated block template content.
- 定义位置
-
-
wp-includes/block-template-utils.php
, line 465
-
wp-includes/block-template-utils.php
- 引入
- 5.9.0
- 弃用
- –
解析一个区块模板,并从每个模板部分删除主题属性。
function _remove_theme_attribute_in_block_template_content( $template_content ) {
$has_updated_content = false;
$new_content = '';
$template_blocks = parse_blocks( $template_content );
$blocks = _flatten_blocks( $template_blocks );
foreach ( $blocks as $key => $block ) {
if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) {
unset( $blocks[ $key ]['attrs']['theme'] );
$has_updated_content = true;
}
}
if ( ! $has_updated_content ) {
return $template_content;
}
foreach ( $template_blocks as $block ) {
$new_content .= serialize_block( $block );
}
return $new_content;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


