WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/03/2015 05:07:15 AM (6 years ago)
Author:
wonderboymusic
Message:

Add the ability to print data *after* a script, whether it is concatenated or not:

  • Add a third argument to WP_Scripts->print_extra_script(), $key, which will be passed to ->get_data() (no longer passes hardcoded 'data')
  • When $key is set to 'data-after', the inline script will be printed after the <script> tag. If the scripts are being concatenated, all scripts' 'data-after' data will be printed after the concatenated <script> has been rendered.

Props hakre, wonderboymusic.
Fixes #25277.

File:
1 edited

Legend:

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

    r31030 r31032  
    2828    public $print_code = '';
    2929    public $ext_handles = '';
     30    public $print_after_html = '';
    3031    public $ext_version = '';
    3132    public $default_dirs;
     
    6869    }
    6970
    70     public function print_extra_script( $handle, $echo = true ) {
    71         if ( !$output = $this->get_data( $handle, 'data' ) )
     71    public function print_extra_script( $handle, $echo = true, $key = 'data' ) {
     72        if ( ! $output = $this->get_data( $handle, $key ) ) {
    7273            return;
    73 
    74         if ( !$echo )
     74        }
     75
     76        if ( ! $echo ) {
    7577            return $output;
     78        }
    7679
    7780        echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
     
    118121            if ( $this->in_default_dir($srce) ) {
    119122                $this->print_code .= $this->print_extra_script( $handle, false );
     123                $this->print_after_html .= "\n" . $this->print_extra_script( $handle, false, 'data-after' );
    120124                $this->concat .= "$handle,";
    121125                $this->concat_version .= "$handle$ver";
     
    156160        if ( $this->do_concat ) {
    157161            $this->print_html .= $tag;
     162            $this->print_after_html .= $this->print_extra_script( $handle, false, 'data-after' ) . "\n";
    158163        } else {
    159164            echo $tag;
     165            $this->print_extra_script( $handle, true, 'data-after' );
    160166        }
    161167
     
    262268        $this->concat_version = '';
    263269        $this->print_html = '';
     270        $this->print_after_html = '';
    264271        $this->ext_version = '';
    265272        $this->ext_handles = '';
Note: See TracChangeset for help on using the changeset viewer.