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
This commit is contained in:
Jonathan Desrosiers
2021-06-30 01:45:10 +00:00
parent 2a02de7d53
commit 9488d3dc7f

View File

@@ -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' ) )