Changeset 56724
- Timestamp:
- 09/26/2023 04:59:11 PM (12 months ago)
- Location:
- trunk
- Files:
-
- 3 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( -
trunk/src/wp-includes/deprecated.php
r56722 r56724 6085 6085 return $template_content; 6086 6086 } 6087 6088 /** 6089 * Parses a block template and removes the theme attribute from each template part. 6090 * 6091 * @since 5.9.0 6092 * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead. 6093 * @access private 6094 * 6095 * @param string $template_content Serialized block template content. 6096 * @return string Updated block template content. 6097 */ 6098 function _remove_theme_attribute_in_block_template_content( $template_content ) { 6099 _deprecated_function( 6100 __FUNCTION__, 6101 '6.4.0', 6102 'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_remove_theme_attribute_from_template_part_block" )' 6103 ); 6104 6105 $has_updated_content = false; 6106 $new_content = ''; 6107 $template_blocks = parse_blocks( $template_content ); 6108 6109 $blocks = _flatten_blocks( $template_blocks ); 6110 foreach ( $blocks as $key => $block ) { 6111 if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) { 6112 unset( $blocks[ $key ]['attrs']['theme'] ); 6113 $has_updated_content = true; 6114 } 6115 } 6116 6117 if ( ! $has_updated_content ) { 6118 return $template_content; 6119 } 6120 6121 foreach ( $template_blocks as $block ) { 6122 $new_content .= serialize_block( $block ); 6123 } 6124 6125 return $new_content; 6126 } -
trunk/tests/phpunit/tests/block-template-utils.php
r56719 r56724 362 362 /** 363 363 * @ticket 54448 364 * @ticket 59460 364 365 * 365 366 * @dataProvider data_remove_theme_attribute_in_block_template_content 367 * 368 * @expectedDeprecated _remove_theme_attribute_in_block_template_content 366 369 */ 367 370 public function test_remove_theme_attribute_in_block_template_content( $template_content, $expected ) { 368 371 $this->assertSame( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) ); 372 } 373 374 /** 375 * @ticket 59460 376 * 377 * @covers ::_remove_theme_attribute_from_template_part_block 378 * @covers ::traverse_and_serialize_blocks 379 * 380 * @dataProvider data_remove_theme_attribute_in_block_template_content 381 * 382 * @param string $template_content The template markup. 383 * @param string $expected The expected markup after removing the theme attribute from Template Part blocks. 384 */ 385 public function test_remove_theme_attribute_from_template_part_block( $template_content, $expected ) { 386 $template_content_parsed_blocks = parse_blocks( $template_content ); 387 388 $this->assertSame( 389 $expected, 390 traverse_and_serialize_blocks( 391 $template_content_parsed_blocks, 392 '_remove_theme_attribute_from_template_part_block' 393 ) 394 ); 369 395 } 370 396
Note: See TracChangeset
for help on using the changeset viewer.