Documentation

Script extends Asset
in package

Script Module class expanding the Asset class.

Table of Contents

Properties

$action_hook_enqueue  : ActionHook
ActionHook instance for the enqueue action.
$action_hook_register  : ActionHook
ActionHook instance for the register action.
$deps  : array<string|int, string>
Asset dependencies.
$handle  : string
Asset handle.
$register_only  : array<string|int, mixed>|null
Asset arguments.
$src  : string
Asset source.
$ver  : string|bool
Asset version.
$args  : string
An array of additional script loading strategies.

Methods

__construct()  : mixed
Constructor.
__toString()  : string
Custom toString magic method.
enqueue_script()  : void
Enqueues the script asset to WordPress.
register_script()  : void
Enqueues the script asset to WordPress.
initialize()  : void
Initializes the script asset.

Properties

$action_hook_enqueue

ActionHook instance for the enqueue action.

protected ActionHook $action_hook_enqueue

ActionHook instance for the enqueue action.

Tags
since
1.0.0

$action_hook_register

ActionHook instance for the register action.

protected ActionHook $action_hook_register

ActionHook instance for the register action.

Tags
since
1.0.0

$deps

Asset dependencies.

protected array<string|int, string> $deps

An array of registered script handles this script depends on.

Tags
see

$deps

link
https://developer.wordpress.org/reference/functions/wp_enqueue_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_enqueue_style/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_style/#parameters
since
1.0.0

$register_only

Asset arguments.

protected array<string|int, mixed>|null $register_only

Array or query string of arguments for registering a script.

Tags
see

$args

link
https://developer.wordpress.org/reference/functions/wp_enqueue_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_enqueue_style/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_style/#parameters
since
1.0.0

$src

Asset source.

protected string $src

Full URL of the script, or path of the script relative to the WordPress root directory.

Tags
see

$src

link
https://developer.wordpress.org/reference/functions/wp_enqueue_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_enqueue_style/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_style/#parameters
since
1.0.0

$ver

Asset version.

protected string|bool $ver

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.

Tags
see

$ver

link
https://developer.wordpress.org/reference/functions/wp_enqueue_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_enqueue_style/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_script/#parameters
link
https://developer.wordpress.org/reference/functions/wp_register_style/#parameters
since
1.0.0

Methods

__construct()

Constructor.

public __construct(string $handle, string $src[, array<string|int, mixed>|string $deps = array() ][, string|bool $ver = false ][, array<string|int, mixed> $args = array() ][, bool $register_only = false ][, ActionHook $action_hook_enqueue = null ][, ActionHook $action_hook_register = null ]) : mixed

Constructs the Script object by setting the handle, source, dependencies, version, args, and register_only.

Parameters
$handle : string

Name of the script. Should be unique.

$src : string

Full URL of the script, or path of the script relative to the WordPress root directory.

$deps : array<string|int, mixed>|string = array()

Optional. An array of registered script handles this script depends on. Default empty array.

$ver : string|bool = false

Optional. String specifying the script version number. If set to false, WordPress version will be used. Default false.

$args : array<string|int, mixed> = array()

Optional. An array of additional script loading strategies. Default empty array.

$register_only : bool = false

Optional. Whether to only register the script and not enqueue. Default false.

$action_hook_enqueue : ActionHook = null

Optional. ActionHook object for the wp_enqueue_scripts method. Default 'wp_enqueue_scripts'.

$action_hook_register : ActionHook = null

Optional. ActionHook object for the wp_register_script method. Default 'wp_enqueue_scripts'.

Tags
since
1.0.0

__toString()

Custom toString magic method.

public __toString() : string

Returns the script asset as a JSON string.

Tags
since
1.0.0
Return values
string

JSON string.

initialize()

Initializes the script asset.

protected initialize() : void

Calls the parent initialize method and adds the script asset to the registry.

Tags
since
1.0.0

        
On this page

Search results