diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index 6ad8ebcd6790e..052db4b11ccf2 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -334,9 +334,10 @@ public function __construct( $block_type, $args = array() ) { * @return string|string[]|null|void The value read from the new property if the first item in the array provided, * null when value not found, or void when unknown property name provided. */ - public function __get( $name ) { + public function &__get( $name ) { if ( 'variations' === $name ) { - return $this->get_variations(); + $this->variations = $this->get_variations(); + return $this->variations; } if ( ! in_array( $name, $this->deprecated_properties, true ) ) { diff --git a/tests/phpunit/tests/blocks/wpBlockType.php b/tests/phpunit/tests/blocks/wpBlockType.php index b826faf575946..1680e403c5096 100644 --- a/tests/phpunit/tests/blocks/wpBlockType.php +++ b/tests/phpunit/tests/blocks/wpBlockType.php @@ -641,6 +641,20 @@ public function test_get_block_type_variations_filter_variations() { $this->assertSameSets( $obtained_variations, $expected_variations, 'The variations that was initially set should be filtered.' ); } + /** + * @ticket 60309 + */ + public function test_can_access_original_varations_variable() { + $block_type = new WP_Block_Type( + 'test/block', + array( + 'title' => 'Test title', + ) + ); + $block_type->variations[] = array( 'name' => 'var1' ); + $this->assertSameSets( array( array( 'name' => 'var1' ) ), $block_type->variations ); + } + /** * Mock variation callback. *