diff -r be944660c56a -r 3d72ae0968f4 wp/wp-includes/class.wp-dependencies.php --- a/wp/wp-includes/class.wp-dependencies.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-includes/class.wp-dependencies.php Tue Sep 27 16:37:53 2022 +0200 @@ -17,33 +17,37 @@ */ class WP_Dependencies { /** - * An array of registered handle objects. + * An array of all registered dependencies keyed by handle. * * @since 2.6.8 - * @var array + * + * @var _WP_Dependency[] */ public $registered = array(); /** - * An array of handles of queued objects. + * An array of handles of queued dependencies. * * @since 2.6.8 + * * @var string[] */ public $queue = array(); /** - * An array of handles of objects to queue. + * An array of handles of dependencies to queue. * * @since 2.6.0 + * * @var string[] */ public $to_do = array(); /** - * An array of handles of objects already queued. + * An array of handles of dependencies already queued. * * @since 2.6.0 + * * @var string[] */ public $done = array(); @@ -54,15 +58,20 @@ * Arguments are appended to the item query string. * * @since 2.6.0 + * * @var array */ public $args = array(); /** - * An array of handle groups to enqueue. + * An array of dependency groups to enqueue. + * + * Each entry is keyed by handle and represents the integer group level or boolean + * false if the handle has no group. * * @since 2.8.0 - * @var array + * + * @var (int|false)[] */ public $groups = array(); @@ -70,6 +79,7 @@ * A handle group to enqueue. * * @since 2.8.0 + * * @deprecated 4.5.0 * @var int */ @@ -79,11 +89,21 @@ * Cached lookup array of flattened queued items and dependencies. * * @since 5.4.0 + * * @var array */ private $all_queued_deps; /** + * List of assets enqueued before details were registered. + * + * @since 5.9.0 + * + * @var array + */ + private $queued_before_register = array(); + + /** * Processes the items and dependencies. * * Processes the items passed to it or the queue, and their dependencies. @@ -94,7 +114,7 @@ * @param string|string[]|false $handles Optional. Items to be processed: queue (false), * single item (string), or multiple items (array of strings). * Default false. - * @param int|false $group Optional. Group level: level (int), no groups (false). + * @param int|false $group Optional. Group level: level (int), no group (false). * @return string[] Array of handles of items that have been processed. */ public function do_items( $handles = false, $group = false ) { @@ -131,7 +151,7 @@ * @since 5.5.0 Added the `$group` parameter. * * @param string $handle Name of the item. Should be unique. - * @param int|false $group Optional. Group level: level (int), no groups (false). + * @param int|false $group Optional. Group level: level (int), no group (false). * Default false. * @return bool True on success, false if not set. */ @@ -152,7 +172,7 @@ * @param string|string[] $handles Item handle (string) or item handles (array of strings). * @param bool $recursion Optional. Internal flag that function is calling itself. * Default false. - * @param int|false $group Optional. Group level: level (int), no groups (false). + * @param int|false $group Optional. Group level: level (int), no group (false). * Default false. * @return bool True on success, false on failure. */ @@ -237,6 +257,18 @@ return false; } $this->registered[ $handle ] = new _WP_Dependency( $handle, $src, $deps, $ver, $args ); + + // If the item was enqueued before the details were registered, enqueue it now. + if ( array_key_exists( $handle, $this->queued_before_register ) ) { + if ( ! is_null( $this->queued_before_register[ $handle ] ) ) { + $this->enqueue( $handle . '?' . $this->queued_before_register[ $handle ] ); + } else { + $this->enqueue( $handle ); + } + + unset( $this->queued_before_register[ $handle ] ); + } + return true; } @@ -323,6 +355,12 @@ if ( isset( $handle[1] ) ) { $this->args[ $handle[0] ] = $handle[1]; } + } elseif ( ! isset( $this->registered[ $handle[0] ] ) ) { + $this->queued_before_register[ $handle[0] ] = null; // $args + + if ( isset( $handle[1] ) ) { + $this->queued_before_register[ $handle[0] ] = $handle[1]; + } } } } @@ -349,12 +387,14 @@ unset( $this->queue[ $key ] ); unset( $this->args[ $handle[0] ] ); + } elseif ( array_key_exists( $handle[0], $this->queued_before_register ) ) { + unset( $this->queued_before_register[ $handle[0] ] ); } } } /** - * Recursively search the passed dependency tree for $handle. + * Recursively search the passed dependency tree for a handle. * * @since 4.0.0 * @@ -391,17 +431,17 @@ } /** - * Query list for an item. + * Query the list for an item. * * @since 2.1.0 * @since 2.6.0 Moved from `WP_Scripts`. * * @param string $handle Name of the item. Should be unique. - * @param string $list Optional. Property name of list array. Default 'registered'. + * @param string $status Optional. Status of the item to query. Default 'registered'. * @return bool|_WP_Dependency Found, or object Item data. */ - public function query( $handle, $list = 'registered' ) { - switch ( $list ) { + public function query( $handle, $status = 'registered' ) { + switch ( $status ) { case 'registered': case 'scripts': // Back compat. if ( isset( $this->registered[ $handle ] ) ) { @@ -410,7 +450,7 @@ return false; case 'enqueued': - case 'queue': + case 'queue': // Back compat. if ( in_array( $handle, $this->queue, true ) ) { return true; } @@ -424,6 +464,7 @@ case 'printed': // Back compat. return in_array( $handle, $this->done, true ); } + return false; } @@ -434,7 +475,7 @@ * * @param string $handle Name of the item. Should be unique. * @param bool $recursion Internal flag that calling function was called recursively. - * @param int|false $group Group level: level (int), no groups (false). + * @param int|false $group Group level: level (int), no group (false). * @return bool Not already in the group or a lower group. */ public function set_group( $handle, $recursion, $group ) {