Skip to content

Commit 2089f54

Browse files
committed
Refactor code based on the review feedback
Props to @ockham.
1 parent d70619c commit 2089f54

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

src/wp-includes/class-wp-block-type.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,20 +522,6 @@ public function set_props( $args ) {
522522
$args = apply_filters( 'register_block_type_args', $args, $this->name );
523523

524524
foreach ( $args as $property_name => $property_value ) {
525-
// Avoid infinite recursion in block hooks (hooking to itself).
526-
if ( 'block_hooks' === $property_name ) {
527-
if ( ! is_array( $property_value ) ) {
528-
continue;
529-
}
530-
if ( array_key_exists( $this->name, $property_value ) ) {
531-
_doing_it_wrong(
532-
__METHOD__,
533-
__( 'Cannot hook block to itself.' ),
534-
'6.4.0'
535-
);
536-
unset( $property_value[ $this->name ] );
537-
}
538-
}
539525
$this->$property_name = $property_value;
540526
}
541527
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "tests/hooked-block-error",
3+
"description": "A block that throws an error because it tries to hook a block to itself.",
4+
"blockHooks": {
5+
"tests/hooked-block-error": "before",
6+
"tests/other-block": "after"
7+
}
8+
}

tests/phpunit/tests/blocks/register.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,22 +1080,15 @@ public function test_register_block_style_name_without_spaces() {
10801080
*
10811081
* @covers ::register_block_type
10821082
*
1083-
* @expectedIncorrectUsage WP_Block_Type::set_props
1083+
* @expectedIncorrectUsage register_block_type_from_metadata
10841084
*/
10851085
public function test_register_block_hooks_targeting_itself() {
1086-
$block_name = 'tests/block-name';
10871086
$block_type = register_block_type(
1088-
$block_name,
1089-
array(
1090-
'block_hooks' => array(
1091-
$block_name => 'first',
1092-
'tests/other-block' => 'last',
1093-
),
1094-
)
1087+
DIR_TESTDATA . '/blocks/hooked-block-error'
10951088
);
10961089

1097-
$this->assertSameSets(
1098-
array( 'tests/other-block' => 'last' ),
1090+
$this->assertSame(
1091+
array( 'tests/other-block' => 'after' ),
10991092
$block_type->block_hooks
11001093
);
11011094
}

0 commit comments

Comments
 (0)