Skip to content

Commit 446a3d5

Browse files
committed
Include script translations only when wp-i18n is set as a dependency
1 parent b60670e commit 446a3d5

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/wp-includes/blocks.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,23 @@ function register_block_script_handle( $metadata, $field_name ) {
100100
);
101101
return false;
102102
}
103-
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC );
104-
$script_uri = $is_core_block ?
103+
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC );
104+
$script_uri = $is_core_block ?
105105
includes_url( str_replace( ABSPATH . WPINC, '', realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ) ) :
106106
plugins_url( $script_path, $metadata['file'] );
107-
$script_asset = require $script_asset_path;
108-
$result = wp_register_script(
107+
$script_asset = require $script_asset_path;
108+
$script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
109+
$result = wp_register_script(
109110
$script_handle,
110111
$script_uri,
111-
isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(),
112+
$script_dependencies,
112113
isset( $script_asset['version'] ) ? $script_asset['version'] : false
113114
);
114115
if ( ! $result ) {
115116
return false;
116117
}
117118

118-
if ( ! empty( $metadata['textdomain'] ) ) {
119+
if ( ! empty( $metadata['textdomain'] ) && in_array( 'wp-i18n', $script_dependencies ) ) {
119120
wp_set_script_translations( $script_handle, $metadata['textdomain'] );
120121
}
121122

0 commit comments

Comments
 (0)