Make WordPress Core

Ticket #8628: 8628-3.patch

File 8628-3.patch, 9.2 KB (added by azaozz, 16 years ago)
  • wp-admin/admin-footer.php

     
    2222<p id="footer-upgrade" class="alignright"><?php echo $upgrade; ?></p>
    2323<div class="clear"></div>
    2424</div>
    25 <?php do_action('admin_footer', ''); ?>
     25<?php
     26do_action('admin_footer', '');
     27do_action('admin_print_footer_scripts');
     28?>
    2629<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
    2730</body>
    28 </html>
    29  No newline at end of file
     31</html>
     32
  • wp-includes/class.wp-dependencies.php

     
    2222        var $to_do = array();
    2323        var $done = array();
    2424        var $args = array();
     25        var $groups = array();
     26        var $group = 0;
    2527
    2628        function WP_Dependencies() {
    2729                $args = func_get_args();
     
    3840         * @param mixed handles (optional) items to be processed.  (void) processes queue, (string) process that item, (array of strings) process those items
    3941         * @return array Items that have been processed
    4042         */
    41         function do_items( $handles = false ) {
     43        function do_items( $handles = false, $group = false ) {
    4244                // Print the queue if nothing is passed.  If a string is passed, print that script.  If an array is passed, print those scripts.
    4345                $handles = false === $handles ? $this->queue : (array) $handles;
    4446                $this->all_deps( $handles );
    4547
    46                 foreach( $this->to_do as $handle ) {
     48                foreach( $this->to_do as $key => $handle ) {
    4749                        if ( !in_array($handle, $this->done) && isset($this->registered[$handle]) ) {
    48                                 if ( $this->registered[$handle]->src ) { // Else it defines a group.
    49                                         $this->do_item( $handle );
     50
     51                                if ( ! $this->registered[$handle]->src ) { // Defines a group.
     52                                        $this->done[] = $handle;
     53                                        continue;
    5054                                }
    51                                 $this->done[] = $handle;
     55
     56                                if ( $this->do_item( $handle, $group ) )
     57                                        $this->done[] = $handle;
     58
     59                                unset( $this->to_do[$key] );
    5260                        }
    5361                }
    5462
    55                 $this->to_do = array();
    5663                return $this->done;
    5764        }
    5865
     
    6976         * @param mixed handles Accepts (string) dep name or (array of strings) dep names
    7077         * @param bool recursion Used internally when function calls itself
    7178         */
    72         function all_deps( $handles, $recursion = false ) {
     79        function all_deps( $handles, $recursion = false, $group = false ) {
    7380                if ( !$handles = (array) $handles )
    7481                        return false;
    7582
    7683                foreach ( $handles as $handle ) {
    77                         $handle = explode('?', $handle);
    78                         if ( isset($handle[1]) )
    79                                 $this->args[$handle[0]] = $handle[1];
    80                         $handle = $handle[0];
     84                        $handle_parts = explode('?', $handle);
     85                        $handle = $handle_parts[0];
    8186
    82                         if ( isset($this->to_do[$handle]) ) // Already grobbed it and its deps
     87                        if ( in_array($handle, $this->done, true) ) // Already done
    8388                                continue;
    8489
     90                        $this->set_group( $handle, $recursion, $group );
     91
     92                        if ( in_array($handle, $this->to_do, true) ) // Already grobbed it and its deps
     93                                continue;
     94
     95                        if ( isset($handle_parts[1]) )
     96                                $this->args[$handle] = $handle_parts[1];
     97
    8598                        $keep_going = true;
    8699                        if ( !isset($this->registered[$handle]) )
    87100                                $keep_going = false; // Script doesn't exist
     
    97110                                        continue; // We're at the top level.  Move on to the next one.
    98111                        }
    99112
    100                         $this->to_do[$handle] = true;
     113                        $this->to_do[] = $handle;
    101114                }
    102115
    103                 if ( !$recursion ) // at the end
    104                         $this->to_do = array_keys( $this->to_do );
    105116                return true;
    106117        }
    107118
     
    181192                return false;
    182193        }
    183194
     195        function set_group( $handle, $recursion, $group ) {
     196                $group = (int) $group;
     197
     198                if ( $recursion )
     199                        $group = min($this->group, $group);
     200                else
     201                        $this->group = $group;
     202
     203                if ( isset($this->groups[$handle]) && $this->groups[$handle] <= $group )
     204                        return false;
     205
     206                $this->groups[$handle] = $group;
     207                return true;
     208        }
     209
    184210}
    185211
    186212class _WP_Dependency {
  • wp-includes/class.wp-scripts.php

     
    1919class WP_Scripts extends WP_Dependencies {
    2020        var $base_url; // Full URL with trailing slash
    2121        var $default_version;
     22        var $in_footer = array();
    2223
    2324        function __construct() {
    2425                do_action_ref_array( 'wp_default_scripts', array(&$this) );
     
    3031         * Prints the scripts passed to it or the print queue.  Also prints all necessary dependencies.
    3132         *
    3233         * @param mixed handles (optional) Scripts to be printed.  (void) prints queue, (string) prints that script, (array of strings) prints those scripts.
     34         * @param int group (optional) If scripts were queued in groups prints this group number.
    3335         * @return array Scripts that have been printed
    3436         */
    35         function print_scripts( $handles = false ) {
    36                 return $this->do_items( $handles );
     37        function print_scripts( $handles = false, $group = false ) {
     38                return $this->do_items( $handles, $group );
    3739        }
    3840
    3941        function print_scripts_l10n( $handle ) {
     
    6264                return true;
    6365        }
    6466
    65         function do_item( $handle ) {
     67        function do_item( $handle, $group = false ) {
    6668                if ( !parent::do_item($handle) )
    6769                        return false;
    6870
     71                if ( 0 === $group && $this->groups[$handle] > 0 ) {
     72                        $this->in_footer[] = $handle;
     73                        return false;
     74                }
     75
     76                if ( false === $group && in_array($handle, $this->in_footer, true) )
     77                        $this->in_footer = array_diff( $this->in_footer, (array) $handle );
     78
    6979                $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
    7080                if ( isset($this->args[$handle]) )
    7181                        $ver .= '&amp;' . $this->args[$handle];
     
    101111                return $this->add_data( $handle, 'l10n', array( $object_name, $l10n ) );
    102112        }
    103113
     114        function set_group( $handle, $recursion, $group = false ) {
     115                $grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0;
     116                if ( false !== $group && $grp > $group )
     117                        $grp = $group;
     118
     119                parent::set_group( $handle, $recursion, $grp );
     120        }
     121
    104122        function all_deps( $handles, $recursion = false ) {
    105123                $r = parent::all_deps( $handles, $recursion );
    106124                if ( !$recursion )
    107125                        $this->to_do = apply_filters( 'print_scripts_array', $this->to_do );
    108126                return $r;
    109127        }
     128
     129        function do_footer_items() {
     130
     131                if ( !empty($this->in_footer) ) {
     132                        foreach( $this->in_footer as $key => $handle ) {
     133                                if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
     134                                        $this->do_item($handle);
     135                                        $this->done[] = $handle;
     136                                        unset( $this->in_footer[$key] );
     137                                }
     138                        }
     139                }
     140
     141                return $this->done;
     142        }
    110143}
  • wp-includes/default-filters.php

     
    181181add_action('do_pings', 'do_all_pings', 10, 1);
    182182add_action('do_robots', 'do_robots');
    183183add_action('sanitize_comment_cookies', 'sanitize_comment_cookies');
    184 add_action('admin_print_scripts', 'wp_print_scripts', 20);
     184add_action('admin_print_scripts', 'wp_print_head_scripts', 20);
     185add_action('admin_print_footer_scripts', 'wp_print_footer_scripts', 20);
    185186add_action('admin_print_styles', 'wp_print_styles', 20);
    186187add_action('init', 'smilies_init', 5);
    187188add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
  • wp-includes/functions.wp-scripts.php

     
    99/**
    1010 * Prints script tags in document head.
    1111 *
    12  * Called by admin-header.php and by wp_head hook. Since it is called by wp_head
     12 * Called in admin-header.php and by wp_head hook. Since it is called by wp_head
    1313 * on every page load, the function does not instantiate the WP_Scripts object
    1414 * unless script names are explicitly passed. Does make use of already
    1515 * instantiated $wp_scripts if present. Use provided wp_print_scripts hook to
     
    1818 * @since r16
    1919 * @see WP_Scripts::print_scripts()
    2020 */
    21 function wp_print_scripts( $handles = false ) {
     21function wp_print_scripts( $handles = false, $group = false ) {
    2222        do_action( 'wp_print_scripts' );
    2323        if ( '' === $handles ) // for wp_head
    2424                $handles = false;
     
    3131                        $wp_scripts = new WP_Scripts();
    3232        }
    3333
    34         return $wp_scripts->do_items( $handles );
     34        return $wp_scripts->do_items( $handles, $group );
    3535}
    3636
    3737/**
     38 * Print the script queue in the HTML head.
     39 * 
     40 * Postpones the scripts that were queued for the footer.
     41 * wp_print_footer_scripts() has to be called in the footer to print these scripts.
     42 *
     43 * @since unknown
     44 * @see wp_print_scripts()
     45 */
     46function wp_print_head_scripts() {
     47        return wp_print_scripts( false, 0 );
     48}
     49
     50/**
     51 * Print the scripts that were queued for the footer.
     52 *
     53 * @since unknown
     54 * @see WP_Scripts::do_footer_items()
     55 */
     56function wp_print_footer_scripts() {
     57        global $wp_scripts;
     58
     59        if ( !is_a($wp_scripts, 'WP_Scripts') )
     60                return array(); // No need to run if not instantiated.
     61
     62        return $wp_scripts->do_footer_items();
     63}
     64
     65/**
    3866 * Register new JavaScript file.
    3967 *
    4068 * @since r16