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.


git-svn-id: https://develop.svn.wordpress.org/trunk@37171 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt
2016-04-10 03:32:47 +00:00
parent fc1f8db19a
commit f98744ec86
3 changed files with 226 additions and 38 deletions

View File

@@ -92,15 +92,6 @@ class WP_Scripts extends WP_Dependencies {
*/
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.
*
@@ -304,11 +295,13 @@ class WP_Scripts extends WP_Dependencies {
*/
$srce = apply_filters( 'script_loader_src', $src, $handle );
if ( $before_handle && ! $conditional ) {
$this->print_html_before .= $before_handle;
}
if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_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->concat .= "$handle,";
$this->concat_version .= "$handle$ver";
@@ -363,11 +356,7 @@ class WP_Scripts extends WP_Dependencies {
$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
if ( $this->do_concat ) {
if ( $after_handle ) {
$this->print_html_before .= $tag;
} else {
$this->print_html .= $tag;
}
$this->print_html .= $tag;
} else {
echo $tag;
}
@@ -592,7 +581,6 @@ class WP_Scripts extends WP_Dependencies {
$this->concat = '';
$this->concat_version = '';
$this->print_html = '';
$this->print_html_before = '';
$this->ext_version = '';
$this->ext_handles = '';
}