From 9488d3dc7f31dd905d4532a43e5f220afce39d1f Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Wed, 30 Jun 2021 01:45:10 +0000 Subject: [PATCH] Script Loader: Fix PHP notice caused by the `viewScript` for the `core/file` block. This fixes a PHP notice caused by the `viewScript` for the `core/file` block having `.min.js` instead of just `.js`. `register_block_script_handle()` was incorrectly looking for `view.min.asset.php`, which does not exist, and caused the `_doing_it_wrong()` notice. This adds a check for `.min.js` in the `viewScript` field of `block.json` and corrects it to `.js` in order to match the expected pattern of `view.asset.php` until a more permanent fix can be created. Follow up to [51259]. Props ipstenu, pbiron, peterwilsoncc. See #53397. git-svn-id: https://develop.svn.wordpress.org/trunk@51267 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 905cb48b37..1d3c123ca8 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -82,7 +82,12 @@ function register_block_script_handle( $metadata, $field_name ) { return $script_handle; } - $script_handle = generate_block_asset_handle( $metadata['name'], $field_name ); + $script_handle = generate_block_asset_handle( $metadata['name'], $field_name ); + + if ( 'viewScript' === $field_name ) { + $script_path = str_replace( '.min.js', '.js', $script_path ); + } + $script_asset_path = realpath( dirname( $metadata['file'] ) . '/' . substr_replace( $script_path, '.asset.php', - strlen( '.js' ) )