16 * |
16 * |
17 * @access public |
17 * @access public |
18 * @since 2.6.8 |
18 * @since 2.6.8 |
19 * @var array |
19 * @var array |
20 */ |
20 */ |
21 var $registered = array(); |
21 public $registered = array(); |
22 |
22 |
23 /** |
23 /** |
24 * An array of queued _WP_Dependency handle objects. |
24 * An array of queued _WP_Dependency handle objects. |
25 * |
25 * |
26 * @access public |
26 * @access public |
27 * @since 2.6.8 |
27 * @since 2.6.8 |
28 * @var array |
28 * @var array |
29 */ |
29 */ |
30 var $queue = array(); |
30 public $queue = array(); |
31 |
31 |
32 /** |
32 /** |
33 * An array of _WP_Dependency handle objects to queue. |
33 * An array of _WP_Dependency handle objects to queue. |
34 * |
34 * |
35 * @access public |
35 * @access public |
36 * @since 2.6.0 |
36 * @since 2.6.0 |
37 * @var array |
37 * @var array |
38 */ |
38 */ |
39 var $to_do = array(); |
39 public $to_do = array(); |
40 |
40 |
41 /** |
41 /** |
42 * An array of _WP_Dependency handle objects already queued. |
42 * An array of _WP_Dependency handle objects already queued. |
43 * |
43 * |
44 * @access public |
44 * @access public |
45 * @since 2.6.0 |
45 * @since 2.6.0 |
46 * @var array |
46 * @var array |
47 */ |
47 */ |
48 var $done = array(); |
48 public $done = array(); |
49 |
49 |
50 /** |
50 /** |
51 * An array of additional arguments passed when a handle is registered. |
51 * An array of additional arguments passed when a handle is registered. |
52 * |
52 * |
53 * Arguments are appended to the item query string. |
53 * Arguments are appended to the item query string. |
54 * |
54 * |
55 * @access public |
55 * @access public |
56 * @since 2.6.0 |
56 * @since 2.6.0 |
57 * @var array |
57 * @var array |
58 */ |
58 */ |
59 var $args = array(); |
59 public $args = array(); |
60 |
60 |
61 /** |
61 /** |
62 * An array of handle groups to enqueue. |
62 * An array of handle groups to enqueue. |
63 * |
63 * |
64 * @access public |
64 * @access public |
65 * @since 2.8.0 |
65 * @since 2.8.0 |
66 * @var array |
66 * @var array |
67 */ |
67 */ |
68 var $groups = array(); |
68 public $groups = array(); |
69 |
69 |
70 /** |
70 /** |
71 * A handle group to enqueue. |
71 * A handle group to enqueue. |
72 * |
72 * |
73 * @access public |
73 * @access public |
74 * @since 2.8.0 |
74 * @since 2.8.0 |
75 * @var int |
75 * @var int |
76 */ |
76 */ |
77 var $group = 0; |
77 public $group = 0; |
78 |
78 |
79 /** |
79 /** |
80 * Process the items and dependencies. |
80 * Process the items and dependencies. |
81 * |
81 * |
82 * Processes the items passed to it or the queue, and their dependencies. |
82 * Processes the items passed to it or the queue, and their dependencies. |
87 * @param mixed $handles Optional. Items to be processed: Process queue (false), process item (string), process items (array of strings). |
87 * @param mixed $handles Optional. Items to be processed: Process queue (false), process item (string), process items (array of strings). |
88 * @param mixed $group Group level: level (int), no groups (false). |
88 * @param mixed $group Group level: level (int), no groups (false). |
89 * @return array Handles of items that have been processed. |
89 * @return array Handles of items that have been processed. |
90 */ |
90 */ |
91 public function do_items( $handles = false, $group = false ) { |
91 public function do_items( $handles = false, $group = false ) { |
92 /** |
92 /* |
93 * If nothing is passed, print the queue. If a string is passed, |
93 * If nothing is passed, print the queue. If a string is passed, |
94 * print that item. If an array is passed, print those items. |
94 * print that item. If an array is passed, print those items. |
95 */ |
95 */ |
96 $handles = false === $handles ? $this->queue : (array) $handles; |
96 $handles = false === $handles ? $this->queue : (array) $handles; |
97 $this->all_deps( $handles ); |
97 $this->all_deps( $handles ); |
98 |
98 |
99 foreach( $this->to_do as $key => $handle ) { |
99 foreach( $this->to_do as $key => $handle ) { |
100 if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) { |
100 if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) { |
101 |
101 |
102 /** |
102 /* |
103 * A single item may alias a set of items, by having dependencies, |
103 * A single item may alias a set of items, by having dependencies, |
104 * but no source. Queuing the item queues the dependencies. |
104 * but no source. Queuing the item queues the dependencies. |
105 * |
105 * |
106 * Example: The extending class WP_Scripts is used to register 'scriptaculous' as a set of registered handles: |
106 * Example: The extending class WP_Scripts is used to register 'scriptaculous' as a set of registered handles: |
107 * <code>add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) );</code> |
107 * <code>add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) );</code> |
108 * |
108 * |
109 * The src property is false. |
109 * The src property is false. |
110 **/ |
110 */ |
111 if ( ! $this->registered[$handle]->src ) { |
111 if ( ! $this->registered[$handle]->src ) { |
112 $this->done[] = $handle; |
112 $this->done[] = $handle; |
113 continue; |
113 continue; |
114 } |
114 } |
115 |
115 |
116 /** |
116 /* |
117 * Attempt to process the item. If successful, |
117 * Attempt to process the item. If successful, |
118 * add the handle to the done array. |
118 * add the handle to the done array. |
119 * |
119 * |
120 * Unset the item from the to_do array. |
120 * Unset the item from the to_do array. |
121 */ |
121 */ |
323 } |
323 } |
324 } |
324 } |
325 } |
325 } |
326 |
326 |
327 /** |
327 /** |
|
328 * Recursively search the passed dependency tree for $handle |
|
329 * |
|
330 * @since 4.0.0 |
|
331 * |
|
332 * @param array $queue An array of queued _WP_Dependency handle objects. |
|
333 * @param string $handle Name of the item. Should be unique. |
|
334 * @return boolean Whether the handle is found after recursively searching the dependency tree. |
|
335 */ |
|
336 protected function recurse_deps( $queue, $handle ) { |
|
337 foreach ( $queue as $queued ) { |
|
338 if ( ! isset( $this->registered[ $queued ] ) ) { |
|
339 continue; |
|
340 } |
|
341 |
|
342 if ( in_array( $handle, $this->registered[ $queued ]->deps ) ) { |
|
343 return true; |
|
344 } elseif ( $this->recurse_deps( $this->registered[ $queued ]->deps, $handle ) ) { |
|
345 return true; |
|
346 } |
|
347 } |
|
348 |
|
349 return false; |
|
350 } |
|
351 |
|
352 /** |
328 * Query list for an item. |
353 * Query list for an item. |
329 * |
354 * |
330 * @access public |
355 * @access public |
331 * @since 2.1.0 |
356 * @since 2.1.0 |
332 * |
357 * |
399 * |
427 * |
400 * @access public |
428 * @access public |
401 * @since 2.6.0 |
429 * @since 2.6.0 |
402 * @var null |
430 * @var null |
403 */ |
431 */ |
404 var $handle; |
432 public $handle; |
405 |
433 |
406 /** |
434 /** |
407 * The handle source. |
435 * The handle source. |
408 * |
436 * |
409 * @access public |
437 * @access public |
410 * @since 2.6.0 |
438 * @since 2.6.0 |
411 * @var null |
439 * @var null |
412 */ |
440 */ |
413 var $src; |
441 public $src; |
414 |
442 |
415 /** |
443 /** |
416 * An array of handle dependencies. |
444 * An array of handle dependencies. |
417 * |
445 * |
418 * @access public |
446 * @access public |
419 * @since 2.6.0 |
447 * @since 2.6.0 |
420 * @var array |
448 * @var array |
421 */ |
449 */ |
422 var $deps = array(); |
450 public $deps = array(); |
423 |
451 |
424 /** |
452 /** |
425 * The handle version. |
453 * The handle version. |
426 * |
454 * |
427 * Used for cache-busting. |
455 * Used for cache-busting. |
428 * |
456 * |
429 * @access public |
457 * @access public |
430 * @since 2.6.0 |
458 * @since 2.6.0 |
431 * @var bool|string |
459 * @var bool|string |
432 */ |
460 */ |
433 var $ver = false; |
461 public $ver = false; |
434 |
462 |
435 /** |
463 /** |
436 * Additional arguments for the handle. |
464 * Additional arguments for the handle. |
437 * |
465 * |
438 * @access public |
466 * @access public |
439 * @since 2.6.0 |
467 * @since 2.6.0 |
440 * @var null |
468 * @var null |
441 */ |
469 */ |
442 var $args = null; // Custom property, such as $in_footer or $media. |
470 public $args = null; // Custom property, such as $in_footer or $media. |
443 |
471 |
444 /** |
472 /** |
445 * Extra data to supply to the handle. |
473 * Extra data to supply to the handle. |
446 * |
474 * |
447 * @access public |
475 * @access public |
448 * @since 2.6.0 |
476 * @since 2.6.0 |
449 * @var array |
477 * @var array |
450 */ |
478 */ |
451 var $extra = array(); |
479 public $extra = array(); |
452 |
480 |
453 /** |
481 /** |
454 * Setup dependencies. |
482 * Setup dependencies. |
455 * |
483 * |
456 * @since 2.6.0 |
484 * @since 2.6.0 |
457 */ |
485 */ |
458 function __construct() { |
486 public function __construct() { |
459 @list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args(); |
487 @list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args(); |
460 if ( ! is_array($this->deps) ) |
488 if ( ! is_array($this->deps) ) |
461 $this->deps = array(); |
489 $this->deps = array(); |
462 } |
490 } |
463 |
491 |
469 * |
497 * |
470 * @param string $name The data key to add. |
498 * @param string $name The data key to add. |
471 * @param mixed $data The data value to add. |
499 * @param mixed $data The data value to add. |
472 * @return bool False if not scalar, true otherwise. |
500 * @return bool False if not scalar, true otherwise. |
473 */ |
501 */ |
474 function add_data( $name, $data ) { |
502 public function add_data( $name, $data ) { |
475 if ( !is_scalar($name) ) |
503 if ( !is_scalar($name) ) |
476 return false; |
504 return false; |
477 $this->extra[$name] = $data; |
505 $this->extra[$name] = $data; |
478 return true; |
506 return true; |
479 } |
507 } |