Ticket #23914: class.wp-dependencies.php.patch
File class.wp-dependencies.php.patch, 8.7 KB (added by , 12 years ago) |
---|
-
wp-includes/class.wp-dependencies.php
21 21 var $queue = array(); 22 22 var $to_do = array(); 23 23 var $done = array(); 24 var $args = array(); 25 var $groups = array(); 26 var $group = 0; 24 var $args = array(); // In extending classes, strings appended to item urls. 25 var $groups = array(); // In extending class WP_Scripts, header and footer groups. 26 var $group = 0; // Internal group state. 27 27 28 28 /** 29 29 * Do the dependencies 30 30 * 31 * Process the items passed to it or the queue. Processes all dependencies.31 * Processes the items passed to it or the queue. Processes all dependencies. 32 32 * 33 * @param mixed $handles (optional) items to be processed. (void) processes queue, (string) process that item, (array of strings) process those items 34 * @return array Items that have been processed 33 * @param mixed $handles (optional) Items to be processed: (false) Process queue, (string) process item, (array of strings) process items 34 * @param mixed $group Group level: (int) level, (false) no groups 35 * @return array Handles of items that have been processed 35 36 */ 36 37 function do_items( $handles = false, $group = false ) { 37 // Print the queue if nothing is passed. If a string is passed, print that script. If an array is passed, print those scripts.38 // Print the queue if nothing is passed. If a string is passed, print that item. If an array is passed, print those items. 38 39 $handles = false === $handles ? $this->queue : (array) $handles; 39 40 $this->all_deps( $handles ); 40 41 41 42 foreach( $this->to_do as $key => $handle ) { 42 43 if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) { 43 44 44 if ( ! $this->registered[$handle]->src ) { // Defines a group. 45 /** 46 * A single item may alias a set of items, by having dependencies but no src. 47 * Queuing the item queues the dependencies. 48 * Example: the extending class WP_Scripts is used to register 'scriptaculous' as a set of registered handles: 49 * add( 'scriptaculous', false, array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls') ); 50 * The src property is false. 51 **/ 52 if ( ! $this->registered[$handle]->src ) { 45 53 $this->done[] = $handle; 46 54 continue; 47 55 } … … 56 64 return $this->done; 57 65 } 58 66 67 /** 68 * Do dependency 69 * 70 * Processes one item for dependencies. 71 * 72 * @param string $handle Unique item name 73 * @return bool Success 74 */ 59 75 function do_item( $handle ) { 60 76 return isset($this->registered[$handle]); 61 77 } 62 78 63 79 /** 64 * Determine sdependencies80 * Determine dependencies 65 81 * 66 * Recursively builds array of items to process taking dependencies into account. Does NOT catch infinite loops. 82 * Recursively builds array of items to process taking dependencies into account. 83 * Does NOT catch infinite loops. 67 84 * 68 * 69 * @param mixed $handles Accepts (string) dep name or (array of strings) dep names 70 * @param bool $recursion Used internally when function calls itself 85 * @param mixed $handles (string) Dependency handle and argument or (array of strings) Dependency handles and arguments 86 * @param bool $recursion Internal flag that function is calling itself 87 * @param mixed $group Group level: (int) level, (false) no groups 88 * @return bool Success 71 89 */ 72 90 function all_deps( $handles, $recursion = false, $group = false ) { 73 91 if ( !$handles = (array) $handles ) … … 88 106 89 107 $keep_going = true; 90 108 if ( !isset($this->registered[$handle]) ) 91 $keep_going = false; // Scriptdoesn't exist109 $keep_going = false; // Item doesn't exist 92 110 elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) ) 93 $keep_going = false; // Scriptrequires deps which don't exist (not a necessary check. efficiency?)111 $keep_going = false; // Item requires deps which don't exist (not a necessary check. efficiency?) 94 112 elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $group ) ) 95 $keep_going = false; // Scriptrequires deps which don't exist113 $keep_going = false; // Item requires deps which don't exist 96 114 97 if ( !$keep_going ) { // Either scriptor its deps don't exist.115 if ( !$keep_going ) { // Either item or its deps don't exist. 98 116 if ( $recursion ) 99 117 return false; // Abort this branch. 100 118 else … … 114 132 } 115 133 116 134 /** 117 * Addsitem135 * Register item 118 136 * 119 * Adds the item only if no item of that name already exists137 * Registers the item if no item of that name already exists. 120 138 * 121 * @param string $handle Script name 122 * @param string $src Script url 123 * @param array $deps (optional) Array of script names on which this script depends 124 * @param string $ver (optional) Script version (used for cache busting) 125 * @return array Hierarchical array of dependencies 139 * @param string $handle Unique item name 140 * @param string $src Item url 141 * @param array of strings $deps (optional) Item handles on which this item depends 142 * @param string $ver (optional) Version (used for cache busting) 143 * @param mixed $args (optional) Custom property of the item. NOT the class property $args. Examples: $media, $in_footer. 144 * @return bool Success 126 145 */ 127 146 function add( $handle, $src, $deps = array(), $ver = false, $args = null ) { 128 147 if ( isset($this->registered[$handle]) ) … … 132 151 } 133 152 134 153 /** 135 * Add sextra data154 * Add extra data 136 155 * 137 * Adds data only if script has already been added.156 * Adds data if item has been registered. 138 157 * 139 * @param string $handle Scriptname140 * @param string $key 141 * @param mixed $value 142 * @return bool success158 * @param string $handle Unique item name 159 * @param string $key Data key 160 * @param mixed $value Data value 161 * @return bool Success 143 162 */ 144 163 function add_data( $handle, $key, $value ) { 145 164 if ( !isset( $this->registered[$handle] ) ) … … 151 170 /** 152 171 * Get extra data 153 172 * 154 * Gets data associated with a certain handle.173 * Gets data associated with a registered item. 155 174 * 156 175 * @since WP 3.3 157 176 * 158 * @param string $handle Scriptname159 * @param string $key 160 * @return mixed 177 * @param string $handle Unique item name 178 * @param string $key Data key 179 * @return mixed Data value 161 180 */ 162 181 function get_data( $handle, $key ) { 163 182 if ( !isset( $this->registered[$handle] ) ) … … 169 188 return $this->registered[$handle]->extra[$key]; 170 189 } 171 190 191 /** 192 * Unregister items 193 * 194 * @param mixed $handles (string) Item handle or (array of strings) Item handles 195 * @return void 196 */ 172 197 function remove( $handles ) { 173 198 foreach ( (array) $handles as $handle ) 174 199 unset($this->registered[$handle]); 175 200 } 176 201 202 /** 203 * Queue items 204 * 205 * Decodes handles and arguments, then queues handles and stores arguments in the class property $args. 206 * For example in extending classes, $args is appended to the item url as a query string. 207 * Note $args is NOT the $args property of items in the $registered array. 208 * 209 * @param mixed $handles (string) Item handle and argument or (array of strings) Item handles and arguments 210 * @return void 211 */ 177 212 function enqueue( $handles ) { 178 213 foreach ( (array) $handles as $handle ) { 179 214 $handle = explode('?', $handle); … … 185 220 } 186 221 } 187 222 223 /** 224 * Dequeue items 225 * 226 * Decodes handles and arguments, then dequeues handles and removes arguments from the class property $args. 227 * 228 * @param mixed $handles (string) Item handle and argument or (array of strings) Item handles and arguments 229 * @return void 230 */ 188 231 function dequeue( $handles ) { 189 232 foreach ( (array) $handles as $handle ) { 190 233 $handle = explode('?', $handle); … … 196 239 } 197 240 } 198 241 199 242 /** 243 * Query list for item 244 * 245 * @param $handle (string) Item handle 246 * @param $list (string) Property name of list array 247 * @return bool Found, or object Item data 248 */ 200 249 function query( $handle, $list = 'registered' ) { 201 250 switch ( $list ) { 202 251 case 'registered' : … … 220 269 return false; 221 270 } 222 271 272 /** 273 * Set item group, unless already in a lower group 274 * 275 * @param $handle (string) Item handle 276 * @param bool $recursion Internal flag that calling function was called recusively 277 * @param mixed $group Group level 278 * @return bool Not already in the group or a lower group 279 */ 223 280 function set_group( $handle, $recursion, $group ) { 224 281 $group = (int) $group; 225 282 … … 242 299 var $src; 243 300 var $deps = array(); 244 301 var $ver = false; 245 var $args = null; 246 302 var $args = null; // Custom property, such as $in_footer or $media. 247 303 var $extra = array(); 248 304 249 305 function __construct() {