| 1 | Index: wp-includes/class.wp-dependencies.php
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- wp-includes/class.wp-dependencies.php (revision 23883)
|
|---|
| 4 | +++ wp-includes/class.wp-dependencies.php (working copy)
|
|---|
| 5 | @@ -21,27 +21,35 @@
|
|---|
| 6 | var $queue = array();
|
|---|
| 7 | var $to_do = array();
|
|---|
| 8 | var $done = array();
|
|---|
| 9 | - var $args = array();
|
|---|
| 10 | - var $groups = array();
|
|---|
| 11 | - var $group = 0;
|
|---|
| 12 | + var $args = array(); // In extending classes, strings appended to item urls.
|
|---|
| 13 | + var $groups = array(); // In extending class WP_Scripts, header and footer groups.
|
|---|
| 14 | + var $group = 0; // Internal group state.
|
|---|
| 15 |
|
|---|
| 16 | /**
|
|---|
| 17 | * Do the dependencies
|
|---|
| 18 | *
|
|---|
| 19 | - * Process the items passed to it or the queue. Processes all dependencies.
|
|---|
| 20 | + * Processes the items passed to it or the queue. Processes all dependencies.
|
|---|
| 21 | *
|
|---|
| 22 | - * @param mixed $handles (optional) items to be processed. (void) processes queue, (string) process that item, (array of strings) process those items
|
|---|
| 23 | - * @return array Items that have been processed
|
|---|
| 24 | + * @param mixed $handles (optional) Items to be processed: (false) Process queue, (string) process item, (array of strings) process items
|
|---|
| 25 | + * @param mixed $group Group level: (int) level, (false) no groups
|
|---|
| 26 | + * @return array Handles of items that have been processed
|
|---|
| 27 | */
|
|---|
| 28 | function do_items( $handles = false, $group = false ) {
|
|---|
| 29 | - // Print the queue if nothing is passed. If a string is passed, print that script. If an array is passed, print those scripts.
|
|---|
| 30 | + // Print the queue if nothing is passed. If a string is passed, print that item. If an array is passed, print those items.
|
|---|
| 31 | $handles = false === $handles ? $this->queue : (array) $handles;
|
|---|
| 32 | $this->all_deps( $handles );
|
|---|
| 33 |
|
|---|
| 34 | foreach( $this->to_do as $key => $handle ) {
|
|---|
| 35 | if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
|
|---|
| 36 |
|
|---|
| 37 | - if ( ! $this->registered[$handle]->src ) { // Defines a group.
|
|---|
| 38 | + /**
|
|---|
| 39 | + * A single item may alias a set of items, by having dependencies but no src.
|
|---|
| 40 | + * Queuing the item queues the dependencies.
|
|---|
| 41 | + * Example: the extending class WP_Scripts is used to register 'scriptaculous' as a set of registered handles:
|
|---|
| 42 | + * add( 'scriptaculous', false, array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls') );
|
|---|
| 43 | + * The src property is false.
|
|---|
| 44 | + **/
|
|---|
| 45 | + if ( ! $this->registered[$handle]->src ) {
|
|---|
| 46 | $this->done[] = $handle;
|
|---|
| 47 | continue;
|
|---|
| 48 | }
|
|---|
| 49 | @@ -56,18 +64,28 @@
|
|---|
| 50 | return $this->done;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | + /**
|
|---|
| 54 | + * Do dependency
|
|---|
| 55 | + *
|
|---|
| 56 | + * Processes one item for dependencies.
|
|---|
| 57 | + *
|
|---|
| 58 | + * @param string $handle Unique item name
|
|---|
| 59 | + * @return bool Success
|
|---|
| 60 | + */
|
|---|
| 61 | function do_item( $handle ) {
|
|---|
| 62 | return isset($this->registered[$handle]);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | /**
|
|---|
| 66 | - * Determines dependencies
|
|---|
| 67 | + * Determine dependencies
|
|---|
| 68 | *
|
|---|
| 69 | - * Recursively builds array of items to process taking dependencies into account. Does NOT catch infinite loops.
|
|---|
| 70 | + * Recursively builds array of items to process taking dependencies into account.
|
|---|
| 71 | + * Does NOT catch infinite loops.
|
|---|
| 72 | *
|
|---|
| 73 | - *
|
|---|
| 74 | - * @param mixed $handles Accepts (string) dep name or (array of strings) dep names
|
|---|
| 75 | - * @param bool $recursion Used internally when function calls itself
|
|---|
| 76 | + * @param mixed $handles (string) Dependency handle and argument or (array of strings) Dependency handles and arguments
|
|---|
| 77 | + * @param bool $recursion Internal flag that function is calling itself
|
|---|
| 78 | + * @param mixed $group Group level: (int) level, (false) no groups
|
|---|
| 79 | + * @return bool Success
|
|---|
| 80 | */
|
|---|
| 81 | function all_deps( $handles, $recursion = false, $group = false ) {
|
|---|
| 82 | if ( !$handles = (array) $handles )
|
|---|
| 83 | @@ -88,13 +106,13 @@
|
|---|
| 84 |
|
|---|
| 85 | $keep_going = true;
|
|---|
| 86 | if ( !isset($this->registered[$handle]) )
|
|---|
| 87 | - $keep_going = false; // Script doesn't exist
|
|---|
| 88 | + $keep_going = false; // Item doesn't exist
|
|---|
| 89 | elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
|
|---|
| 90 | - $keep_going = false; // Script requires deps which don't exist (not a necessary check. efficiency?)
|
|---|
| 91 | + $keep_going = false; // Item requires deps which don't exist (not a necessary check. efficiency?)
|
|---|
| 92 | elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $group ) )
|
|---|
| 93 | - $keep_going = false; // Script requires deps which don't exist
|
|---|
| 94 | + $keep_going = false; // Item requires deps which don't exist
|
|---|
| 95 |
|
|---|
| 96 | - if ( !$keep_going ) { // Either script or its deps don't exist.
|
|---|
| 97 | + if ( !$keep_going ) { // Either item or its deps don't exist.
|
|---|
| 98 | if ( $recursion )
|
|---|
| 99 | return false; // Abort this branch.
|
|---|
| 100 | else
|
|---|
| 101 | @@ -114,15 +132,16 @@
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /**
|
|---|
| 105 | - * Adds item
|
|---|
| 106 | + * Register item
|
|---|
| 107 | *
|
|---|
| 108 | - * Adds the item only if no item of that name already exists
|
|---|
| 109 | + * Registers the item if no item of that name already exists.
|
|---|
| 110 | *
|
|---|
| 111 | - * @param string $handle Script name
|
|---|
| 112 | - * @param string $src Script url
|
|---|
| 113 | - * @param array $deps (optional) Array of script names on which this script depends
|
|---|
| 114 | - * @param string $ver (optional) Script version (used for cache busting)
|
|---|
| 115 | - * @return array Hierarchical array of dependencies
|
|---|
| 116 | + * @param string $handle Unique item name
|
|---|
| 117 | + * @param string $src Resource url
|
|---|
| 118 | + * @param array of strings $deps (optional) Item handles on which this item depends
|
|---|
| 119 | + * @param string $ver (optional) Version (used for cache busting)
|
|---|
| 120 | + * @param mixed $args (optional) Custom property of the item. NOT the class property $args. Examples: $media, $in_footer.
|
|---|
| 121 | + * @return bool Success
|
|---|
| 122 | */
|
|---|
| 123 | function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
|
|---|
| 124 | if ( isset($this->registered[$handle]) )
|
|---|
| 125 | @@ -132,14 +151,14 @@
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /**
|
|---|
| 129 | - * Adds extra data
|
|---|
| 130 | + * Add extra data
|
|---|
| 131 | *
|
|---|
| 132 | - * Adds data only if script has already been added.
|
|---|
| 133 | + * Adds data if item has been registered.
|
|---|
| 134 | *
|
|---|
| 135 | - * @param string $handle Script name
|
|---|
| 136 | - * @param string $key
|
|---|
| 137 | - * @param mixed $value
|
|---|
| 138 | - * @return bool success
|
|---|
| 139 | + * @param string $handle Unique item name
|
|---|
| 140 | + * @param string $key Data key
|
|---|
| 141 | + * @param mixed $value Data value
|
|---|
| 142 | + * @return bool Success
|
|---|
| 143 | */
|
|---|
| 144 | function add_data( $handle, $key, $value ) {
|
|---|
| 145 | if ( !isset( $this->registered[$handle] ) )
|
|---|
| 146 | @@ -151,13 +170,13 @@
|
|---|
| 147 | /**
|
|---|
| 148 | * Get extra data
|
|---|
| 149 | *
|
|---|
| 150 | - * Gets data associated with a certain handle.
|
|---|
| 151 | + * Gets data associated with a registered item.
|
|---|
| 152 | *
|
|---|
| 153 | * @since WP 3.3
|
|---|
| 154 | *
|
|---|
| 155 | - * @param string $handle Script name
|
|---|
| 156 | - * @param string $key
|
|---|
| 157 | - * @return mixed
|
|---|
| 158 | + * @param string $handle Unique item name
|
|---|
| 159 | + * @param string $key Data key
|
|---|
| 160 | + * @return mixed Data value
|
|---|
| 161 | */
|
|---|
| 162 | function get_data( $handle, $key ) {
|
|---|
| 163 | if ( !isset( $this->registered[$handle] ) )
|
|---|
| 164 | @@ -169,11 +188,27 @@
|
|---|
| 165 | return $this->registered[$handle]->extra[$key];
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | + /**
|
|---|
| 169 | + * Unregister items
|
|---|
| 170 | + *
|
|---|
| 171 | + * @param mixed $handles (string) Item handle or (array of strings) Item handles
|
|---|
| 172 | + * @return void
|
|---|
| 173 | + */
|
|---|
| 174 | function remove( $handles ) {
|
|---|
| 175 | foreach ( (array) $handles as $handle )
|
|---|
| 176 | unset($this->registered[$handle]);
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | + /**
|
|---|
| 180 | + * Queue items
|
|---|
| 181 | + *
|
|---|
| 182 | + * Decode handle and argument, then queue handle and store argument in the class property $args.
|
|---|
| 183 | + * For example, in extending classes, $args is appended to the item url.
|
|---|
| 184 | + * Note $args is NOT the $args property of items in the $registered array.
|
|---|
| 185 | + *
|
|---|
| 186 | + * @param mixed $handles (string) Item handle and argument or (array of strings) Item handles and arguments
|
|---|
| 187 | + * @return void
|
|---|
| 188 | + */
|
|---|
| 189 | function enqueue( $handles ) {
|
|---|
| 190 | foreach ( (array) $handles as $handle ) {
|
|---|
| 191 | $handle = explode('?', $handle);
|
|---|
| 192 | @@ -185,6 +220,14 @@
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | + /**
|
|---|
| 197 | + * Dequeue items
|
|---|
| 198 | + *
|
|---|
| 199 | + * Decode handle and argument, then dequeue handle and remove argument from the class property $args.
|
|---|
| 200 | + *
|
|---|
| 201 | + * @param mixed $handles (string) Item handle and argument or (array of strings) Item handles and arguments
|
|---|
| 202 | + * @return void
|
|---|
| 203 | + */
|
|---|
| 204 | function dequeue( $handles ) {
|
|---|
| 205 | foreach ( (array) $handles as $handle ) {
|
|---|
| 206 | $handle = explode('?', $handle);
|
|---|
| 207 | @@ -196,7 +239,12 @@
|
|---|
| 208 | }
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | -
|
|---|
| 212 | + /**
|
|---|
| 213 | + * Query list for item
|
|---|
| 214 | + *
|
|---|
| 215 | + * @param $handle (string) Item handle
|
|---|
| 216 | + * @return bool Found, or object Item data
|
|---|
| 217 | + */
|
|---|
| 218 | function query( $handle, $list = 'registered' ) {
|
|---|
| 219 | switch ( $list ) {
|
|---|
| 220 | case 'registered' :
|
|---|
| 221 | @@ -220,6 +268,14 @@
|
|---|
| 222 | return false;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | + /**
|
|---|
| 226 | + * Set item group, unless already in a lower group
|
|---|
| 227 | + *
|
|---|
| 228 | + * @param $handle (string) Item handle
|
|---|
| 229 | + * @param bool $recursion Internal flag that calling function was called recusively
|
|---|
| 230 | + * @param mixed $group Group level
|
|---|
| 231 | + * @return bool Not already in the group or a lower group
|
|---|
| 232 | + */
|
|---|
| 233 | function set_group( $handle, $recursion, $group ) {
|
|---|
| 234 | $group = (int) $group;
|
|---|
| 235 |
|
|---|
| 236 | @@ -242,8 +298,7 @@
|
|---|
| 237 | var $src;
|
|---|
| 238 | var $deps = array();
|
|---|
| 239 | var $ver = false;
|
|---|
| 240 | - var $args = null;
|
|---|
| 241 | -
|
|---|
| 242 | + var $args = null; // Custom property, such as $in_footer or $media.
|
|---|
| 243 | var $extra = array();
|
|---|
| 244 |
|
|---|
| 245 | function __construct() {
|
|---|