Changeset 60173
- Timestamp:
- 04/18/2025 12:55:40 PM (4 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r59938 r60173 1249 1249 ); 1250 1250 1251 /* 1252 * We need to avoid inserting any blocks hooked into the `before` and `after` positions 1253 * of the temporary wrapper block that we create to wrap the content. 1254 * See https://core.trac.wordpress.org/ticket/63287 for more details. 1255 */ 1256 $suppress_blocks_from_insertion_before_and_after_wrapper_block = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( $wrapper_block_type ) { 1257 if ( 1258 $wrapper_block_type === $anchor_block_type && 1259 in_array( $relative_position, array( 'before', 'after' ), true ) 1260 ) { 1261 return array(); 1262 } 1263 return $hooked_block_types; 1264 }; 1265 1251 1266 // Apply Block Hooks. 1267 add_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX, 3 ); 1252 1268 $content = apply_block_hooks_to_content( $content, $post, $callback ); 1269 remove_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX ); 1253 1270 1254 1271 // Finally, we need to remove the temporary wrapper block. -
trunk/tests/phpunit/tests/blocks/applyBlockHooksToContent.php
r59523 r60173 18 18 * 19 19 * @ticket 61902. 20 * @ticket 63287. 20 21 */ 21 22 public static function wpSetUpBeforeClass() { … … 24 25 array( 25 26 'block_hooks' => array( 26 ' tests/anchor-block' => 'after',27 'core/post-content' => 'after', 27 28 ), 28 29 ) … … 80 81 /** 81 82 * @ticket 61902 83 * @ticket 63287 82 84 */ 83 85 public function test_apply_block_hooks_to_content_inserts_hooked_block() { 84 86 $context = new WP_Block_Template(); 85 $context->content = '<!-- wp: tests/anchor-block/-->';87 $context->content = '<!-- wp:post-content /-->'; 86 88 87 89 $actual = apply_block_hooks_to_content( $context->content, $context, 'insert_hooked_blocks' ); 88 90 $this->assertSame( 89 '<!-- wp: tests/anchor-block/--><!-- wp:tests/hooked-block /-->',91 '<!-- wp:post-content /--><!-- wp:tests/hooked-block /-->', 90 92 $actual 91 93 ); … … 94 96 /** 95 97 * @ticket 61074 98 * @ticket 63287 96 99 */ 97 100 public function test_apply_block_hooks_to_content_with_context_set_to_null() { 98 $content = '<!-- wp: tests/anchor-block/-->';101 $content = '<!-- wp:post-content /-->'; 99 102 100 103 /* … … 107 110 $actual = apply_block_hooks_to_content( $content, null, 'insert_hooked_blocks' ); 108 111 $this->assertSame( 109 '<!-- wp: tests/anchor-block/--><!-- wp:tests/hooked-block /-->',112 '<!-- wp:post-content /--><!-- wp:tests/hooked-block /-->', 110 113 $actual 111 114 ); -
trunk/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php
r59838 r60173 89 89 ) 90 90 ); 91 92 register_block_type( 93 'tests/hooked-block-after-post-content', 94 array( 95 'block_hooks' => array( 96 'core/post-content' => 'after', 97 ), 98 ) 99 ); 100 101 register_block_type( 'tests/dynamically-hooked-block-before-post-content' ); 91 102 } 92 103 … … 101 112 $registry->unregister( 'tests/hooked-block' ); 102 113 $registry->unregister( 'tests/hooked-block-first-child' ); 114 $registry->unregister( 'tests/hooked-block-after-post-content' ); 115 $registry->unregister( 'tests/dynamically-hooked-block-before-post-content' ); 103 116 } 104 117 … … 132 145 133 146 /** 147 * @ticket 63287 148 */ 149 public function test_apply_block_hooks_to_content_from_post_object_does_not_insert_hooked_block_before_container_block() { 150 $filter = function ( $hooked_block_types, $relative_position, $anchor_block_type ) { 151 if ( 'core/post-content' === $anchor_block_type && 'before' === $relative_position ) { 152 $hooked_block_types[] = 'tests/dynamically-hooked-block-before-post-content'; 153 } 154 155 return $hooked_block_types; 156 }; 157 158 $expected = '<!-- wp:tests/hooked-block-first-child /-->' . 159 self::$post->post_content . 160 '<!-- wp:tests/hooked-block /-->'; 161 162 add_filter( 'hooked_block_types', $filter, 10, 3 ); 163 $actual = apply_block_hooks_to_content_from_post_object( 164 self::$post->post_content, 165 self::$post, 166 'insert_hooked_blocks' 167 ); 168 remove_filter( 'hooked_block_types', $filter, 10 ); 169 170 $this->assertSame( $expected, $actual ); 171 } 172 173 /** 134 174 * @ticket 62716 135 175 */
Note: See TracChangeset
for help on using the changeset viewer.