Changeset 57594
- Timestamp:
- 02/12/2024 01:13:38 PM (7 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r57349 r57594 902 902 } 903 903 904 $hooked_blocks = get_hooked_blocks(); 905 if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { 906 $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template ); 907 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template ); 908 $blocks = parse_blocks( $template->content ); 909 $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 910 } 911 904 912 return $template; 905 913 } -
trunk/tests/phpunit/tests/block-templates/base.php
r54269 r57594 40 40 'post_name' => 'my_template', 41 41 'post_title' => 'My Template', 42 'post_content' => ' Content',42 'post_content' => '<!-- wp:heading {"level":1} --><h1>Template</h1><!-- /wp:heading -->', 43 43 'post_excerpt' => 'Description of my template', 44 44 'tax_input' => array( … … 58 58 'post_name' => 'my_template_part', 59 59 'post_title' => 'My Template Part', 60 'post_content' => ' Content',60 'post_content' => '<!-- wp:heading {"level":2} --><h2>Template Part</h2><!-- /wp:heading -->', 61 61 'post_excerpt' => 'Description of my template part', 62 62 'tax_input' => array( -
trunk/tests/phpunit/tests/block-templates/buildBlockTemplateResultFromPost.php
r56983 r57594 8 8 */ 9 9 class Tests_Block_Templates_BuildBlockTemplateResultFromPost extends WP_Block_Templates_UnitTestCase { 10 11 /** 12 * Tear down each test method. 13 * 14 * @since 6.5.0 15 */ 16 public function tear_down() { 17 $registry = WP_Block_Type_Registry::get_instance(); 18 19 if ( $registry->is_registered( 'tests/my-block' ) ) { 20 $registry->unregister( 'tests/my-block' ); 21 } 22 23 parent::tear_down(); 24 } 10 25 11 26 /** … … 50 65 $this->assertSame( self::$template_part_post->post_modified, $template_part->modified, 'Template part result properties match' ); 51 66 } 67 68 /** 69 * @ticket 59646 70 */ 71 public function test_should_inject_hooked_block_into_template() { 72 register_block_type( 73 'tests/my-block', 74 array( 75 'block_hooks' => array( 76 'core/heading' => 'before', 77 ), 78 ) 79 ); 80 81 $template = _build_block_template_result_from_post( 82 self::$template_post, 83 'wp_template' 84 ); 85 $this->assertStringStartsWith( '<!-- wp:tests/my-block /-->', $template->content ); 86 $this->assertStringContainsString( '"metadata":{"ignoredHookedBlocks":["tests/my-block"]}', $template->content ); 87 } 88 89 /** 90 * @ticket 59646 91 */ 92 public function test_should_inject_hooked_block_into_template_part() { 93 register_block_type( 94 'tests/my-block', 95 array( 96 'block_hooks' => array( 97 'core/heading' => 'after', 98 ), 99 ) 100 ); 101 102 $template_part = _build_block_template_result_from_post( 103 self::$template_part_post, 104 'wp_template_part' 105 ); 106 $this->assertStringEndsWith( '<!-- wp:tests/my-block /-->', $template_part->content ); 107 $this->assertStringContainsString( '"metadata":{"ignoredHookedBlocks":["tests/my-block"]}', $template_part->content ); 108 } 52 109 }
Note: See TracChangeset
for help on using the changeset viewer.