WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/10/2016 03:32:47 AM (6 years ago)
Author:
jeremyfelt
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-scripts.php

    r36917 r37171  
    9292     */
    9393    public $print_html = '';
    94 
    95     /**
    96      * HTML to print before the script handle.
    97      *
    98      * @since 4.5.0
    99      * @access public
    100      * @var string
    101      */
    102     public $print_html_before = '';
    10394
    10495    /**
     
    305296            $srce = apply_filters( 'script_loader_src', $src, $handle );
    306297
    307             if ( $before_handle && ! $conditional ) {
    308                 $this->print_html_before .= $before_handle;
    309             }
    310 
    311             if ( $this->in_default_dir( $srce ) && ! $conditional && ! $after_handle ) {
     298            if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle ) ) {
     299                $this->do_concat = false;
     300
     301                // Have to print the so-far concatenated scripts right away to maintain the right order.
     302                _print_scripts();
     303                $this->reset();
     304            } elseif ( $this->in_default_dir( $srce ) && ! $conditional ) {
    312305                $this->print_code .= $this->print_extra_script( $handle, false );
    313306                $this->concat .= "$handle,";
     
    364357
    365358        if ( $this->do_concat ) {
    366             if ( $after_handle ) {
    367                 $this->print_html_before .= $tag;
    368             } else {
    369                 $this->print_html .= $tag;
    370             }
     359            $this->print_html .= $tag;
    371360        } else {
    372361            echo $tag;
     
    593582        $this->concat_version = '';
    594583        $this->print_html = '';
    595         $this->print_html_before = '';
    596584        $this->ext_version = '';
    597585        $this->ext_handles = '';
Note: See TracChangeset for help on using the changeset viewer.