mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Script Loader: Fix i18n edge case breaking dependencies.
Prevent concatenation of scripts if the text domain is defined to ensure the dependency order is respected. This accounts for an edge case in which replacing a core script via a plugin and a lack of translations (eg, for a US English site) could cause the JavaScript files to be ordered incorrectly. Follow up to [52937]. Props audrasjb, boniu91, chaion07, costdev, hellofromtonya, jsnajdr, mukesh27, ndiego, ugyensupport. Fixes #55628. git-svn-id: https://develop.svn.wordpress.org/trunk@53360 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -311,6 +311,8 @@ class WP_Scripts extends WP_Dependencies {
|
||||
$inline_script_tag = '';
|
||||
}
|
||||
|
||||
$translations_stop_concat = ! empty( $obj->textdomain );
|
||||
|
||||
$translations = $this->print_translations( $handle, false );
|
||||
if ( $translations ) {
|
||||
$translations = sprintf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $translations );
|
||||
@@ -327,7 +329,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
*/
|
||||
$srce = apply_filters( 'script_loader_src', $src, $handle );
|
||||
|
||||
if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle || $translations ) ) {
|
||||
if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle || $translations_stop_concat ) ) {
|
||||
$this->do_concat = false;
|
||||
|
||||
// Have to print the so-far concatenated scripts right away to maintain the right order.
|
||||
|
||||
@@ -1481,4 +1481,38 @@ JS;
|
||||
array( false, '[""]' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 55628
|
||||
* @covers ::wp_set_script_translations
|
||||
*/
|
||||
public function test_wp_external_wp_i18n_print_order() {
|
||||
global $wp_scripts;
|
||||
|
||||
$wp_scripts->do_concat = true;
|
||||
$wp_scripts->default_dirs = array( '/default/' );
|
||||
|
||||
// wp-i18n script in a non-default directory.
|
||||
wp_register_script( 'wp-i18n', '/plugins/wp-i18n.js', array(), null );
|
||||
// Script in default dir that's going to be concatenated.
|
||||
wp_enqueue_script( 'jquery-core', '/default/jquery-core.js', array(), null );
|
||||
// Script in default dir that depends on wp-i18n.
|
||||
wp_enqueue_script( 'common', '/default/common.js', array(), null );
|
||||
wp_set_script_translations( 'common' );
|
||||
|
||||
$print_scripts = get_echo(
|
||||
function() {
|
||||
wp_print_scripts();
|
||||
_print_scripts();
|
||||
}
|
||||
);
|
||||
|
||||
// The non-default script should end concatenation and maintain order.
|
||||
$ver = get_bloginfo( 'version' );
|
||||
$expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core&ver={$ver}'></script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/plugins/wp-i18n.js' id='wp-i18n-js'></script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/default/common.js' id='common-js'></script>\n";
|
||||
|
||||
$this->assertSame( $expected, $print_scripts );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user