Opened 12 years ago
Closed 12 months ago
#20683 closed enhancement (wontfix)
WP_Dependencies' constructor should accept a string/array value for $deps rather than converting a string to an empty array
Reported by: | vhauri | Owned by: | markjaquith |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.6 |
Component: | Script Loader | Keywords: | has-patch close 2nd-opinion needs-refresh |
Focuses: | Cc: |
Description
Currently, WP_Dependencies' constructor takes any $deps value that's not an array and converts it to an empty array. I propose bringing the constructor's behavior more in line with standard WP function paramater behavior by accepting a string as a single dependency. Essentially this involves adding an is_string() check on $deps before checking if it's not an array, and creating an array with a single element in the case that it is a string.
if ( !is_array($this->deps) ) $this->deps = array();
becomes
if ( is_string( $this->deps ) ) $this->deps = (array) $this->deps; elseif ( !is_array( $this->deps ) ) $this->deps = array();
See the attached diff for a proposed patch.
Attachments (4)
Change History (24)
#1
@
12 years ago
- Keywords has-patch added
+1, but I think array( $this->deps )
is clearer than (array) $this->deps
.
#3
@
12 years ago
- Milestone changed from Awaiting Review to 3.5
- Owner set to markjaquith
- Status changed from new to accepted
Looks good. Nice common sense API improvement.
#8
@
12 years ago
- Keywords revert added
- Resolution fixed deleted
- Status changed from closed to reopened
This seemed like an easy win, but will likely be this release's hey-look-we-broke-your-scripts bug if it gets into 3.5 final. See #22111. Re-opening.
#10
@
12 years ago
From @nacin's comment on #22111, seems like it's not currently worth rocking the boat. Is it coming out or staying in?
#13
follow-up:
↓ 15
@
11 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
I don't accept that this is unsolvable.
The problem here seems to be that by allowing $deps to be a string, then somebody who had accidentally put a version there (like in #22111) would get a non-existent dependency. The code in WP_Dependency would then simply not include the code because of a missing dependency.
This problem can be solved by simply ignoring non-existent dependencies and letting the script/stylesheet load anyway. Yes, it may be broken, but it will definitely be broken if it doesn't load at all.
Dependencies define the order of loading, but we don't necessarily have to state that they will also define absolute dependence upon the defined enqueued items. If somebody has a non-existent dependency, then that's clearly a coding error, and throwing a _doing_it_wrong but loading the scripts anyway would make more sense.
Looks to me like you can just remove those checks in function all_deps, or change them to keep going anyway but throw a debugging error.
#15
in reply to:
↑ 13
@
11 years ago
Replying to Otto42:
I don't accept that this is unsolvable.
The problem here seems to be that by allowing $deps to be a string, then somebody who had accidentally put a version there (like in #22111) would get a non-existent dependency. The code in WP_Dependency would then simply not include the code because of a missing dependency.
This problem can be solved by simply ignoring non-existent dependencies and letting the script/stylesheet load anyway. Yes, it may be broken, but it will definitely be broken if it doesn't load at all.
Dependencies define the order of loading, but we don't necessarily have to state that they will also define absolute dependence upon the defined enqueued items. If somebody has a non-existent dependency, then that's clearly a coding error, and throwing a _doing_it_wrong but loading the scripts anyway would make more sense.
Surprisingly, I agree with you. Dependencies do mean that the code relies on it, but getting a Javascript error with jQuery is undefined
(e.g.) seems a little easier to debug than the script not loading at all.
#19
@
4 years ago
- Keywords close 2nd-opinion needs-refresh added; dev-feedback removed
- Milestone set to Awaiting Review
- Version set to 2.6
The latest patch needs a refresh against current trunk
.
I'm also considering just closing this out as wontfix
. WP_Depenencies
was introduced in 2.6, and specifying dependencies in array format when using wp_enqueue_script()
/wp_enqueue_style()
is now such a common practice that I don't know that the benefit of this change still exists.
Marking close
/2nd-opinion
for others to weigh in.
Patch to allow a single $deps in WP_Dependencies to be passed as a string