diff --git a/tests/_data/editor_asset_test.php b/tests/_data/editor_asset_test.php new file mode 100644 index 00000000..59a9b06f --- /dev/null +++ b/tests/_data/editor_asset_test.php @@ -0,0 +1,2 @@ + array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '024bef6fb3a0bc82cb17'); diff --git a/tests/acceptance/ExampleCest.php b/tests/acceptance/ExampleCest.php new file mode 100644 index 00000000..9565da76 --- /dev/null +++ b/tests/acceptance/ExampleCest.php @@ -0,0 +1,8 @@ +amOnPage('/'); + } + +} diff --git a/tests/wpunit/BlockBaseWpUnitTest.php b/tests/wpunit/BlockBaseWpUnitTest.php new file mode 100644 index 00000000..e892006a --- /dev/null +++ b/tests/wpunit/BlockBaseWpUnitTest.php @@ -0,0 +1,38 @@ +get_asset_file_args( get_theme_file_path( "dist/blocks/core/button/editor.asset.php" ) ); + self::assertArrayHasKey( 'version', $args ); + $version = $args['version'] ?? false; + self::assertEquals( '024bef6fb3a0bc82cb17', $version ); + } + + protected function tearDown(): void { + parent::tearDown(); + + $block_dir = get_template_directory() . '/dist/blocks/core/button'; + $editor_asset = $block_dir . '/editor.asset.php'; + + unlink( $editor_asset ); + rmdir( $block_dir ); + } + +} diff --git a/wp-content/plugins/core/src/Blocks/Block_Base.php b/wp-content/plugins/core/src/Blocks/Block_Base.php index 12ee3459..ba73d179 100644 --- a/wp-content/plugins/core/src/Blocks/Block_Base.php +++ b/wp-content/plugins/core/src/Blocks/Block_Base.php @@ -72,6 +72,8 @@ public function register_core_block_variations(): void { public function enqueue_core_block_public_styles(): void { $handle = $this->get_block_style_handle(); $path = $this->get_block_path(); + $args = $this->get_asset_file_args( get_theme_file_path( "dist/blocks/$path/index.asset.php" ) ); + $version = $args['version'] ?? false; $src_path = get_theme_file_path( "dist/blocks/$path/style-index.css" ); $src = get_theme_file_uri( "dist/blocks/$path/style-index.css" ); @@ -79,6 +81,10 @@ public function enqueue_core_block_public_styles(): void { return; } + if ( ! empty( $version ) ) { + $src = $src . '?ver=' . $version; + } + wp_add_inline_style( $handle, file_get_contents( $src_path ) ); add_editor_style( $src ); } @@ -92,6 +98,8 @@ public function enqueue_core_block_public_styles(): void { */ public function enqueue_core_block_editor_styles(): void { $path = $this->get_block_path(); + $args = $this->get_asset_file_args( get_theme_file_path( "dist/blocks/$path/editor.asset.php" ) ); + $version = $args['version'] ?? false; $editor_src_path = get_theme_file_path( "dist/blocks/$path/editor.css" ); $editor_src = get_theme_file_uri( "dist/blocks/$path/editor.css" ); @@ -99,6 +107,10 @@ public function enqueue_core_block_editor_styles(): void { return; } + if ( ! empty( $version ) ) { + $editor_src = $editor_src . '?ver=' . $version; + } + add_editor_style( $editor_src ); }