Skip to content

Commit bc18fd0

Browse files
committed
Scripts: Add warning when enqueued with missing dependencies.
1 parent e1a8c92 commit bc18fd0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/wp-includes/class-wp-dependencies.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,27 @@ public function all_deps( $handles, $recursion = false, $group = false ) {
200200
}
201201

202202
$keep_going = true;
203+
$missing_dependencies = ( isset( $this->registered[ $handle ] ) && $this->registered[ $handle ]->deps ) ? array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) ) : array();
203204
if ( ! isset( $this->registered[ $handle ] ) ) {
204205
$keep_going = false; // Item doesn't exist.
205-
} elseif ( $this->registered[ $handle ]->deps && array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) ) ) {
206+
} elseif ( $missing_dependencies ) {
207+
// Prevent duplicate notices.
208+
static $reported = array();
209+
210+
if ( ! isset( $reported[ $handle ] ) ) {
211+
$reported[ $handle ] = true;
212+
213+
_doing_it_wrong(
214+
__METHOD__,
215+
sprintf(
216+
/* translators: 1: Script module ID, 2: Comma-separated list of missing dependency IDs. */
217+
__( 'The script with the handle %1$s was enqueued with dependencies that are not registered: %2$s.' ),
218+
$handle,
219+
implode( ', ', $missing_dependencies )
220+
),
221+
'7.0.0'
222+
);
223+
}
206224
$keep_going = false; // Item requires dependencies that don't exist.
207225
} elseif ( $this->registered[ $handle ]->deps && ! $this->all_deps( $this->registered[ $handle ]->deps, true, $new_group ) ) {
208226
$keep_going = false; // Item requires dependencies that don't exist.

0 commit comments

Comments
 (0)