WordPress.org

Make WordPress Core

Changeset 10367


Ignore:
Timestamp:
01/15/09 19:50:23 (5 years ago)
Author:
azaozz
Message:

Let plugins register footer scripts easier and add filters to the concatenating functions

Location:
trunk/wp-includes
Files:
3 edited

Legend:

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

    r10362 r10367  
    2727    var $print_html = ''; 
    2828    var $print_code = ''; 
     29    var $src = ''; 
    2930    var $default_dirs; 
    3031 
     
    110111        } 
    111112 
     113        $this->src .= "$src,"; 
    112114        $src = add_query_arg('ver', $ver, $src); 
    113115        $src = clean_url(apply_filters( 'script_loader_src', $src, $handle )); 
  • trunk/wp-includes/functions.wp-scripts.php

    r9243 r10367  
    4141 * @see WP_Scripts::add() For parameter information. 
    4242 */ 
    43 function wp_register_script( $handle, $src, $deps = array(), $ver = false ) { 
     43function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 
    4444    global $wp_scripts; 
    4545    if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     
    4747 
    4848    $wp_scripts->add( $handle, $src, $deps, $ver ); 
     49    if ( $in_footer ) 
     50        $wp_scripts->add_data( $handle, 'group', 1 ); 
    4951} 
    5052 
     
    8789 * @see WP_Script::add(), WP_Script::enqueue() 
    8890*/ 
    89 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) { 
     91function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { 
    9092    global $wp_scripts; 
    9193    if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     
    9597        $_handle = explode('?', $handle); 
    9698        $wp_scripts->add( $_handle[0], $src, $deps, $ver ); 
     99        if ( $in_footer ) 
     100            $wp_scripts->add_data( $_handle[0], 'group', 1 ); 
    97101    } 
    98102    $wp_scripts->enqueue( $handle ); 
  • trunk/wp-includes/script-loader.php

    r10366 r10367  
    537537function wp_print_head_scripts() { 
    538538    do_action( 'wp_print_scripts' ); 
    539     global $wp_scripts, $concatenate_scripts, $compress_scripts; 
     539    global $wp_scripts, $concatenate_scripts; 
    540540 
    541541    if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     
    548548    $wp_scripts->do_head_items(); 
    549549 
    550     _pring_scripts(); 
     550    if ( apply_filters('print_head_scripts', true) ) 
     551        _pring_scripts(); 
    551552 
    552553    $wp_scripts->do_concat = false; 
     554    $wp_scripts->print_code = $wp_scripts->concat = $wp_scripts->concat_version = $wp_scripts->print_html = $wp_scripts->src = ''; 
    553555    return $wp_scripts->done; 
    554556} 
     
    571573    $wp_scripts->do_footer_items(); 
    572574 
    573     _pring_scripts(); 
     575    if ( apply_filters('print_footer_scripts', true) ) 
     576        _pring_scripts(); 
    574577 
    575578    $wp_scripts->do_concat = false; 
     579    $wp_scripts->concat = $wp_scripts->concat_version = $wp_scripts->print_code = $wp_scripts->print_html = $wp_scripts->src = ''; 
    576580    return $wp_scripts->done; 
    577581} 
     
    590594            echo "/* ]]> */\n"; 
    591595            echo "</script>\n"; 
    592             $wp_scripts->print_code = ''; 
    593596        } 
    594597 
    595         $ver = md5($wp_scripts->concat_version); 
    596         $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&load=" . rtrim($wp_scripts->concat, ',') . "&ver=$ver"; 
     598        $ver = md5("$wp_scripts->concat" . "$wp_scripts->concat_version"); 
     599        $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&amp;load=" . rtrim($wp_scripts->concat, ',') . "&amp;ver=$ver"; 
    597600        echo "<script type='text/javascript' src='$src'></script>\n"; 
    598         $wp_scripts->concat = $wp_scripts->concat_version = ''; 
    599601    } 
    600602 
    601     if ( !empty($wp_scripts->print_html) ) { 
     603    if ( !empty($wp_scripts->print_html) ) 
    602604        echo $wp_scripts->print_html; 
    603         $wp_scripts->print_html = ''; 
    604     } 
     605 
    605606} 
    606607 
     
    619620    $wp_styles->do_items(false); 
    620621 
    621     if ( !empty($wp_styles->concat) ) { 
    622         $ver = md5($wp_styles->concat_version); 
    623         $rtl = 'rtl' === $wp_styles->text_direction ? 1 : 0; 
    624         $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&rtl={$rtl}&load=" . rtrim($wp_styles->concat, ',') . "&ver=$ver"; 
    625         echo "<link rel='stylesheet' href='$href' type='text/css' media='all' />\n"; 
    626         $wp_styles->concat = $wp_styles->concat_version = ''; 
     622    if ( apply_filters('print_admin_styles', true) ) { 
     623        if ( !empty($wp_styles->concat) ) { 
     624            $ver = md5("$wp_styles->concat" . "$wp_styles->concat_version"); 
     625            $rtl = 'rtl' === $wp_styles->text_direction ? 1 : 0; 
     626            $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&amp;rtl={$rtl}&amp;load=" . rtrim($wp_styles->concat, ',') . "&amp;ver=$ver"; 
     627            echo "<link rel='stylesheet' href='$href' type='text/css' media='all' />\n"; 
     628        } 
     629 
     630        if ( !empty($wp_styles->print_html) ) 
     631            echo $wp_styles->print_html; 
    627632    } 
    628633 
    629     if ( !empty($wp_styles->print_html) ) { 
    630         echo $wp_styles->print_html; 
    631         $wp_styles->print_html = ''; 
    632     } 
    633  
    634634    $wp_styles->do_concat = false; 
     635    $wp_styles->concat = $wp_styles->concat_version = $wp_styles->print_html = ''; 
    635636    return $wp_styles->done; 
    636637} 
Note: See TracChangeset for help on using the changeset viewer.