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
$action_hook_register
ActionHook instance for the register action.
protected
ActionHook
$action_hook_register
ActionHook instance for the register action.
Tags
$deps
Asset dependencies.
protected
array<string|int, string>
$deps
An array of registered script handles this script depends on.
Tags
$handle
Asset handle.
protected
string
$handle
Name of the script. Should be unique.
Tags
$register_only
Asset arguments.
protected
array<string|int, mixed>|null
$register_only
Array or query string of arguments for registering a script.
Tags
$src
Asset source.
protected
string
$src
Full URL of the script, or path of the script relative to the WordPress root directory.
Tags
$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
$args
An array of additional script loading strategies.
private
string
$args
Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like ‘(orientation: portrait)’ and ‘(max-width: 640px)’. Default:'all'
Tags
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
__toString()
Custom toString magic method.
public
__toString() : string
Returns the script asset as a JSON string.
Tags
Return values
string —JSON string.
enqueue_script()
Enqueues the script asset to WordPress.
public
enqueue_script() : void
Uses the wp_enqueue_script()
function to enqueue the script asset.
Tags
register_script()
Enqueues the script asset to WordPress.
public
register_script() : void
Uses the wp_register_script()
function to register the script asset.
Tags
initialize()
Initializes the script asset.
protected
initialize() : void
Calls the parent initialize method and adds the script asset to the registry.