author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 16 | a86126ab1dd4 |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Dependencies API: WP_Dependencies base class |
0 | 4 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @since 2.6.0 |
0 | 6 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @package WordPress |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
* @subpackage Dependencies |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* Core base class extended to register items. |
0 | 13 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @see _WP_Dependency |
0 | 17 |
*/ |
18 |
class WP_Dependencies { |
|
19 |
/** |
|
19 | 20 |
* An array of all registered dependencies keyed by handle. |
0 | 21 |
* |
22 |
* @since 2.6.8 |
|
19 | 23 |
* |
24 |
* @var _WP_Dependency[] |
|
0 | 25 |
*/ |
5 | 26 |
public $registered = array(); |
0 | 27 |
|
28 |
/** |
|
19 | 29 |
* An array of handles of queued dependencies. |
0 | 30 |
* |
31 |
* @since 2.6.8 |
|
19 | 32 |
* |
16 | 33 |
* @var string[] |
0 | 34 |
*/ |
5 | 35 |
public $queue = array(); |
0 | 36 |
|
37 |
/** |
|
19 | 38 |
* An array of handles of dependencies to queue. |
0 | 39 |
* |
40 |
* @since 2.6.0 |
|
19 | 41 |
* |
16 | 42 |
* @var string[] |
0 | 43 |
*/ |
5 | 44 |
public $to_do = array(); |
0 | 45 |
|
46 |
/** |
|
19 | 47 |
* An array of handles of dependencies already queued. |
0 | 48 |
* |
49 |
* @since 2.6.0 |
|
19 | 50 |
* |
16 | 51 |
* @var string[] |
0 | 52 |
*/ |
5 | 53 |
public $done = array(); |
0 | 54 |
|
55 |
/** |
|
56 |
* An array of additional arguments passed when a handle is registered. |
|
57 |
* |
|
58 |
* Arguments are appended to the item query string. |
|
59 |
* |
|
60 |
* @since 2.6.0 |
|
19 | 61 |
* |
0 | 62 |
* @var array |
63 |
*/ |
|
5 | 64 |
public $args = array(); |
0 | 65 |
|
66 |
/** |
|
19 | 67 |
* An array of dependency groups to enqueue. |
68 |
* |
|
69 |
* Each entry is keyed by handle and represents the integer group level or boolean |
|
70 |
* false if the handle has no group. |
|
0 | 71 |
* |
72 |
* @since 2.8.0 |
|
19 | 73 |
* |
74 |
* @var (int|false)[] |
|
0 | 75 |
*/ |
5 | 76 |
public $groups = array(); |
0 | 77 |
|
78 |
/** |
|
79 |
* A handle group to enqueue. |
|
80 |
* |
|
81 |
* @since 2.8.0 |
|
19 | 82 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* @deprecated 4.5.0 |
0 | 84 |
* @var int |
85 |
*/ |
|
5 | 86 |
public $group = 0; |
0 | 87 |
|
88 |
/** |
|
16 | 89 |
* Cached lookup array of flattened queued items and dependencies. |
90 |
* |
|
91 |
* @since 5.4.0 |
|
19 | 92 |
* |
16 | 93 |
* @var array |
94 |
*/ |
|
95 |
private $all_queued_deps; |
|
96 |
||
97 |
/** |
|
19 | 98 |
* List of assets enqueued before details were registered. |
99 |
* |
|
100 |
* @since 5.9.0 |
|
101 |
* |
|
102 |
* @var array |
|
103 |
*/ |
|
104 |
private $queued_before_register = array(); |
|
105 |
||
106 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
* Processes the items and dependencies. |
0 | 108 |
* |
109 |
* Processes the items passed to it or the queue, and their dependencies. |
|
110 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
* @since 2.8.0 Added the `$group` parameter. |
0 | 113 |
* |
16 | 114 |
* @param string|string[]|false $handles Optional. Items to be processed: queue (false), |
115 |
* single item (string), or multiple items (array of strings). |
|
116 |
* Default false. |
|
19 | 117 |
* @param int|false $group Optional. Group level: level (int), no group (false). |
16 | 118 |
* @return string[] Array of handles of items that have been processed. |
0 | 119 |
*/ |
120 |
public function do_items( $handles = false, $group = false ) { |
|
5 | 121 |
/* |
0 | 122 |
* If nothing is passed, print the queue. If a string is passed, |
123 |
* print that item. If an array is passed, print those items. |
|
124 |
*/ |
|
125 |
$handles = false === $handles ? $this->queue : (array) $handles; |
|
126 |
$this->all_deps( $handles ); |
|
127 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
foreach ( $this->to_do as $key => $handle ) { |
9 | 129 |
if ( ! in_array( $handle, $this->done, true ) && isset( $this->registered[ $handle ] ) ) { |
5 | 130 |
/* |
0 | 131 |
* Attempt to process the item. If successful, |
132 |
* add the handle to the done array. |
|
133 |
* |
|
134 |
* Unset the item from the to_do array. |
|
135 |
*/ |
|
9 | 136 |
if ( $this->do_item( $handle, $group ) ) { |
0 | 137 |
$this->done[] = $handle; |
9 | 138 |
} |
0 | 139 |
|
9 | 140 |
unset( $this->to_do[ $key ] ); |
0 | 141 |
} |
142 |
} |
|
143 |
||
144 |
return $this->done; |
|
145 |
} |
|
146 |
||
147 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
* Processes a dependency. |
0 | 149 |
* |
150 |
* @since 2.6.0 |
|
16 | 151 |
* @since 5.5.0 Added the `$group` parameter. |
0 | 152 |
* |
16 | 153 |
* @param string $handle Name of the item. Should be unique. |
19 | 154 |
* @param int|false $group Optional. Group level: level (int), no group (false). |
16 | 155 |
* Default false. |
0 | 156 |
* @return bool True on success, false if not set. |
157 |
*/ |
|
16 | 158 |
public function do_item( $handle, $group = false ) { |
9 | 159 |
return isset( $this->registered[ $handle ] ); |
0 | 160 |
} |
161 |
||
162 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* Determines dependencies. |
0 | 164 |
* |
165 |
* Recursively builds an array of items to process taking |
|
166 |
* dependencies into account. Does NOT catch infinite loops. |
|
167 |
* |
|
168 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
* @since 2.6.0 Moved from `WP_Scripts`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* @since 2.8.0 Added the `$group` parameter. |
0 | 171 |
* |
16 | 172 |
* @param string|string[] $handles Item handle (string) or item handles (array of strings). |
173 |
* @param bool $recursion Optional. Internal flag that function is calling itself. |
|
174 |
* Default false. |
|
19 | 175 |
* @param int|false $group Optional. Group level: level (int), no group (false). |
16 | 176 |
* Default false. |
0 | 177 |
* @return bool True on success, false on failure. |
178 |
*/ |
|
179 |
public function all_deps( $handles, $recursion = false, $group = false ) { |
|
16 | 180 |
$handles = (array) $handles; |
181 |
if ( ! $handles ) { |
|
0 | 182 |
return false; |
9 | 183 |
} |
0 | 184 |
|
185 |
foreach ( $handles as $handle ) { |
|
9 | 186 |
$handle_parts = explode( '?', $handle ); |
187 |
$handle = $handle_parts[0]; |
|
188 |
$queued = in_array( $handle, $this->to_do, true ); |
|
0 | 189 |
|
16 | 190 |
if ( in_array( $handle, $this->done, true ) ) { // Already done. |
0 | 191 |
continue; |
9 | 192 |
} |
0 | 193 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
$moved = $this->set_group( $handle, $recursion, $group ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
$new_group = $this->groups[ $handle ]; |
0 | 196 |
|
16 | 197 |
if ( $queued && ! $moved ) { // Already queued and in the right group. |
0 | 198 |
continue; |
9 | 199 |
} |
0 | 200 |
|
201 |
$keep_going = true; |
|
9 | 202 |
if ( ! isset( $this->registered[ $handle ] ) ) { |
0 | 203 |
$keep_going = false; // Item doesn't exist. |
9 | 204 |
} elseif ( $this->registered[ $handle ]->deps && array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) ) ) { |
0 | 205 |
$keep_going = false; // Item requires dependencies that don't exist. |
9 | 206 |
} elseif ( $this->registered[ $handle ]->deps && ! $this->all_deps( $this->registered[ $handle ]->deps, true, $new_group ) ) { |
0 | 207 |
$keep_going = false; // Item requires dependencies that don't exist. |
9 | 208 |
} |
0 | 209 |
|
210 |
if ( ! $keep_going ) { // Either item or its dependencies don't exist. |
|
9 | 211 |
if ( $recursion ) { |
0 | 212 |
return false; // Abort this branch. |
9 | 213 |
} else { |
0 | 214 |
continue; // We're at the top level. Move on to the next one. |
9 | 215 |
} |
0 | 216 |
} |
217 |
||
9 | 218 |
if ( $queued ) { // Already grabbed it and its dependencies. |
0 | 219 |
continue; |
9 | 220 |
} |
0 | 221 |
|
9 | 222 |
if ( isset( $handle_parts[1] ) ) { |
223 |
$this->args[ $handle ] = $handle_parts[1]; |
|
224 |
} |
|
0 | 225 |
|
226 |
$this->to_do[] = $handle; |
|
227 |
} |
|
228 |
||
229 |
return true; |
|
230 |
} |
|
231 |
||
232 |
/** |
|
233 |
* Register an item. |
|
234 |
* |
|
235 |
* Registers the item if no item of that name already exists. |
|
236 |
* |
|
237 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* @since 2.6.0 Moved from `WP_Scripts`. |
0 | 239 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* @param string $handle Name of the item. Should be unique. |
16 | 241 |
* @param string|bool $src Full URL of the item, or path of the item relative |
242 |
* to the WordPress root directory. If source is set to false, |
|
243 |
* item is an alias of other items it depends on. |
|
244 |
* @param string[] $deps Optional. An array of registered item handles this item depends on. |
|
245 |
* Default empty array. |
|
246 |
* @param string|bool|null $ver Optional. String specifying item version number, if it has one, |
|
247 |
* which is added to the URL as a query string for cache busting purposes. |
|
248 |
* If version is set to false, a version number is automatically added |
|
249 |
* equal to current installed WordPress version. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* If set to null, no version is added. |
16 | 251 |
* @param mixed $args Optional. Custom property of the item. NOT the class property $args. |
252 |
* Examples: $media, $in_footer. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* @return bool Whether the item has been registered. True on success, false on failure. |
0 | 254 |
*/ |
255 |
public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) { |
|
9 | 256 |
if ( isset( $this->registered[ $handle ] ) ) { |
0 | 257 |
return false; |
9 | 258 |
} |
259 |
$this->registered[ $handle ] = new _WP_Dependency( $handle, $src, $deps, $ver, $args ); |
|
19 | 260 |
|
261 |
// If the item was enqueued before the details were registered, enqueue it now. |
|
262 |
if ( array_key_exists( $handle, $this->queued_before_register ) ) { |
|
263 |
if ( ! is_null( $this->queued_before_register[ $handle ] ) ) { |
|
264 |
$this->enqueue( $handle . '?' . $this->queued_before_register[ $handle ] ); |
|
265 |
} else { |
|
266 |
$this->enqueue( $handle ); |
|
267 |
} |
|
268 |
||
269 |
unset( $this->queued_before_register[ $handle ] ); |
|
270 |
} |
|
271 |
||
0 | 272 |
return true; |
273 |
} |
|
274 |
||
275 |
/** |
|
276 |
* Add extra item data. |
|
277 |
* |
|
278 |
* Adds data to a registered item. |
|
279 |
* |
|
280 |
* @since 2.6.0 |
|
281 |
* |
|
282 |
* @param string $handle Name of the item. Should be unique. |
|
283 |
* @param string $key The data key. |
|
284 |
* @param mixed $value The data value. |
|
285 |
* @return bool True on success, false on failure. |
|
286 |
*/ |
|
287 |
public function add_data( $handle, $key, $value ) { |
|
9 | 288 |
if ( ! isset( $this->registered[ $handle ] ) ) { |
0 | 289 |
return false; |
9 | 290 |
} |
0 | 291 |
|
9 | 292 |
return $this->registered[ $handle ]->add_data( $key, $value ); |
0 | 293 |
} |
294 |
||
295 |
/** |
|
296 |
* Get extra item data. |
|
297 |
* |
|
298 |
* Gets data associated with a registered item. |
|
299 |
* |
|
300 |
* @since 3.3.0 |
|
301 |
* |
|
302 |
* @param string $handle Name of the item. Should be unique. |
|
303 |
* @param string $key The data key. |
|
304 |
* @return mixed Extra item data (string), false otherwise. |
|
305 |
*/ |
|
306 |
public function get_data( $handle, $key ) { |
|
9 | 307 |
if ( ! isset( $this->registered[ $handle ] ) ) { |
0 | 308 |
return false; |
9 | 309 |
} |
0 | 310 |
|
9 | 311 |
if ( ! isset( $this->registered[ $handle ]->extra[ $key ] ) ) { |
0 | 312 |
return false; |
9 | 313 |
} |
0 | 314 |
|
9 | 315 |
return $this->registered[ $handle ]->extra[ $key ]; |
0 | 316 |
} |
317 |
||
318 |
/** |
|
319 |
* Un-register an item or items. |
|
320 |
* |
|
321 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* @since 2.6.0 Moved from `WP_Scripts`. |
0 | 323 |
* |
16 | 324 |
* @param string|string[] $handles Item handle (string) or item handles (array of strings). |
0 | 325 |
*/ |
326 |
public function remove( $handles ) { |
|
9 | 327 |
foreach ( (array) $handles as $handle ) { |
328 |
unset( $this->registered[ $handle ] ); |
|
329 |
} |
|
0 | 330 |
} |
331 |
||
332 |
/** |
|
333 |
* Queue an item or items. |
|
334 |
* |
|
335 |
* Decodes handles and arguments, then queues handles and stores |
|
336 |
* arguments in the class property $args. For example in extending |
|
337 |
* classes, $args is appended to the item url as a query string. |
|
338 |
* Note $args is NOT the $args property of items in the $registered array. |
|
339 |
* |
|
340 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
* @since 2.6.0 Moved from `WP_Scripts`. |
0 | 342 |
* |
16 | 343 |
* @param string|string[] $handles Item handle (string) or item handles (array of strings). |
0 | 344 |
*/ |
345 |
public function enqueue( $handles ) { |
|
346 |
foreach ( (array) $handles as $handle ) { |
|
9 | 347 |
$handle = explode( '?', $handle ); |
16 | 348 |
|
349 |
if ( ! in_array( $handle[0], $this->queue, true ) && isset( $this->registered[ $handle[0] ] ) ) { |
|
0 | 350 |
$this->queue[] = $handle[0]; |
16 | 351 |
|
352 |
// Reset all dependencies so they must be recalculated in recurse_deps(). |
|
353 |
$this->all_queued_deps = null; |
|
354 |
||
9 | 355 |
if ( isset( $handle[1] ) ) { |
356 |
$this->args[ $handle[0] ] = $handle[1]; |
|
357 |
} |
|
19 | 358 |
} elseif ( ! isset( $this->registered[ $handle[0] ] ) ) { |
359 |
$this->queued_before_register[ $handle[0] ] = null; // $args |
|
360 |
||
361 |
if ( isset( $handle[1] ) ) { |
|
362 |
$this->queued_before_register[ $handle[0] ] = $handle[1]; |
|
363 |
} |
|
0 | 364 |
} |
365 |
} |
|
366 |
} |
|
367 |
||
368 |
/** |
|
369 |
* Dequeue an item or items. |
|
370 |
* |
|
371 |
* Decodes handles and arguments, then dequeues handles |
|
372 |
* and removes arguments from the class property $args. |
|
373 |
* |
|
374 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* @since 2.6.0 Moved from `WP_Scripts`. |
0 | 376 |
* |
16 | 377 |
* @param string|string[] $handles Item handle (string) or item handles (array of strings). |
0 | 378 |
*/ |
379 |
public function dequeue( $handles ) { |
|
380 |
foreach ( (array) $handles as $handle ) { |
|
9 | 381 |
$handle = explode( '?', $handle ); |
16 | 382 |
$key = array_search( $handle[0], $this->queue, true ); |
383 |
||
0 | 384 |
if ( false !== $key ) { |
16 | 385 |
// Reset all dependencies so they must be recalculated in recurse_deps(). |
386 |
$this->all_queued_deps = null; |
|
387 |
||
9 | 388 |
unset( $this->queue[ $key ] ); |
389 |
unset( $this->args[ $handle[0] ] ); |
|
19 | 390 |
} elseif ( array_key_exists( $handle[0], $this->queued_before_register ) ) { |
391 |
unset( $this->queued_before_register[ $handle[0] ] ); |
|
0 | 392 |
} |
393 |
} |
|
394 |
} |
|
395 |
||
396 |
/** |
|
19 | 397 |
* Recursively search the passed dependency tree for a handle. |
5 | 398 |
* |
399 |
* @since 4.0.0 |
|
400 |
* |
|
9 | 401 |
* @param string[] $queue An array of queued _WP_Dependency handles. |
402 |
* @param string $handle Name of the item. Should be unique. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
* @return bool Whether the handle is found after recursively searching the dependency tree. |
5 | 404 |
*/ |
405 |
protected function recurse_deps( $queue, $handle ) { |
|
16 | 406 |
if ( isset( $this->all_queued_deps ) ) { |
407 |
return isset( $this->all_queued_deps[ $handle ] ); |
|
5 | 408 |
} |
409 |
||
16 | 410 |
$all_deps = array_fill_keys( $queue, true ); |
411 |
$queues = array(); |
|
412 |
$done = array(); |
|
413 |
||
414 |
while ( $queue ) { |
|
415 |
foreach ( $queue as $queued ) { |
|
416 |
if ( ! isset( $done[ $queued ] ) && isset( $this->registered[ $queued ] ) ) { |
|
417 |
$deps = $this->registered[ $queued ]->deps; |
|
418 |
if ( $deps ) { |
|
419 |
$all_deps += array_fill_keys( $deps, true ); |
|
420 |
array_push( $queues, $deps ); |
|
421 |
} |
|
422 |
$done[ $queued ] = true; |
|
423 |
} |
|
424 |
} |
|
425 |
$queue = array_pop( $queues ); |
|
426 |
} |
|
427 |
||
428 |
$this->all_queued_deps = $all_deps; |
|
429 |
||
430 |
return isset( $this->all_queued_deps[ $handle ] ); |
|
5 | 431 |
} |
432 |
||
433 |
/** |
|
19 | 434 |
* Query the list for an item. |
0 | 435 |
* |
436 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* @since 2.6.0 Moved from `WP_Scripts`. |
0 | 438 |
* |
439 |
* @param string $handle Name of the item. Should be unique. |
|
19 | 440 |
* @param string $status Optional. Status of the item to query. Default 'registered'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
* @return bool|_WP_Dependency Found, or object Item data. |
0 | 442 |
*/ |
19 | 443 |
public function query( $handle, $status = 'registered' ) { |
444 |
switch ( $status ) { |
|
9 | 445 |
case 'registered': |
16 | 446 |
case 'scripts': // Back compat. |
9 | 447 |
if ( isset( $this->registered[ $handle ] ) ) { |
0 | 448 |
return $this->registered[ $handle ]; |
9 | 449 |
} |
0 | 450 |
return false; |
451 |
||
9 | 452 |
case 'enqueued': |
19 | 453 |
case 'queue': // Back compat. |
16 | 454 |
if ( in_array( $handle, $this->queue, true ) ) { |
5 | 455 |
return true; |
456 |
} |
|
457 |
return $this->recurse_deps( $this->queue, $handle ); |
|
0 | 458 |
|
9 | 459 |
case 'to_do': |
16 | 460 |
case 'to_print': // Back compat. |
461 |
return in_array( $handle, $this->to_do, true ); |
|
0 | 462 |
|
9 | 463 |
case 'done': |
16 | 464 |
case 'printed': // Back compat. |
465 |
return in_array( $handle, $this->done, true ); |
|
0 | 466 |
} |
19 | 467 |
|
0 | 468 |
return false; |
469 |
} |
|
470 |
||
471 |
/** |
|
472 |
* Set item group, unless already in a lower group. |
|
473 |
* |
|
474 |
* @since 2.8.0 |
|
475 |
* |
|
16 | 476 |
* @param string $handle Name of the item. Should be unique. |
477 |
* @param bool $recursion Internal flag that calling function was called recursively. |
|
19 | 478 |
* @param int|false $group Group level: level (int), no group (false). |
16 | 479 |
* @return bool Not already in the group or a lower group. |
0 | 480 |
*/ |
481 |
public function set_group( $handle, $recursion, $group ) { |
|
482 |
$group = (int) $group; |
|
483 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
if ( isset( $this->groups[ $handle ] ) && $this->groups[ $handle ] <= $group ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
} |
0 | 487 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
$this->groups[ $handle ] = $group; |
0 | 489 |
|
490 |
return true; |
|
491 |
} |
|
492 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
} |