Make WordPress Core

Changeset 29252


Ignore:
Timestamp:
07/20/2014 12:28:57 AM (10 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.

Location:
trunk
Files:
2 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' :
  • trunk/tests/phpunit/tests/dependencies/jquery.php

    r25785 r29252  
    7070        $this->assertFalse( strpos( $contents, 'sourceMappingURL' ), 'Presence of sourceMappingURL' );
    7171    }
     72
     73    /**
     74     * @ticket 28404
     75     */
     76    function test_wp_script_is_dep_enqueued() {
     77        wp_enqueue_script( 'jquery-ui-accordion' );
     78
     79        $this->assertTrue( wp_script_is( 'jquery', 'enqueued' ) );
     80        $this->assertFalse( wp_script_is( 'underscore', 'enqueued' ) );
     81
     82        unset( $GLOBALS['wp_scripts'] );
     83    }
    7284}
Note: See TracChangeset for help on using the changeset viewer.