Changeset 56724 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 09/26/2023 04:59:11 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r56722 r56724 491 491 492 492 /** 493 * Parses a block template and removes the theme attribute from each template part.494 * 495 * @since 5.9.0493 * Removes the `theme` attribute from a given template part block. 494 * 495 * @since 6.4.0 496 496 * @access private 497 497 * 498 * @param string $template_content Serialized block template content. 499 * @return string Updated block template content. 500 */ 501 function _remove_theme_attribute_in_block_template_content( $template_content ) { 502 $has_updated_content = false; 503 $new_content = ''; 504 $template_blocks = parse_blocks( $template_content ); 505 506 $blocks = _flatten_blocks( $template_blocks ); 507 foreach ( $blocks as $key => $block ) { 508 if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) { 509 unset( $blocks[ $key ]['attrs']['theme'] ); 510 $has_updated_content = true; 511 } 512 } 513 514 if ( ! $has_updated_content ) { 515 return $template_content; 516 } 517 518 foreach ( $template_blocks as $block ) { 519 $new_content .= serialize_block( $block ); 520 } 521 522 return $new_content; 498 * @param array $block a parsed block. 499 * @return void 500 */ 501 function _remove_theme_attribute_from_template_part_block( &$block ) { 502 if ( 503 'core/template-part' === $block['blockName'] && 504 isset( $block['attrs']['theme'] ) 505 ) { 506 unset( $block['attrs']['theme'] ); 507 } 523 508 } 524 509 … … 1279 1264 $templates = get_block_templates(); 1280 1265 foreach ( $templates as $template ) { 1281 $template->content = _remove_theme_attribute_in_block_template_content( $template->content ); 1266 $template->content = traverse_and_serialize_blocks( 1267 parse_blocks( $template->content ), 1268 '_remove_theme_attribute_from_template_part_block' 1269 ); 1282 1270 1283 1271 $zip->addFromString(
Note: See TracChangeset
for help on using the changeset viewer.