Skip to content

Commit

Permalink
Unset block instance's variations field
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jun 18, 2024
1 parent 6821538 commit 72a0384
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
$variations = require $variations_path;
return $variations;
};
// The block instance's `variations` field is only allowed to be an array
// (of known block variations). We unset it so that the block instance will
// provide a getter that returns the result of the `variation_callback` instead.
unset( $settings['variations'] );
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,15 +977,15 @@ public function test_register_block_type_from_metadata_with_variations_php_file(
remove_filter( 'block_type_metadata', $filter_metadata_registration );

$this->assertInstanceOf( 'WP_Block_Type', $result, 'The block was not registered' );
$this->assertSame( 'variations.php', $result->variations, 'The block variations are incorrect' );
$this->assertIsCallable( $result->variation_callback, 'The variation callback hasn\'t been set' );

$this->assertIsCallable( $result->variation_callback, 'The variation callback hasn\'t been set' );
$expected_variations = require DIR_TESTDATA . '/blocks/notice/variations.php';
$this->assertSame(
$expected_variations,
call_user_func( $result->variation_callback ),
'The variation callback hasn\'t been set correctly'
);
$this->assertSame( $expected_variations, $result->variations, 'The block variations are incorrect' );
}

/**
Expand Down

0 comments on commit 72a0384

Please sign in to comment.