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. Built from https://develop.svn.wordpress.org/trunk@31032 git-svn-id: http://core.svn.wordpress.org/trunk@31013 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f7aef5b69a
commit
650a6d1062
|
@ -27,6 +27,7 @@ class WP_Scripts extends WP_Dependencies {
|
|||
public $print_html = '';
|
||||
public $print_code = '';
|
||||
public $ext_handles = '';
|
||||
public $print_after_html = '';
|
||||
public $ext_version = '';
|
||||
public $default_dirs;
|
||||
|
||||
|
@ -67,12 +68,14 @@ class WP_Scripts extends WP_Dependencies {
|
|||
return $this->print_extra_script( $handle, $echo );
|
||||
}
|
||||
|
||||
public function print_extra_script( $handle, $echo = true ) {
|
||||
if ( !$output = $this->get_data( $handle, 'data' ) )
|
||||
public function print_extra_script( $handle, $echo = true, $key = 'data' ) {
|
||||
if ( ! $output = $this->get_data( $handle, $key ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$echo )
|
||||
if ( ! $echo ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
|
||||
echo "/* <![CDATA[ */\n";
|
||||
|
@ -117,6 +120,7 @@ class WP_Scripts extends WP_Dependencies {
|
|||
$srce = apply_filters( 'script_loader_src', $src, $handle );
|
||||
if ( $this->in_default_dir($srce) ) {
|
||||
$this->print_code .= $this->print_extra_script( $handle, false );
|
||||
$this->print_after_html .= "\n" . $this->print_extra_script( $handle, false, 'data-after' );
|
||||
$this->concat .= "$handle,";
|
||||
$this->concat_version .= "$handle$ver";
|
||||
return true;
|
||||
|
@ -155,8 +159,10 @@ class WP_Scripts extends WP_Dependencies {
|
|||
|
||||
if ( $this->do_concat ) {
|
||||
$this->print_html .= $tag;
|
||||
$this->print_after_html .= $this->print_extra_script( $handle, false, 'data-after' ) . "\n";
|
||||
} else {
|
||||
echo $tag;
|
||||
$this->print_extra_script( $handle, true, 'data-after' );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -261,6 +267,7 @@ class WP_Scripts extends WP_Dependencies {
|
|||
$this->concat = '';
|
||||
$this->concat_version = '';
|
||||
$this->print_html = '';
|
||||
$this->print_after_html = '';
|
||||
$this->ext_version = '';
|
||||
$this->ext_handles = '';
|
||||
}
|
||||
|
|
|
@ -857,8 +857,21 @@ function _print_scripts() {
|
|||
echo "<script type='text/javascript' src='" . esc_attr($src) . "'></script>\n";
|
||||
}
|
||||
|
||||
if ( !empty($wp_scripts->print_html) )
|
||||
if ( ! empty( $wp_scripts->print_html ) ) {
|
||||
echo $wp_scripts->print_html;
|
||||
}
|
||||
|
||||
if ( ! empty( $wp_scripts->print_after_html ) ) {
|
||||
if ( $wp_scripts->do_concat ) {
|
||||
echo "<script type='text/javascript'>\n";
|
||||
echo "/* <![CDATA[ */\n"; // not needed in HTML 5
|
||||
echo trim( $wp_scripts->print_after_html ) . "\n";
|
||||
echo "/* ]]> */\n";
|
||||
echo "</script>\n";
|
||||
} else {
|
||||
echo $wp_scripts->print_after_html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.2-alpha-31031';
|
||||
$wp_version = '4.2-alpha-31032';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue