_remove_theme_attribute_in_block_template_content()
Deprecated since 6.4.0. It is no longer supported and may be removed in future releases. Use
traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead.Parses a block template and removes the theme attribute from each template part.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
String. Updated block template content.
Usage
_remove_theme_attribute_in_block_template_content( $template_content );
- $template_content(string) (required)
- Serialized block template content.
Changelog
| Since 5.9.0 | Introduced. |
| Deprecated since 6.4.0 | Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead. |
_remove_theme_attribute_in_block_template_content() remove theme attribute in block template content code WP 6.8.3
function _remove_theme_attribute_in_block_template_content( $template_content ) {
_deprecated_function(
__FUNCTION__,
'6.4.0',
'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_remove_theme_attribute_from_template_part_block" )'
);
$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;
}