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