_remove_theme_attribute_in_block_template_content() – Parses a block template and removes the theme attribute from each template part.

You appear to be a bot. Output may be restricted

Description

Parses a block template and removes the theme attribute from each template part.

Usage

$string = _remove_theme_attribute_in_block_template_content( $template_content );

Parameters

$template_content
( string ) required – Serialized block template content.

Returns

string Updated block template content.

Source

File name: wordpress/wp-includes/block-template-utils.php
Lines:

1 to 23 of 23
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;
}
 

 View on GitHub View on Trac