Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#28404 closed defect (bug) (fixed)

wp_script_is() returns false for scripts enqueued via dependencies.

Reported by: mikejolley's profile mikejolley Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.9.1
Component: Script Loader Keywords: has-patch
Focuses: Cc:


Register/enqueue a script with dependencies, e.g.

wp_enqueue_script( 'wc-cart', $src, array( 'jquery', 'wc-country-select' ), $version, true );

With the above example I've enqueued wc-cart and, via a dependency, wc-country-select. The problem is:

wp_script_is( 'wc-country-select', 'enqueued' );

will always return false. This is due to the query method in the WP_Dependencies class not checking the dependencies of each enqueued handle.

IMO this should return true. The script is enqueued via dependency - without a way to check this I cannot conditionally localize my scripts without checking all dependencies.

Fix will be attached.

Attachments (2)

fix-wp-script-is.28404.diff (736 bytes) - added by mikejolley 10 years ago.
Patch for #28404
28404.diff (758 bytes) - added by SergeyBiryukov 10 years ago.
Minor edit to avoid deep nesting

Download all attachments as: .zip

Change History (4)

10 years ago

Minor edit to avoid deep nesting

#1 @SergeyBiryukov
10 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.0

#2 @wonderboymusic
10 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 29252:

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.

Note: See TracTickets for help on using tickets.