From 4d9c9b9433c68c1ee2f1f08c0498df03efdf4a23 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Sun, 10 Apr 2016 03:33:26 +0000 Subject: [PATCH] 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 --- wp-includes/class.wp-scripts.php | 26 +++++++------------------- wp-includes/script-loader.php | 4 ---- wp-includes/version.php | 2 +- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php index ce5469e543..144bfce220 100644 --- a/wp-includes/class.wp-scripts.php +++ b/wp-includes/class.wp-scripts.php @@ -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 = ''; } diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index ab02bfd2eb..66080a835b 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -998,10 +998,6 @@ function _print_scripts() { echo "\n"; } - if ( ! empty( $wp_scripts->print_html_before ) ) { - echo $wp_scripts->print_html_before; - } - $concat = str_split( $concat, 128 ); $concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat ); diff --git a/wp-includes/version.php b/wp-includes/version.php index b20973bdf7..978fa0fd5e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @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.