Support for using wp_enqueue_script() and wp_enqueue_style() in the HTML body. All scripts and styles are added in the footer, fixes #9346
git-svn-id: http://svn.automattic.com/wordpress/trunk@18446 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4ad0954961
commit
23f490bb02
|
@ -39,7 +39,7 @@ class WP_Dependencies {
|
||||||
$this->all_deps( $handles );
|
$this->all_deps( $handles );
|
||||||
|
|
||||||
foreach( $this->to_do as $key => $handle ) {
|
foreach( $this->to_do as $key => $handle ) {
|
||||||
if ( !in_array($handle, $this->done) && isset($this->registered[$handle]) ) {
|
if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
|
||||||
|
|
||||||
if ( ! $this->registered[$handle]->src ) { // Defines a group.
|
if ( ! $this->registered[$handle]->src ) { // Defines a group.
|
||||||
$this->done[] = $handle;
|
$this->done[] = $handle;
|
||||||
|
|
|
@ -167,15 +167,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_footer_items() {
|
function do_footer_items() {
|
||||||
if ( !empty($this->in_footer) ) {
|
$this->do_items(false, 1);
|
||||||
foreach( $this->in_footer as $key => $handle ) {
|
|
||||||
if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
|
|
||||||
$this->do_item($handle);
|
|
||||||
$this->done[] = $handle;
|
|
||||||
unset( $this->in_footer[$key] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->done;
|
return $this->done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,5 +122,17 @@ class WP_Styles extends WP_Dependencies {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
|
||||||
|
$this->do_items(false, 1);
|
||||||
|
return $this->done;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
$this->do_concat = false;
|
||||||
|
$this->concat = '';
|
||||||
|
$this->concat_version = '';
|
||||||
|
$this->print_html = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -242,7 +242,7 @@ add_action( 'do_pings', 'do_all_pings', 10, 1 );
|
||||||
add_action( 'do_robots', 'do_robots' );
|
add_action( 'do_robots', 'do_robots' );
|
||||||
add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' );
|
add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' );
|
||||||
add_action( 'admin_print_scripts', 'print_head_scripts', 20 );
|
add_action( 'admin_print_scripts', 'print_head_scripts', 20 );
|
||||||
add_action( 'admin_print_footer_scripts', 'print_footer_scripts', 20 );
|
add_action( 'admin_print_footer_scripts', 'wp_print_footer_scripts', 20 );
|
||||||
add_action( 'admin_print_styles', 'print_admin_styles', 20 );
|
add_action( 'admin_print_styles', 'print_admin_styles', 20 );
|
||||||
add_action( 'init', 'smilies_init', 5 );
|
add_action( 'init', 'smilies_init', 5 );
|
||||||
add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
|
add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
|
||||||
|
|
|
@ -474,7 +474,7 @@ function wp_default_styles( &$styles ) {
|
||||||
$styles->content_url = defined('WP_CONTENT_URL')? WP_CONTENT_URL : '';
|
$styles->content_url = defined('WP_CONTENT_URL')? WP_CONTENT_URL : '';
|
||||||
$styles->default_version = get_bloginfo( 'version' );
|
$styles->default_version = get_bloginfo( 'version' );
|
||||||
$styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
|
$styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
|
||||||
$styles->default_dirs = array('/wp-admin/');
|
$styles->default_dirs = array('/wp-admin/', '/wp-includes/');
|
||||||
|
|
||||||
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
|
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
|
||||||
|
|
||||||
|
@ -723,7 +723,9 @@ function wp_print_head_scripts() {
|
||||||
* @since 2.8
|
* @since 2.8
|
||||||
*/
|
*/
|
||||||
function wp_print_footer_scripts() {
|
function wp_print_footer_scripts() {
|
||||||
return print_footer_scripts();
|
print_late_styles();
|
||||||
|
print_footer_scripts();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -752,21 +754,45 @@ function print_admin_styles() {
|
||||||
|
|
||||||
$wp_styles->do_items(false);
|
$wp_styles->do_items(false);
|
||||||
|
|
||||||
if ( apply_filters('print_admin_styles', true) ) {
|
if ( apply_filters('print_admin_styles', true) )
|
||||||
if ( !empty($wp_styles->concat) ) {
|
_print_styles();
|
||||||
$dir = $wp_styles->text_direction;
|
|
||||||
$ver = md5("$wp_styles->concat_version{$dir}");
|
|
||||||
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&load=" . trim($wp_styles->concat, ', ') . "&ver=$ver";
|
|
||||||
echo "<link rel='stylesheet' href='" . esc_attr($href) . "' type='text/css' media='all' />\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !empty($wp_styles->print_html) )
|
$wp_styles->reset();
|
||||||
echo $wp_styles->print_html;
|
return $wp_styles->done;
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_late_styles() {
|
||||||
|
global $wp_styles, $concatenate_scripts;
|
||||||
|
|
||||||
|
if ( !is_a($wp_styles, 'WP_Styles') )
|
||||||
|
return;
|
||||||
|
|
||||||
|
$wp_styles->do_concat = $concatenate_scripts;
|
||||||
|
$wp_styles->do_footer_items();
|
||||||
|
|
||||||
|
if ( apply_filters('print_late_styles', true) )
|
||||||
|
_print_styles();
|
||||||
|
|
||||||
|
$wp_styles->reset();
|
||||||
|
return $wp_styles->done;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _print_styles() {
|
||||||
|
global $wp_styles, $compress_css;
|
||||||
|
|
||||||
|
$zip = $compress_css ? 1 : 0;
|
||||||
|
if ( $zip && defined('ENFORCE_GZIP') && ENFORCE_GZIP )
|
||||||
|
$zip = 'gzip';
|
||||||
|
|
||||||
|
if ( !empty($wp_styles->concat) ) {
|
||||||
|
$dir = $wp_styles->text_direction;
|
||||||
|
$ver = md5("$wp_styles->concat_version{$dir}");
|
||||||
|
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&load=" . trim($wp_styles->concat, ', ') . "&ver=$ver";
|
||||||
|
echo "<link rel='stylesheet' href='" . esc_attr($href) . "' type='text/css' media='all' />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$wp_styles->do_concat = false;
|
if ( !empty($wp_styles->print_html) )
|
||||||
$wp_styles->concat = $wp_styles->concat_version = $wp_styles->print_html = '';
|
echo $wp_styles->print_html;
|
||||||
return $wp_styles->done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function script_concat_settings() {
|
function script_concat_settings() {
|
||||||
|
|
Loading…
Reference in New Issue