Opened 12 years ago
Closed 8 years ago
#23816 closed enhancement (maybelater)
wp_enqueue_script|style() dependency failures are silent
Reported by: | johnbillion | Owned by: | rmccue |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Script Loader | Keywords: | needs-docs needs-patch |
Focuses: | Cc: |
Description (last modified by )
If I call wp_enqueue_script()
or wp_enqueue_style()
with a dependency that doesn't exist then I don't get told about it.
Example:
wp_enqueue_script( 'my-script', get_stylesheet_directory_uri() . '/my-script.js', array( 'script-that-does-not-exist' ) );
Actual result: nothing is enqueued, and no notices are thrown.
Expected result: When WP_DEBUG
is true, I should get a PHP notice warning me that the dependency script doesn't exist.
Attachments (3)
Change History (16)
#2
in reply to:
↑ 1
@
12 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Replying to SergeyBiryukov:
Could not reproduce that. The script was not enqueued.
Confirmed. Enqueing a file with a missing dependency does not enqueue the file. I'm not sure what I was doing.
#3
@
10 years ago
- Component changed from General to Script Loader
- Description modified (diff)
- Milestone set to Awaiting Review
- Priority changed from low to normal
- Resolution invalid deleted
- Status changed from closed to reopened
Opening this back up. The original report is mostly valid. If you register/enqueue something with a bad dependency, you get silent failure. Nothing is output, and no notices are thrown. I typo'd 'wp-utils' instead of 'wp-util' and it was maddening trying to figure out why no scripts were printing.
#4
@
10 years ago
Constantly running into this. Added a patch that fires an action here, allowing tooling to report a broken dependency chain, but this doesn't report anything in core. We might want to move this into the subclasses instead and simply call it from the parent to allow more specific hooks, plus differentiation between scripts and styles.
(Note: this file is technically part of BackPress, so I'm not sure if we should be doing something with actions. There aren't any in the file currently. That said, BackPress hasn't been synched in a long time, so I don't think it's an issue.)
We could also add a default handler into core that outputs these as HTML comments if you have WP_DEBUG
on and we're doing_action( 'wp_head' )
#5
@
10 years ago
- Keywords has-patch added
Updated patch; now adds wp_scripts_missing_dependency
and wp_styles_missing_dependency
as separate filters.
#6
follow-up:
↓ 7
@
10 years ago
- Keywords needs-docs added
We might as well go the whole hog and add a default hook onto those actions which triggers a PHP notice when WP_DEBUG
is on.
The third parameter needs adding to the hook docs too.
#7
in reply to:
↑ 6
@
10 years ago
Replying to johnbillion:
We might as well go the whole hog and add a default hook onto those actions which triggers a PHP notice when
WP_DEBUG
is on.
The third parameter needs adding to the hook docs too.
Fixed on both by doing it inline, ala _doing_it_wrong
/_deprecated_{file,function}
. Can switch to a default filter if you'd prefer, but it's not really reusable code since it has different messages for each.
#8
@
10 years ago
- Keywords needs-patch added; has-patch removed
Ran into an issue with this one. Dependency resolution takes place for all scripts in the header, and again in the footer. If you register a script to output in the footer, but it depends on something registered after wp_head
, you get an error despite the script being output correctly.
We need to take this into account when passing in $handles
to all_deps
; an array_filter
should suffice.
#11
@
9 years ago
- Keywords needs-patch added; has-patch needs-refresh removed
Determining whether an asset actually has a missing dependency is not that straight forward. Query Monitor has a component which detects broken dependencies and handles the header/footer situation that Ryan mentioned above.
Could not reproduce that. My steps:
js/my-script.js
file in Twenty Thirteen child theme.functions.php
:'script-that-does-not-exist'
with'jquery'
, the script was enqueued.