Make WordPress Core

Changeset 18446


Ignore:
Timestamp:
07/21/2011 04:32:01 PM (13 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

Location:
trunk/wp-includes
Files:
5 edited

Legend:

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

    r17771 r18446  
    4040
    4141        foreach( $this->to_do as $key => $handle ) {
    42             if ( !in_array($handle, $this->done) && isset($this->registered[$handle]) ) {
     42            if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
    4343
    4444                if ( ! $this->registered[$handle]->src ) { // Defines a group.
  • trunk/wp-includes/class.wp-scripts.php

    r16469 r18446  
    168168
    169169    function do_footer_items() {
    170         if ( !empty($this->in_footer) ) {
    171             foreach( $this->in_footer as $key => $handle ) {
    172                 if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
    173                     $this->do_item($handle);
    174                     $this->done[] = $handle;
    175                     unset( $this->in_footer[$key] );
    176                 }
    177             }
    178         }
     170        $this->do_items(false, 1);
    179171        return $this->done;
    180172    }
  • trunk/wp-includes/class.wp-styles.php

    r13351 r18446  
    123123        return false;
    124124    }
     125   
     126    function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
     127        $this->do_items(false, 1);
     128        return $this->done;
     129    }
    125130
     131    function reset() {
     132        $this->do_concat = false;
     133        $this->concat = '';
     134        $this->concat_version = '';
     135        $this->print_html = '';
     136    }
    126137}
     138
  • trunk/wp-includes/default-filters.php

    r17999 r18446  
    243243add_action( 'sanitize_comment_cookies',   'sanitize_comment_cookies'       );
    244244add_action( 'admin_print_scripts',        'print_head_scripts',      20    );
    245 add_action( 'admin_print_footer_scripts', 'print_footer_scripts',    20    );
     245add_action( 'admin_print_footer_scripts', 'wp_print_footer_scripts', 20    );
    246246add_action( 'admin_print_styles',         'print_admin_styles',      20    );
    247247add_action( 'init',                       'smilies_init',             5    );
  • 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.