Ensure consistent dependency order when using `wp_add_inline_script()`

This disables the concatenation of remaining enqueued scripts once `wp_add_inline_script()` is invoked, which allows us to reliably print these scripts and their before/after inline scripts in the desired order.

Props gitlost, azaozz, swisspidy, ocean90.
Fixes #36392.

Built from https://develop.svn.wordpress.org/trunk@37171


git-svn-id: http://core.svn.wordpress.org/trunk@37138 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt 2016-04-10 03:33:26 +00:00
parent a70a6c4bae
commit 4d9c9b9433
3 changed files with 8 additions and 24 deletions

View File

@ -92,15 +92,6 @@ class WP_Scripts extends WP_Dependencies {
*/ */
public $print_html = ''; public $print_html = '';
/**
* HTML to print before the script handle.
*
* @since 4.5.0
* @access public
* @var string
*/
public $print_html_before = '';
/** /**
* Holds inline code if concatenation is enabled. * Holds inline code if concatenation is enabled.
* *
@ -304,11 +295,13 @@ class WP_Scripts extends WP_Dependencies {
*/ */
$srce = apply_filters( 'script_loader_src', $src, $handle ); $srce = apply_filters( 'script_loader_src', $src, $handle );
if ( $before_handle && ! $conditional ) { if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle ) ) {
$this->print_html_before .= $before_handle; $this->do_concat = false;
}
if ( $this->in_default_dir( $srce ) && ! $conditional && ! $after_handle ) { // Have to print the so-far concatenated scripts right away to maintain the right order.
_print_scripts();
$this->reset();
} elseif ( $this->in_default_dir( $srce ) && ! $conditional ) {
$this->print_code .= $this->print_extra_script( $handle, false ); $this->print_code .= $this->print_extra_script( $handle, false );
$this->concat .= "$handle,"; $this->concat .= "$handle,";
$this->concat_version .= "$handle$ver"; $this->concat_version .= "$handle$ver";
@ -363,11 +356,7 @@ class WP_Scripts extends WP_Dependencies {
$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src ); $tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
if ( $this->do_concat ) { if ( $this->do_concat ) {
if ( $after_handle ) { $this->print_html .= $tag;
$this->print_html_before .= $tag;
} else {
$this->print_html .= $tag;
}
} else { } else {
echo $tag; echo $tag;
} }
@ -592,7 +581,6 @@ class WP_Scripts extends WP_Dependencies {
$this->concat = ''; $this->concat = '';
$this->concat_version = ''; $this->concat_version = '';
$this->print_html = ''; $this->print_html = '';
$this->print_html_before = '';
$this->ext_version = ''; $this->ext_version = '';
$this->ext_handles = ''; $this->ext_handles = '';
} }

View File

@ -998,10 +998,6 @@ function _print_scripts() {
echo "</script>\n"; echo "</script>\n";
} }
if ( ! empty( $wp_scripts->print_html_before ) ) {
echo $wp_scripts->print_html_before;
}
$concat = str_split( $concat, 128 ); $concat = str_split( $concat, 128 );
$concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat ); $concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.5-RC1-37170'; $wp_version = '4.5-RC1-37171';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.