Editor: Avoid a JS console error on the Navigation block view.

Props mkaz, sabernhardt, costdev.
Fixes #54456.


git-svn-id: https://develop.svn.wordpress.org/trunk@52291 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras 2021-11-30 20:00:09 +00:00
parent d418ae6c93
commit d9dc716cff

View File

@ -83,9 +83,11 @@ function register_block_script_handle( $metadata, $field_name ) {
}
$script_handle = generate_block_asset_handle( $metadata['name'], $field_name );
$script_asset_path = realpath(
dirname( $metadata['file'] ) . '/' .
substr_replace( $script_path, '.asset.php', - strlen( '.js' ) )
$script_asset_path = wp_normalize_path(
realpath(
dirname( $metadata['file'] ) . '/' .
substr_replace( $script_path, '.asset.php', - strlen( '.js' ) )
)
);
if ( ! file_exists( $script_asset_path ) ) {
_doing_it_wrong(
@ -100,9 +102,13 @@ function register_block_script_handle( $metadata, $field_name ) {
);
return false;
}
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC );
// Path needs to be normalized to work in Windows env.
$wpinc_path_norm = wp_normalize_path( ABSPATH . WPINC );
$script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) );
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
$script_uri = $is_core_block ?
includes_url( str_replace( ABSPATH . WPINC, '', realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ) ) :
includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ) :
plugins_url( $script_path, $metadata['file'] );
$script_asset = require $script_asset_path;
$script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
@ -139,7 +145,8 @@ function register_block_style_handle( $metadata, $field_name ) {
if ( empty( $metadata[ $field_name ] ) ) {
return false;
}
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC );
$wpinc_path_norm = wp_normalize_path( ABSPATH . WPINC );
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) {
return false;
}
@ -232,7 +239,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
if ( ! is_array( $metadata ) || empty( $metadata['name'] ) ) {
return false;
}
$metadata['file'] = $metadata_file;
$metadata['file'] = wp_normalize_path( $metadata_file );
/**
* Filters the metadata provided for registering a block type.