@@ -70,6 +70,17 @@ class WP_Script_Modules {
7070 'high ' ,
7171 );
7272
73+ /**
74+ * List of IDs for script modules encountered which have missing dependencies.
75+ *
76+ * An ID is added to this list when it is discovered to have missing dependencies. At this time, a warning is
77+ * emitted with {@see _doing_it_wrong()}. The ID is then added to this list, so that duplicate warnings don't occur.
78+ *
79+ * @since 7.0.0
80+ * @var string[]
81+ */
82+ private $ modules_with_missing_dependencies = array ();
83+
7384 /**
7485 * Registers the script module if no script module with that script module
7586 * identifier has already been registered.
@@ -724,16 +735,19 @@ private function sort_item_dependencies( string $id, array $import_types, array
724735 // If the item requires dependencies that do not exist, fail.
725736 $ missing_dependencies = array_diff ( $ dependency_ids , array_keys ( $ this ->registered ) );
726737 if ( count ( $ missing_dependencies ) > 0 ) {
727- _doing_it_wrong (
728- __METHOD__ ,
729- sprintf (
738+ if ( ! in_array ( $ id , $ this ->modules_with_missing_dependencies , true ) ) {
739+ _doing_it_wrong (
740+ __METHOD__ ,
741+ sprintf (
730742 /* translators: 1: Script module ID, 2: Comma-separated list of missing dependency IDs. */
731- __ ( 'The script module "%1$s" was enqueued with dependencies that are not registered: %2$s. ' ),
732- $ id ,
733- implode ( ', ' , $ missing_dependencies )
734- ),
735- '7.0.0 '
736- );
743+ __ ( 'The script module "%1$s" was enqueued with dependencies that are not registered: %2$s. ' ),
744+ $ id ,
745+ implode ( ', ' , $ missing_dependencies )
746+ ),
747+ '7.0.0 '
748+ );
749+ $ this ->modules_with_missing_dependencies [] = $ id ;
750+ }
737751
738752 return false ;
739753 }
0 commit comments