Style
extends Asset
in package
Style Module class extends 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.
- $media : string
- The media for which this stylesheet has been defined.
Methods
- __construct() : mixed
- Constructor.
- __toString() : string
- Custom toString magic method.
- enqueue_style() : void
- Enqueues the style asset to WordPress.
- register_style() : void
- Registers the style asset to WordPress.
- initialize() : void
- Initializes the style 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
$media
The media for which this stylesheet has been defined.
private
string
$media
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 ][, string $media = 'all' ][, bool $register_only = false ][, ActionHook $action_hook_enqueue = null ][, ActionHook $action_hook_register = null ]) : mixed
Constructs the Style object by setting the handle, source, dependencies, version, media, and register_only.
Parameters
- $handle : string
-
Name of the stylesheet. Should be unique.
- $src : string
-
Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
- $deps : array<string|int, mixed>|string = array()
-
Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
- $ver : string|bool = false
-
Optional. String specifying the stylesheet version number. If set to false, WordPress version will be used. Default false.
- $media : string = 'all'
-
Optional. The media for which this stylesheet has been defined. Default 'all'.
- $register_only : bool = false
-
Optional. Whether to only register the stylesheet 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_style method. Default 'wp_enqueue_scripts'.
Tags
__toString()
Custom toString magic method.
public
__toString() : string
Returns the style and asset as a JSON string.
Tags
Return values
string —JSON string.
enqueue_style()
Enqueues the style asset to WordPress.
public
enqueue_style() : void
Uses the wp_enqueue_style()
function to enqueue the style asset.
Tags
register_style()
Registers the style asset to WordPress.
public
register_style() : void
Uses the wp_register_style()
function to register the style asset.
Tags
initialize()
Initializes the style asset.
protected
initialize() : void
Calls the parent initialize method and adds the style asset to the registry.