Ticket #8628: 8628-3.patch
File 8628-3.patch, 9.2 KB (added by , 16 years ago) |
---|
-
wp-admin/admin-footer.php
22 22 <p id="footer-upgrade" class="alignright"><?php echo $upgrade; ?></p> 23 23 <div class="clear"></div> 24 24 </div> 25 <?php do_action('admin_footer', ''); ?> 25 <?php 26 do_action('admin_footer', ''); 27 do_action('admin_print_footer_scripts'); 28 ?> 26 29 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> 27 30 </body> 28 </html> 29 No newline at end of file 31 </html> 32 -
wp-includes/class.wp-dependencies.php
22 22 var $to_do = array(); 23 23 var $done = array(); 24 24 var $args = array(); 25 var $groups = array(); 26 var $group = 0; 25 27 26 28 function WP_Dependencies() { 27 29 $args = func_get_args(); … … 38 40 * @param mixed handles (optional) items to be processed. (void) processes queue, (string) process that item, (array of strings) process those items 39 41 * @return array Items that have been processed 40 42 */ 41 function do_items( $handles = false ) {43 function do_items( $handles = false, $group = false ) { 42 44 // Print the queue if nothing is passed. If a string is passed, print that script. If an array is passed, print those scripts. 43 45 $handles = false === $handles ? $this->queue : (array) $handles; 44 46 $this->all_deps( $handles ); 45 47 46 foreach( $this->to_do as $ handle ) {48 foreach( $this->to_do as $key => $handle ) { 47 49 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; 50 54 } 51 $this->done[] = $handle; 55 56 if ( $this->do_item( $handle, $group ) ) 57 $this->done[] = $handle; 58 59 unset( $this->to_do[$key] ); 52 60 } 53 61 } 54 62 55 $this->to_do = array();56 63 return $this->done; 57 64 } 58 65 … … 69 76 * @param mixed handles Accepts (string) dep name or (array of strings) dep names 70 77 * @param bool recursion Used internally when function calls itself 71 78 */ 72 function all_deps( $handles, $recursion = false ) {79 function all_deps( $handles, $recursion = false, $group = false ) { 73 80 if ( !$handles = (array) $handles ) 74 81 return false; 75 82 76 83 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]; 81 86 82 if ( i sset($this->to_do[$handle]) ) // Already grobbed it and its deps87 if ( in_array($handle, $this->done, true) ) // Already done 83 88 continue; 84 89 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 85 98 $keep_going = true; 86 99 if ( !isset($this->registered[$handle]) ) 87 100 $keep_going = false; // Script doesn't exist … … 97 110 continue; // We're at the top level. Move on to the next one. 98 111 } 99 112 100 $this->to_do[ $handle] = true;113 $this->to_do[] = $handle; 101 114 } 102 115 103 if ( !$recursion ) // at the end104 $this->to_do = array_keys( $this->to_do );105 116 return true; 106 117 } 107 118 … … 181 192 return false; 182 193 } 183 194 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 184 210 } 185 211 186 212 class _WP_Dependency { -
wp-includes/class.wp-scripts.php
19 19 class WP_Scripts extends WP_Dependencies { 20 20 var $base_url; // Full URL with trailing slash 21 21 var $default_version; 22 var $in_footer = array(); 22 23 23 24 function __construct() { 24 25 do_action_ref_array( 'wp_default_scripts', array(&$this) ); … … 30 31 * Prints the scripts passed to it or the print queue. Also prints all necessary dependencies. 31 32 * 32 33 * @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. 33 35 * @return array Scripts that have been printed 34 36 */ 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 ); 37 39 } 38 40 39 41 function print_scripts_l10n( $handle ) { … … 62 64 return true; 63 65 } 64 66 65 function do_item( $handle ) {67 function do_item( $handle, $group = false ) { 66 68 if ( !parent::do_item($handle) ) 67 69 return false; 68 70 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 69 79 $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; 70 80 if ( isset($this->args[$handle]) ) 71 81 $ver .= '&' . $this->args[$handle]; … … 101 111 return $this->add_data( $handle, 'l10n', array( $object_name, $l10n ) ); 102 112 } 103 113 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 104 122 function all_deps( $handles, $recursion = false ) { 105 123 $r = parent::all_deps( $handles, $recursion ); 106 124 if ( !$recursion ) 107 125 $this->to_do = apply_filters( 'print_scripts_array', $this->to_do ); 108 126 return $r; 109 127 } 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 } 110 143 } -
wp-includes/default-filters.php
181 181 add_action('do_pings', 'do_all_pings', 10, 1); 182 182 add_action('do_robots', 'do_robots'); 183 183 add_action('sanitize_comment_cookies', 'sanitize_comment_cookies'); 184 add_action('admin_print_scripts', 'wp_print_scripts', 20); 184 add_action('admin_print_scripts', 'wp_print_head_scripts', 20); 185 add_action('admin_print_footer_scripts', 'wp_print_footer_scripts', 20); 185 186 add_action('admin_print_styles', 'wp_print_styles', 20); 186 187 add_action('init', 'smilies_init', 5); 187 188 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); -
wp-includes/functions.wp-scripts.php
9 9 /** 10 10 * Prints script tags in document head. 11 11 * 12 * Called byadmin-header.php and by wp_head hook. Since it is called by wp_head12 * Called in admin-header.php and by wp_head hook. Since it is called by wp_head 13 13 * on every page load, the function does not instantiate the WP_Scripts object 14 14 * unless script names are explicitly passed. Does make use of already 15 15 * instantiated $wp_scripts if present. Use provided wp_print_scripts hook to … … 18 18 * @since r16 19 19 * @see WP_Scripts::print_scripts() 20 20 */ 21 function wp_print_scripts( $handles = false ) {21 function wp_print_scripts( $handles = false, $group = false ) { 22 22 do_action( 'wp_print_scripts' ); 23 23 if ( '' === $handles ) // for wp_head 24 24 $handles = false; … … 31 31 $wp_scripts = new WP_Scripts(); 32 32 } 33 33 34 return $wp_scripts->do_items( $handles );34 return $wp_scripts->do_items( $handles, $group ); 35 35 } 36 36 37 37 /** 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 */ 46 function 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 */ 56 function 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 /** 38 66 * Register new JavaScript file. 39 67 * 40 68 * @since r16