Assets
in package
Uses
UtilsProvider, Assets
Assets handling.
Table of Contents
Properties
- $ASSETS_BUMP : mixed
- For future implementations and updates of this class you can differ from BUMP version.
- $core : mixed
Methods
- __construct() : mixed
- C'tor.
- admin_enqueue_scripts() : mixed
- Enqueue scripts and styles for admin pages.
- anonymous_localize_script() : mixed
- Make a localized array anonymous. Some plugins like WP Rocket tries to lazy load also localized scripts and this should be avoided in some scenarios like Real Cookie Banners' banner script.
- customize_controls_print_scripts() : mixed
- Enqueue scripts in customize (not preview!)
- enableAdvancedEnqueue() : mixed
- Allows to enable advanced enqueue features for a given handle.
- enableAsyncEnqueue() : mixed
- Enable `async` attribute for given handle(s) (only scripts are supported).
- enableDeferredEnqueue() : mixed
- Enable `defer` attribute for given handle(s) (only scripts are supported, see https://stackoverflow.com/a/25890780).
- enablePreloadEnqueue() : mixed
- Enable `<link rel="preload" />` HTML tag for given handle(s).
- enablePriorityQueue() : mixed
- Enable scripts and styles to be appear at the top of `<head`.
- enqueue() : mixed
- Enqueue scripts and styles for this library.
- enqueue_scripts_and_styles() : mixed
- Enqueue scripts and styles depending on the type. This function is called from both admin_enqueue_scripts and wp_enqueue_scripts. You can check the type through the $type parameter. In this function you can include your external libraries from public/lib, too.
- enqueueComposerScript() : string
- Enqueue a composer package script from our multi-package repository.
- enqueueComposerStyle() : string
- Enqueue a composer package style from our multi-package repository.
- enqueueLibraryScript() : string|bool
- Wrapper for Assets#enqueueScript() method with $isLib = true.
- enqueueLibraryStyle() : string|bool
- Wrapper for Assets#enqueueStyle() method with $isLib = true.
- enqueueMobx() : mixed
- Enqueue mobx state management library.
- enqueueReactJsxRuntime() : mixed
- When using WordPress < 6.6 we need to enqueue the react/jsx-runtime UMD bundle to make the `ReactJSXRuntime` external work.
- enqueueScript() : string|bool
- Registers the script if $src provided (does NOT overwrite), and enqueues it. Use this wrapper method instead of wp_enqueue_script if you want to use the cachebuster for the given src. If the src is not found in the cachebuster (inc/base/others/cachebuster.php) it falls back to _VERSION.
- enqueueStyle() : string|bool
- Enqueue a CSS stylesheet. Use this wrapper method instead of wp_enqueue_style if you want to use the cachebuster for the given src. If the src is not found in the cachebuster (inc/base/others/cachebuster.php) it falls back to _VERSION.
- enqueueUtils() : mixed
- Enqueue utils and return an array of dependencies.
- getAsciiUrl() : string
- Convert a complete URL to IDN url. This is necessery if you use a URIBuilder like lil-url in your frontend.
- getCachebusterVersion() : string
- Get the cachebuster entry for a given file. If the $src begins with public/lib/ it will use the inc/base/others/cachebuster-lib.php cachebuster instead of inc/base/others/cachebuster.php.
- getChunkTranslationMap() : mixed
- Get a map of available translations for all available chunks.
- getPluginConstantPrefix() : string
- Get the prefix of this package so we can utils package natively.
- getPluginsUrl() : string
- Wrapper for plugins_url. It respects the public folder depending on the SCRIPTS_DEBUG constant.
- getPublicFolder() : string
- Gets a public folder depending on the debug mode relative to the plugins folder with trailing slash.
- isScreenBase() : bool
- Checks if a specific screen is active.
- load_script_textdomain_relative_path() : mixed
- Force the basename for the md5 of a loaded JSON translation file.
- load_script_translation_file() : mixed
- Fix correct filename for enqueued composer packages.
- localizeScript() : mixed
- Localize the WordPress backend and frontend.
- login_enqueue_scripts() : mixed
- overrideLocalizeScript() : array<string|int, mixed>
- Localize the plugin with additional options.
- probablyDeregisterWhenNewerVersion() : mixed
- Probably deregister a given handle when our requested version is higher than the current enqueued version script / style.
- setLazyScriptTranslations() : mixed
- The function and mechanism of wp_set_script_translations() is great of course. Unfortunately popular plugins like WP Rocket and Divi are not compatible with it (especially page builders and caching plugins). Why? Shortly explained, the injected inline scripts relies on `wp.i18n` which can be deferred or async loaded (the script itself) -> wp is not defined.
- setupConstants() : mixed
- Make sure the REAL_QUEUE constants are available.
- useNonMinifiedSources() : bool
- Check if SCRIPT_DEBUG is set to true.
- wp_enqueue_scripts() : mixed
- Enqueue scripts and styles for frontend pages.
- enqueueComposer() : string|bool
- Enqueue helper for monorepo packages. See dependents for more documentation.
- getTranslationSuffixByBasename() : mixed
- Get the suffix for `chunks` localized variable including dependencies.
- probablyEnqueueChunk() : mixed
- Checks if a `vendor-` file is created for a given script and enqueue it.
- probablyEnqueueComposerChunk() : mixed
- Checks if a `vendor-` file is created for a given script in a composer package and enqueue it.
Properties
$ASSETS_BUMP
For future implementations and updates of this class you can differ from BUMP version.
public
static mixed
$ASSETS_BUMP
= 4
Increment, if needed.
$core
private
mixed
$core
Methods
__construct()
C'tor.
public
__construct(Core $core) : mixed
Parameters
- $core : Core
Tags
admin_enqueue_scripts()
Enqueue scripts and styles for admin pages.
public
admin_enqueue_scripts(string $hook_suffix) : mixed
Parameters
- $hook_suffix : string
-
The current admin page
anonymous_localize_script()
Make a localized array anonymous. Some plugins like WP Rocket tries to lazy load also localized scripts and this should be avoided in some scenarios like Real Cookie Banners' banner script.
public
anonymous_localize_script(string $handle, string $object_name, array<string|int, mixed> $l10n[, array<string|int, mixed> $settings = [] ]) : mixed
Use this instead of wp_localize_script
.
Settings:
string[] makeBase64Encoded List of keys of the array object which should be converted to base64 at output time (e.g. to avoid ModSecurity issues)
boolean useCore Use `wp_localize_script` internally instead of custom localize script
string[] lazyParse A list of pathes of the array which should be lazy parsed. This could be useful to improve performance and parse as needed (e.g. huge arrays).
Parameters
- $handle : string
-
Name of the script to attach data to.
- $object_name : string
-
Name of the variable that will contain the data.
- $l10n : array<string|int, mixed>
-
Array of data to localize.
- $settings : array<string|int, mixed> = []
Tags
customize_controls_print_scripts()
Enqueue scripts in customize (not preview!)
public
customize_controls_print_scripts() : mixed
enableAdvancedEnqueue()
Allows to enable advanced enqueue features for a given handle.
public
enableAdvancedEnqueue(string|array<string|int, string> $handles[, array<string|int, string> $features = null ][, string $type = 'script' ]) : mixed
Parameters
- $handles : string|array<string|int, string>
- $features : array<string|int, string> = null
-
See $ADVANCED_ENQUEUE_FEATURE_* constants or
null
for all features - $type : string = 'script'
-
Can be
script
orstyle
enableAsyncEnqueue()
Enable `async` attribute for given handle(s) (only scripts are supported).
public
enableAsyncEnqueue(string|array<string|int, string> $handles) : mixed
Parameters
- $handles : string|array<string|int, string>
enableDeferredEnqueue()
Enable `defer` attribute for given handle(s) (only scripts are supported, see https://stackoverflow.com/a/25890780).
public
enableDeferredEnqueue(string|array<string|int, string> $handles) : mixed
Parameters
- $handles : string|array<string|int, string>
Tags
enablePreloadEnqueue()
Enable `<link rel="preload" />` HTML tag for given handle(s).
public
enablePreloadEnqueue(string|array<string|int, string> $handles[, string $type = 'script' ]) : mixed
Parameters
- $handles : string|array<string|int, string>
- $type : string = 'script'
-
Can be
script
orstyle
Tags
enablePriorityQueue()
Enable scripts and styles to be appear at the top of `<head`.
public
enablePriorityQueue(string|array<string|int, string> $handles[, string $type = 'script' ]) : mixed
Parameters
- $handles : string|array<string|int, string>
- $type : string = 'script'
-
Can be
script
orstyle
enqueue()
Enqueue scripts and styles for this library.
public
enqueue([Assets $assets = null ]) : mixed
Parameters
- $assets : Assets = null
enqueue_scripts_and_styles()
Enqueue scripts and styles depending on the type. This function is called from both admin_enqueue_scripts and wp_enqueue_scripts. You can check the type through the $type parameter. In this function you can include your external libraries from public/lib, too.
public
enqueue_scripts_and_styles(string $type[, string $hook_suffix = null ]) : mixed
Note: The scripts are loaded only on backend (admin_enqueue_scripts
). If your plugin
is also loaded on frontend you need to make sure to enqueue via wp_enqueue_scripts
, too.
See also https://app.clickup.com/t/4rknyh for more information about this (commits).
Parameters
- $type : string
-
The type (see Assets constants)
- $hook_suffix : string = null
-
The current admin page
enqueueComposerScript()
Enqueue a composer package script from our multi-package repository.
public
enqueueComposerScript(string $handle[, array<string|int, string> $deps = [] ][, string $src = 'index.js' ][, bool $in_footer = true ]) : string
Parameters
- $handle : string
-
Name of the package.
- $deps : array<string|int, string> = []
-
An array of registered scripts handles this script depends on.
- $src : string = 'index.js'
-
The file to use in dist or dev folder.
- $in_footer : bool = true
-
Whether to enqueue the script before