Skip to content

Commit

Permalink
Move _remove_theme_attribute_in_block_template_content to deprecated.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Sep 26, 2023
1 parent 4021517 commit 66afb4f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
40 changes: 0 additions & 40 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,46 +489,6 @@ function _inject_theme_attribute_in_template_part_block( &$block ) {
}
}

/**
* Parses a block template and removes the theme attribute from each template part.
*
* @since 5.9.0
* @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead.
* @access private
*
* @param string $template_content Serialized block template content.
* @return string Updated block template content.
*/
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;
}

/**
* Removes the `theme` attribute from a given template part block.
*
Expand Down
40 changes: 40 additions & 0 deletions src/wp-includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6084,3 +6084,43 @@ function _inject_theme_attribute_in_block_template_content( $template_content )

return $template_content;
}

/**
* Parses a block template and removes the theme attribute from each template part.
*
* @since 5.9.0
* @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead.
* @access private
*
* @param string $template_content Serialized block template content.
* @return string Updated block template content.
*/
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;
}

0 comments on commit 66afb4f

Please sign in to comment.