[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

Dependencies API: Scripts functions

File Size: 441 lines (15 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
Initializes $wp_scripts if it has not been set.

return: WP_Scripts WP_Scripts instance.

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

param: string $function_name Function name.
param: string $handle        Optional. Name of the script or stylesheet that was

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|string[]|false $handles Optional. Scripts to be printed. Default 'false'.

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

wp_register_script( $handle, $src, $deps = array()   X-Ref
Registers 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|false     $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: array|bool       $args     {

wp_localize_script( $handle, $object_name, $l10n )   X-Ref
Localizes 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.

wp_set_script_translations( $handle, $domain = 'default', $path = '' )   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.

wp_deregister_script( $handle )   X-Ref
Removes 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.

wp_enqueue_script( $handle, $src = '', $deps = array()   X-Ref
Enqueues 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: array|bool       $args     {

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

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

wp_script_is( $handle, $status = '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 $status Optional. Status of the script to check. Default 'enqueued'.

wp_script_add_data( $handle, $key, $value )   X-Ref
Adds 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.



Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref