Let plugins register footer scripts easier and add filters to the concatenating functions
git-svn-id: https://develop.svn.wordpress.org/trunk@10367 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5f38225a1c
commit
97839ac498
|
@ -26,6 +26,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||||
var $do_concat = false;
|
var $do_concat = false;
|
||||||
var $print_html = '';
|
var $print_html = '';
|
||||||
var $print_code = '';
|
var $print_code = '';
|
||||||
|
var $src = '';
|
||||||
var $default_dirs;
|
var $default_dirs;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
@ -109,6 +110,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||||
$src = $this->base_url . $src;
|
$src = $this->base_url . $src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->src .= "$src,";
|
||||||
$src = add_query_arg('ver', $ver, $src);
|
$src = add_query_arg('ver', $ver, $src);
|
||||||
$src = clean_url(apply_filters( 'script_loader_src', $src, $handle ));
|
$src = clean_url(apply_filters( 'script_loader_src', $src, $handle ));
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,14 @@ function wp_print_scripts( $handles = false ) {
|
||||||
* @since r16
|
* @since r16
|
||||||
* @see WP_Scripts::add() For parameter information.
|
* @see WP_Scripts::add() For parameter information.
|
||||||
*/
|
*/
|
||||||
function wp_register_script( $handle, $src, $deps = array(), $ver = false ) {
|
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
|
||||||
global $wp_scripts;
|
global $wp_scripts;
|
||||||
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
||||||
$wp_scripts = new WP_Scripts();
|
$wp_scripts = new WP_Scripts();
|
||||||
|
|
||||||
$wp_scripts->add( $handle, $src, $deps, $ver );
|
$wp_scripts->add( $handle, $src, $deps, $ver );
|
||||||
|
if ( $in_footer )
|
||||||
|
$wp_scripts->add_data( $handle, 'group', 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +88,7 @@ function wp_deregister_script( $handle ) {
|
||||||
* @since r16
|
* @since r16
|
||||||
* @see WP_Script::add(), WP_Script::enqueue()
|
* @see WP_Script::add(), WP_Script::enqueue()
|
||||||
*/
|
*/
|
||||||
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) {
|
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
|
||||||
global $wp_scripts;
|
global $wp_scripts;
|
||||||
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
||||||
$wp_scripts = new WP_Scripts();
|
$wp_scripts = new WP_Scripts();
|
||||||
|
@ -94,6 +96,8 @@ function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false
|
||||||
if ( $src ) {
|
if ( $src ) {
|
||||||
$_handle = explode('?', $handle);
|
$_handle = explode('?', $handle);
|
||||||
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
|
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
|
||||||
|
if ( $in_footer )
|
||||||
|
$wp_scripts->add_data( $_handle[0], 'group', 1 );
|
||||||
}
|
}
|
||||||
$wp_scripts->enqueue( $handle );
|
$wp_scripts->enqueue( $handle );
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,7 +536,7 @@ function wp_style_loader_src( $src, $handle ) {
|
||||||
*/
|
*/
|
||||||
function wp_print_head_scripts() {
|
function wp_print_head_scripts() {
|
||||||
do_action( 'wp_print_scripts' );
|
do_action( 'wp_print_scripts' );
|
||||||
global $wp_scripts, $concatenate_scripts, $compress_scripts;
|
global $wp_scripts, $concatenate_scripts;
|
||||||
|
|
||||||
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
||||||
$wp_scripts = new WP_Scripts();
|
$wp_scripts = new WP_Scripts();
|
||||||
|
@ -547,9 +547,11 @@ function wp_print_head_scripts() {
|
||||||
$wp_scripts->do_concat = $concatenate_scripts;
|
$wp_scripts->do_concat = $concatenate_scripts;
|
||||||
$wp_scripts->do_head_items();
|
$wp_scripts->do_head_items();
|
||||||
|
|
||||||
_pring_scripts();
|
if ( apply_filters('print_head_scripts', true) )
|
||||||
|
_pring_scripts();
|
||||||
|
|
||||||
$wp_scripts->do_concat = false;
|
$wp_scripts->do_concat = false;
|
||||||
|
$wp_scripts->print_code = $wp_scripts->concat = $wp_scripts->concat_version = $wp_scripts->print_html = $wp_scripts->src = '';
|
||||||
return $wp_scripts->done;
|
return $wp_scripts->done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,9 +572,11 @@ function wp_print_footer_scripts() {
|
||||||
$wp_scripts->do_concat = $concatenate_scripts;
|
$wp_scripts->do_concat = $concatenate_scripts;
|
||||||
$wp_scripts->do_footer_items();
|
$wp_scripts->do_footer_items();
|
||||||
|
|
||||||
_pring_scripts();
|
if ( apply_filters('print_footer_scripts', true) )
|
||||||
|
_pring_scripts();
|
||||||
|
|
||||||
$wp_scripts->do_concat = false;
|
$wp_scripts->do_concat = false;
|
||||||
|
$wp_scripts->concat = $wp_scripts->concat_version = $wp_scripts->print_code = $wp_scripts->print_html = $wp_scripts->src = '';
|
||||||
return $wp_scripts->done;
|
return $wp_scripts->done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,19 +593,16 @@ function _pring_scripts() {
|
||||||
echo $wp_scripts->print_code;
|
echo $wp_scripts->print_code;
|
||||||
echo "/* ]]> */\n";
|
echo "/* ]]> */\n";
|
||||||
echo "</script>\n";
|
echo "</script>\n";
|
||||||
$wp_scripts->print_code = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$ver = md5($wp_scripts->concat_version);
|
$ver = md5("$wp_scripts->concat" . "$wp_scripts->concat_version");
|
||||||
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&load=" . rtrim($wp_scripts->concat, ',') . "&ver=$ver";
|
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&load=" . rtrim($wp_scripts->concat, ',') . "&ver=$ver";
|
||||||
echo "<script type='text/javascript' src='$src'></script>\n";
|
echo "<script type='text/javascript' src='$src'></script>\n";
|
||||||
$wp_scripts->concat = $wp_scripts->concat_version = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($wp_scripts->print_html) ) {
|
if ( !empty($wp_scripts->print_html) )
|
||||||
echo $wp_scripts->print_html;
|
echo $wp_scripts->print_html;
|
||||||
$wp_scripts->print_html = '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_print_admin_styles() {
|
function wp_print_admin_styles() {
|
||||||
|
@ -618,20 +619,20 @@ function wp_print_admin_styles() {
|
||||||
|
|
||||||
$wp_styles->do_items(false);
|
$wp_styles->do_items(false);
|
||||||
|
|
||||||
if ( !empty($wp_styles->concat) ) {
|
if ( apply_filters('print_admin_styles', true) ) {
|
||||||
$ver = md5($wp_styles->concat_version);
|
if ( !empty($wp_styles->concat) ) {
|
||||||
$rtl = 'rtl' === $wp_styles->text_direction ? 1 : 0;
|
$ver = md5("$wp_styles->concat" . "$wp_styles->concat_version");
|
||||||
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&rtl={$rtl}&load=" . rtrim($wp_styles->concat, ',') . "&ver=$ver";
|
$rtl = 'rtl' === $wp_styles->text_direction ? 1 : 0;
|
||||||
echo "<link rel='stylesheet' href='$href' type='text/css' media='all' />\n";
|
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&rtl={$rtl}&load=" . rtrim($wp_styles->concat, ',') . "&ver=$ver";
|
||||||
$wp_styles->concat = $wp_styles->concat_version = '';
|
echo "<link rel='stylesheet' href='$href' type='text/css' media='all' />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($wp_styles->print_html) ) {
|
if ( !empty($wp_styles->print_html) )
|
||||||
echo $wp_styles->print_html;
|
echo $wp_styles->print_html;
|
||||||
$wp_styles->print_html = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$wp_styles->do_concat = false;
|
$wp_styles->do_concat = false;
|
||||||
|
$wp_styles->concat = $wp_styles->concat_version = $wp_styles->print_html = '';
|
||||||
return $wp_styles->done;
|
return $wp_styles->done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue