[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> functions.wp-scripts.php (summary)

Dependencies API: Scripts functions

File Size: 421 lines (13 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 12 functions

  wp_scripts()
  _wp_scripts_maybe_doing_it_wrong()
  wp_print_scripts()
  wp_add_inline_script()
  wp_register_script()
  wp_localize_script()
  wp_set_script_translations()
  wp_deregister_script()
  wp_enqueue_script()
  wp_dequeue_script()
  wp_script_is()
  wp_script_add_data()

Functions
Functions that are not part of a class:

wp_scripts()   X-Ref
Initialize $wp_scripts if it has not been set.

return: WP_Scripts WP_Scripts instance.
since: 4.2.0

_wp_scripts_maybe_doing_it_wrong( $function, $handle = '' )   X-Ref
Helper function to output a _doing_it_wrong message when applicable.

param: string $function Function name.
param: string $handle   Optional. Name of the script or stylesheet that was
since: 4.2.0
since: 5.5.0 Added the `$handle` parameter.

wp_print_scripts( $handles = false )   X-Ref
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.

return: string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
param: string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
since: 2.1.0

wp_add_inline_script( $handle, $data, $position = 'after' )   X-Ref
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.

return: bool True on success, false on failure.
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
since: 4.5.0

wp_register_script( $handle, $src, $deps = array()   X-Ref
Register a new script.

Registers a script to be enqueued later using the wp_enqueue_script() function.

return: bool Whether the script has been registered. True on success, false on failure.
param: string           $handle    Name of the script. Should be unique.
param: string|bool      $src       Full URL of the script, or path of the script relative to the WordPress root directory.
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
param: bool             $in_footer Optional. Whether to enqueue the script before `</body>` instead of in the `<head>`.
since: 2.1.0
since: 4.3.0 A return value was added.

wp_localize_script( $handle, $object_name, $l10n )   X-Ref
Localize a script.

Works only if the script has already been registered.

Accepts an associative array $l10n and creates a JavaScript object:

"$object_name" = {
key: value,
key: value,
...
}

return: bool True if the script was successfully localized, false otherwise.
param: string $handle      Script handle the data will be attached to.
param: string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
param: array  $l10n        The data itself. The data can be either a single or multi-dimensional array.
since: 2.2.0

wp_set_script_translations( $handle, $domain = 'default', $path = null )   X-Ref
Sets translated strings for a script.

Works only if the script has already been registered.

return: bool True if the text domain was successfully localized, false otherwise.
param: string $handle Script handle the textdomain will be attached to.
param: string $domain Optional. Text domain. Default 'default'.
param: string $path   Optional. The full file path to the directory containing translation files.
since: 5.0.0
since: 5.1.0 The `$domain` parameter was made optional.

wp_deregister_script( $handle )   X-Ref
Remove a registered script.

Note: there are intentional safeguards in place to prevent critical admin scripts,
such as jQuery core, from being unregistered.

param: string $handle Name of the script to be removed.
since: 2.1.0

wp_enqueue_script( $handle, $src = '', $deps = array()   X-Ref
Enqueue a script.

Registers the script if $src provided (does NOT overwrite), and enqueues it.

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.
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
param: bool             $in_footer Optional. Whether to enqueue the script before `</body>` instead of in the `<head>`.
since: 2.1.0

wp_dequeue_script( $handle )   X-Ref
Remove a previously enqueued script.

param: string $handle Name of the script to be removed.
since: 3.1.0

wp_script_is( $handle, $list = 'enqueued' )   X-Ref
Determines whether a script has been added to the queue.

For more information on this and similar theme functions, check out
the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
Conditional Tags} article in the Theme Developer Handbook.

return: bool Whether the script is queued.
param: string $handle Name of the script.
param: string $list   Optional. Status of the script to check. Default 'enqueued'.
since: 2.8.0
since: 3.5.0 'enqueued' added as an alias of the 'queue' list.

wp_script_add_data( $handle, $key, $value )   X-Ref
Add metadata to a script.

Works only if the script has already been registered.

Possible values for $key and $value:
'conditional' string Comments for IE 6, lte IE 7, etc.

return: bool True on success, false on failure.
param: string $handle Name of the script.
param: string $key    Name of data point for which we're storing a value.
param: mixed  $value  String containing the data to be added.
since: 4.2.0



Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1