@@ -68,6 +68,47 @@ function _wp_scripts_maybe_doing_it_wrong( $function_name, $handle = '' ) {
6868 );
6969}
7070
71+ /**
72+ * Adds the data for the recognized args and warns for unrecognized args.
73+ *
74+ * @ignore
75+ * @since 7.0.0
76+ *
77+ * @param string $function_name Function name.
78+ * @param WP_Scripts $wp_scripts WP_Scripts instance.
79+ * @param string $handle Script handle.
80+ * @param array $args Array of extra args for the script.
81+ */
82+ function _wp_scripts_add_args_data ( string $ function_name , WP_Scripts $ wp_scripts , string $ handle , array $ args ) {
83+ $ allowed_keys = array ( 'strategy ' , 'in_footer ' , 'fetchpriority ' , 'module_dependencies ' );
84+ $ unknown_keys = array_diff ( array_keys ( $ args ), $ allowed_keys );
85+ if ( ! empty ( $ unknown_keys ) ) {
86+ _doing_it_wrong (
87+ $ function_name ,
88+ sprintf (
89+ /* translators: 1: $args, 2: List of unrecognized keys. */
90+ __ ( 'Unrecognized keys in the %1$s array: %2$s. ' ),
91+ '$args ' ,
92+ implode ( wp_get_list_item_separator (), $ unknown_keys )
93+ ),
94+ '7.0.0 '
95+ );
96+ }
97+
98+ if ( ! empty ( $ args ['in_footer ' ] ) ) {
99+ $ wp_scripts ->add_data ( $ handle , 'group ' , 1 );
100+ }
101+ if ( ! empty ( $ args ['strategy ' ] ) ) {
102+ $ wp_scripts ->add_data ( $ handle , 'strategy ' , $ args ['strategy ' ] );
103+ }
104+ if ( ! empty ( $ args ['fetchpriority ' ] ) ) {
105+ $ wp_scripts ->add_data ( $ handle , 'fetchpriority ' , $ args ['fetchpriority ' ] );
106+ }
107+ if ( ! empty ( $ args ['module_dependencies ' ] ) ) {
108+ $ wp_scripts ->add_data ( $ handle , 'module_dependencies ' , $ args ['module_dependencies ' ] );
109+ }
110+ }
111+
71112/**
72113 * Prints scripts in document head that are in the $handles queue.
73114 *
@@ -159,22 +200,24 @@ function wp_add_inline_script( $handle, $data, $position = 'after' ) {
159200 * @since 4.3.0 A return value was added.
160201 * @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
161202 * @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array.
162- *
163- * @param string $handle Name of the script. Should be unique.
164- * @param string|false $src Full URL of the script, or path of the script relative to the WordPress root directory.
165- * If source is set to false, script is an alias of other scripts it depends on.
166- * @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
167- * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
168- * as a query string for cache busting purposes. If version is set to false, a version
169- * number is automatically added equal to current installed WordPress version.
170- * If set to null, no version is added.
171- * @param array<string, string|bool>|bool $args {
172- * Optional. An array of additional script loading strategies. Default empty array.
203+ * @since 7.0.0 The $module_dependencies parameter of type string[] was added to the $args parameter of type array.
204+ *
205+ * @param string $handle Name of the script. Should be unique.
206+ * @param string|false $src Full URL of the script, or path of the script relative to the WordPress root directory.
207+ * If source is set to false, script is an alias of other scripts it depends on.
208+ * @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
209+ * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
210+ * as a query string for cache busting purposes. If version is set to false, a version
211+ * number is automatically added equal to current installed WordPress version.
212+ * If set to null, no version is added.
213+ * @param array<string, string|bool|string[]>|bool $args {
214+ * Optional. An array of extra args for the script. Default empty array.
173215 * Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
174216 *
175- * @type string $strategy Optional. If provided, may be either 'defer' or 'async'.
176- * @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'.
177- * @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'.
217+ * @type string $strategy Optional. If provided, may be either 'defer' or 'async'.
218+ * @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'.
219+ * @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'.
220+ * @type string[] $module_dependencies Optional. IDs for module dependencies loaded via dynamic import. Default empty array.
178221 * }
179222 * @return bool Whether the script has been registered. True on success, false on failure.
180223 */
@@ -189,15 +232,8 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args
189232 $ wp_scripts = wp_scripts ();
190233
191234 $ registered = $ wp_scripts ->add ( $ handle , $ src , $ deps , $ ver );
192- if ( ! empty ( $ args ['in_footer ' ] ) ) {
193- $ wp_scripts ->add_data ( $ handle , 'group ' , 1 );
194- }
195- if ( ! empty ( $ args ['strategy ' ] ) ) {
196- $ wp_scripts ->add_data ( $ handle , 'strategy ' , $ args ['strategy ' ] );
197- }
198- if ( ! empty ( $ args ['fetchpriority ' ] ) ) {
199- $ wp_scripts ->add_data ( $ handle , 'fetchpriority ' , $ args ['fetchpriority ' ] );
200- }
235+ _wp_scripts_add_args_data ( __FUNCTION__ , $ wp_scripts , $ handle , $ args );
236+
201237 return $ registered ;
202238}
203239
@@ -345,22 +381,24 @@ function wp_deregister_script( $handle ) {
345381 * @since 2.1.0
346382 * @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
347383 * @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array.
348- *
349- * @param string $handle Name of the script. Should be unique.
350- * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
351- * Default empty.
352- * @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
353- * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
354- * as a query string for cache busting purposes. If version is set to false, a version
355- * number is automatically added equal to current installed WordPress version.
356- * If set to null, no version is added.
357- * @param array<string, string|bool>|bool $args {
358- * Optional. An array of additional script loading strategies. Default empty array.
384+ * @since 7.0.0 The $module_dependencies parameter of type string[] was added to the $args parameter of type array.
385+ *
386+ * @param string $handle Name of the script. Should be unique.
387+ * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
388+ * Default empty.
389+ * @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
390+ * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
391+ * as a query string for cache busting purposes. If version is set to false, a version
392+ * number is automatically added equal to current installed WordPress version.
393+ * If set to null, no version is added.
394+ * @param array<string, string|bool|string[]>|bool $args {
395+ * Optional. An array of extra args for the script. Default empty array.
359396 * Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
360397 *
361- * @type string $strategy Optional. If provided, may be either 'defer' or 'async'.
362- * @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'.
363- * @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'.
398+ * @type string $strategy Optional. If provided, may be either 'defer' or 'async'.
399+ * @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'.
400+ * @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'.
401+ * @type string[] $module_dependencies Optional. IDs for module dependencies loaded via dynamic import. Default empty array.
364402 * }
365403 */
366404function wp_enqueue_script ( $ handle , $ src = '' , $ deps = array (), $ ver = false , $ args = array () ) {
@@ -379,14 +417,8 @@ function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $
379417 if ( $ src ) {
380418 $ wp_scripts ->add ( $ _handle [0 ], $ src , $ deps , $ ver );
381419 }
382- if ( ! empty ( $ args ['in_footer ' ] ) ) {
383- $ wp_scripts ->add_data ( $ _handle [0 ], 'group ' , 1 );
384- }
385- if ( ! empty ( $ args ['strategy ' ] ) ) {
386- $ wp_scripts ->add_data ( $ _handle [0 ], 'strategy ' , $ args ['strategy ' ] );
387- }
388- if ( ! empty ( $ args ['fetchpriority ' ] ) ) {
389- $ wp_scripts ->add_data ( $ _handle [0 ], 'fetchpriority ' , $ args ['fetchpriority ' ] );
420+ if ( ! empty ( $ args ) ) {
421+ _wp_scripts_add_args_data ( __FUNCTION__ , $ wp_scripts , $ _handle [0 ], $ args );
390422 }
391423 }
392424
0 commit comments