wp_enqueue_scripts',
'admin_enqueue_scripts',
'login_enqueue_scripts'
);
if ( $handle ) {
$message .= ' ' . sprintf(
/* translators: %s: Name of the script or stylesheet. */
__( 'This notice was triggered by the %s handle.' ),
'' . $handle . ''
);
}
_doing_it_wrong(
$function_name,
$message,
'3.3.0'
);
}
/**
* Adds the data for the recognized args and warns for unrecognized args.
*
* @see wp_enqueue_script()
* @see wp_register_script()
*
* @ignore
* @since 7.0.0
*
* @param WP_Scripts $wp_scripts WP_Scripts instance.
* @param string $handle Script handle.
* @param array $args Array of extra args for the script.
*
* @phpstan-param non-empty-string $handle
* @phpstan-param array{
* in_footer?: bool,
* strategy?: 'async'|'defer',
* fetchpriority?: 'low'|'auto'|'high',
* module_dependencies?: arraymodule_dependencies',
$handle,
'in_footer',
'strategy',
'defer'
),
'7.0.0'
);
}
}
}
/**
* Prints scripts in document head that are in the $handles queue.
*
* Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
* the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
* Makes use of already-instantiated `$wp_scripts` global if present. Use provided {@see 'wp_print_scripts'}
* hook to register/enqueue new scripts.
*
* @see WP_Scripts::do_item()
* @since 2.1.0
*
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
*
* @param string|string[]|false $handles Optional. Scripts to be printed. Default 'false'.
* @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
*/
function wp_print_scripts( $handles = false ) {
global $wp_scripts;
/**
* Fires before scripts in the $handles queue are printed.
*
* @since 2.1.0
*/
do_action( 'wp_print_scripts' );
if ( '' === $handles ) { // For 'wp_head'.
$handles = false;
}
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
if ( ! $handles ) {
return array(); // No need to instantiate if nothing is there.
}
}
return wp_scripts()->do_items( $handles );
}
/**
* Adds extra code to a registered script.
*
* Code will only be added if the script is already in the queue.
* Accepts a string `$data` containing the code. If two or more code blocks
* are added to the same script `$handle`, they will be printed in the order
* they were added, i.e. the latter added code can redeclare the previous.
*
* @since 4.5.0
*
* @see WP_Scripts::add_inline_script()
*
* @param string $handle Name of the script to add the inline script to.
* @param string $data String containing the JavaScript to be added.
* @param string $position Optional. Whether to add the inline script before the handle
* or after. Default 'after'.
* @return bool True on success, false on failure.
*/
function wp_add_inline_script( $handle, $data, $position = 'after' ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
if ( false !== stripos( $data, '' ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: #is', '$1', $data ) );
}
return wp_scripts()->add_inline_script( $handle, $data, $position );
}
/**
* Registers a new script.
*
* Registers a script to be enqueued later using the wp_enqueue_script() function.
*
* @see WP_Dependencies::add()
* @see WP_Dependencies::add_data()
*
* @since 2.1.0
* @since 4.3.0 A return value was added.
* @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
* @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array.
* @since 7.0.0 The $module_dependencies parameter of type string[] was added to the $args parameter of type array.
*
* @param string $handle Name of the script. Should be unique.
* @param string|false $src Full URL of the script, or path of the script relative to the WordPress root directory.
* If source is set to false, script is an alias of other scripts it depends on.
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
* as a query string for cache busting purposes. If version is set to false, a version
* number is automatically added equal to current installed WordPress version.
* If set to null, no version is added.
* @param array|bool $args {
* Optional. An array of extra args for the script. Default empty array.
* Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
*
* @type string $strategy Optional. If provided, may be either 'defer' or 'async'.
* @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'.
* @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'.
* @type array $module_dependencies Optional. IDs for module dependencies loaded via dynamic import. Default empty array.
* For the full data format, see the `$deps` param of {@see wp_register_script_module()}.
* When provided, the script must either be printed in the footer (with
* `in_footer` set to true) or use a deferred loading `strategy` (`defer`),
* so that the script modules import map is printed before the script
* is evaluated. Otherwise dynamic imports may fail to resolve.
* }
* @return bool Whether the script has been registered. True on success, false on failure.
*
* @phpstan-param non-empty-string $handle
* @phpstan-param non-empty-string|false $src
* @phpstan-param non-empty-string[] $deps
* @phpstan-param array{
* in_footer?: bool,
* strategy?: 'async'|'defer',
* fetchpriority?: 'low'|'auto'|'high',
* module_dependencies?: array$handle",
'wp_enqueue_scripts'
),
'3.6.0'
);
return;
}
}
wp_scripts()->remove( $handle );
}
/**
* Enqueues a script.
*
* Registers the script if `$src` provided (does NOT overwrite), and enqueues it.
*
* @see WP_Dependencies::add()
* @see WP_Dependencies::add_data()
* @see WP_Dependencies::enqueue()
*
* @since 2.1.0
* @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
* @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array.
* @since 7.0.0 The $module_dependencies parameter of type string[] was added to the $args parameter of type array.
*
* @param string $handle Name of the script. Should be unique.
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
* Default empty.
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
* as a query string for cache busting purposes. If version is set to false, a version
* number is automatically added equal to current installed WordPress version.
* If set to null, no version is added.
* @param array|bool $args {
* Optional. An array of extra args for the script. Default empty array.
* Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
*
* @type string $strategy Optional. If provided, may be either 'defer' or 'async'.
* @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'.
* @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'.
* @type array $module_dependencies Optional. IDs for module dependencies loaded via dynamic import. Default empty array.
* For the full data format, see the `$deps` param of {@see wp_register_script_module()}.
* When provided, the script must either be printed in the footer (with
* `in_footer` set to true) or use a deferred loading `strategy` (`defer`),
* so that the script modules import map is printed before the script
* is evaluated. Otherwise dynamic imports may fail to resolve.
* }
*
* @phpstan-param non-empty-string $handle
* @phpstan-param string $src
* @phpstan-param non-empty-string[] $deps
* @phpstan-param array{
* in_footer?: bool,
* strategy?: 'async'|'defer',
* fetchpriority?: 'low'|'auto'|'high',
* module_dependencies?: array