WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/20/2014 12:28:57 AM (6 years ago)
Author:
wonderboymusic
Message:

wp_script_is( ..., 'enqueued' ) needs to check dependencies recursively - a single item's dependencies may only be a subset of the full dependency tree. Adds a new method on WP_Dependencies called ->recurse_deps().

Adds unit test.

Props wonderboymusic, SergeyBiryukov, mikejolley.
Fixes #28404.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-dependencies.php

    r28517 r29252  
    326326
    327327    /**
     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            } else {
     345                return $this->recurse_deps( $this->registered[ $queued ]->deps, $handle );
     346            }
     347        }
     348
     349        return false;
     350    }
     351
     352    /**
    328353     * Query list for an item.
    329354     *
     
    345370            case 'enqueued' :
    346371            case 'queue' :
    347                 return in_array( $handle, $this->queue );
     372                if ( in_array( $handle, $this->queue ) ) {
     373                    return true;
     374                }
     375                return $this->recurse_deps( $this->queue, $handle );
    348376
    349377            case 'to_do' :
Note: See TracChangeset for help on using the changeset viewer.