WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/21/2011 04:32:01 PM (8 years ago)
Author:
azaozz
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/script-loader.php

    r18436 r18446  
    475475    $styles->default_version = get_bloginfo( 'version' );
    476476    $styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
    477     $styles->default_dirs = array('/wp-admin/');
     477    $styles->default_dirs = array('/wp-admin/', '/wp-includes/');
    478478
    479479    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
     
    724724 */
    725725function wp_print_footer_scripts() {
    726     return print_footer_scripts();
     726    print_late_styles();
     727    print_footer_scripts();
     728    return true;
    727729}
    728730
     
    753755    $wp_styles->do_items(false);
    754756
    755     if ( apply_filters('print_admin_styles', true) ) {
    756         if ( !empty($wp_styles->concat) ) {
    757             $dir = $wp_styles->text_direction;
    758             $ver = md5("$wp_styles->concat_version{$dir}");
    759             $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&load=" . trim($wp_styles->concat, ', ') . "&ver=$ver";
    760             echo "<link rel='stylesheet' href='" . esc_attr($href) . "' type='text/css' media='all' />\n";
    761         }
    762 
    763         if ( !empty($wp_styles->print_html) )
    764             echo $wp_styles->print_html;
     757    if ( apply_filters('print_admin_styles', true) )
     758        _print_styles();
     759
     760    $wp_styles->reset();
     761    return $wp_styles->done;
     762}
     763
     764function print_late_styles() {
     765    global $wp_styles, $concatenate_scripts;
     766
     767    if ( !is_a($wp_styles, 'WP_Styles') )
     768        return;
     769
     770    $wp_styles->do_concat = $concatenate_scripts;
     771    $wp_styles->do_footer_items();
     772
     773    if ( apply_filters('print_late_styles', true) )
     774        _print_styles();
     775
     776    $wp_styles->reset();
     777    return $wp_styles->done;
     778}
     779
     780function _print_styles() {
     781    global $wp_styles, $compress_css;
     782
     783    $zip = $compress_css ? 1 : 0;
     784    if ( $zip && defined('ENFORCE_GZIP') && ENFORCE_GZIP )
     785        $zip = 'gzip';
     786
     787    if ( !empty($wp_styles->concat) ) {
     788        $dir = $wp_styles->text_direction;
     789        $ver = md5("$wp_styles->concat_version{$dir}");
     790        $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&load=" . trim($wp_styles->concat, ', ') . "&ver=$ver";
     791        echo "<link rel='stylesheet' href='" . esc_attr($href) . "' type='text/css' media='all' />\n";
    765792    }
    766793
    767     $wp_styles->do_concat = false;
    768     $wp_styles->concat = $wp_styles->concat_version = $wp_styles->print_html = '';
    769     return $wp_styles->done;
     794    if ( !empty($wp_styles->print_html) )
     795        echo $wp_styles->print_html;
    770796}
    771797
Note: See TracChangeset for help on using the changeset viewer.