Properties

$ASSETS_BUMP

$ASSETS_BUMP :

For future implementations and updates of this class you can differ from BUMP version.

Increment, if needed.

Type

Methods

getPluginConstantPrefix()

getPluginConstantPrefix(): string

Get the prefix of this package so we can utils package natively.

Returns

string

setupConstants()

setupConstants()

Make sure the REAL_UTILS constants are available.

overrideLocalizeScript()

overrideLocalizeScript(string  $context): array

Localize the plugin with additional options.

Parameters

string $context

Returns

array

enqueue_scripts_and_styles()

enqueue_scripts_and_styles(string  $type,string  $hook_suffix = null)

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.

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

string $type

The type (see Assets constants)

string $hook_suffix

The current admin page

localizeScript()

localizeScript(string  $context): mixed

Localize the WordPress backend and frontend.

Parameters

string $context

Returns

mixed

enableAdvancedEnqueue()

enableAdvancedEnqueue(string|array<mixed,string>  $handles,array<mixed,string>  $features = null,string  $type = 'script')

Allows to enable advanced enqueue features for a given handle.

Parameters

string|array<mixed,string> $handles
array<mixed,string> $features

See $ADVANCED_ENQUEUEFEATURE* constants or null for all features

string $type

Can be script or style

enableDeferredEnqueue()

enableDeferredEnqueue(string|array<mixed,string>  $handles)

Enable `defer` attribute for given handle(s) (only scripts are supported, see https://stackoverflow.com/a/25890780).

Parameters

string|array<mixed,string> $handles

enablePreloadEnqueue()

enablePreloadEnqueue(string|array<mixed,string>  $handles,string  $type = 'script')

Enable `<link rel="preload" />` HTML tag for given handle(s).

Parameters

string|array<mixed,string> $handles
string $type

Can be script or style

enablePriorityQueue()

enablePriorityQueue(string|array<mixed,string>  $handles,string  $type = 'script')

Enable scripts and styles to be appear at the top of `<head`.

Parameters

string|array<mixed,string> $handles
string $type

Can be script or style

getChunkTranslationMap()

getChunkTranslationMap()

Get a map of available translations for all available chunks.

enqueueUtils()

enqueueUtils()

Enqueue utils and return an array of dependencies.

enqueueMobx()

enqueueMobx()

Enqueue mobx state management library.

enqueueScript()

enqueueScript(string  $handle,mixed  $src,array<mixed,string>  $deps = array(),boolean  $in_footer = true,boolean  $isLib = false): string|boolean

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.

You can also use something like this to determine SCRIPT_DEBUG files:

$this->enqueueLibraryScript(
    Constants::ASSETS_HANDLE_REACT_DOM,
    [[$useNonMinifiedSources, 'react-dom/umd/react-dom.development.js'], 'react-dom/umd/react-dom.production.min.js'],
    Constants::ASSETS_HANDLE_REACT
);

Parameters

string $handle

Name of the script. Should be unique.

mixed $src

The src relative to public/dist or public/dev folder (when $isLib is false)

array<mixed,string> $deps

An array of registered script handles this script depends on.

boolean $in_footer

Whether to enqueue the script before instead of in the .

boolean $isLib

If true the public/lib/ folder is used.

Returns

string|boolean —

The used handle

enqueueLibraryScript()

enqueueLibraryScript(string  $handle,mixed  $src,array<mixed,string>  $deps = array(),boolean  $in_footer = false): string|boolean

Wrapper for Assets#enqueueScript() method with $isLib = true.

Parameters

string $handle
mixed $src
array<mixed,string> $deps
boolean $in_footer

Returns

string|boolean —

The used handle

enqueueStyle()

enqueueStyle(string  $handle,mixed  $src,array<mixed,string>  $deps = array(),string  $media = 'all',boolean  $isLib = false): string|boolean

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.

It also allows $src to be like in enqueueScript()

Parameters

string $handle

Name of the style. Should be unique.

mixed $src

The src relative to public/dist or public/dev folder (when $isLib is false)

array<mixed,string> $deps

An array of registered style handles this style depends on.

string $media

The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.

boolean $isLib

If true the public/lib/ folder is used.

Returns

string|boolean —

The used handle

enqueueLibraryStyle()

enqueueLibraryStyle(string  $handle,mixed  $src,array<mixed,string>  $deps = array(),string  $media = 'all'): string|boolean

Wrapper for Assets#enqueueStyle() method with $isLib = true.

Parameters

string $handle
mixed $src
array<mixed,string> $deps
string $media

Returns

string|boolean —

The used handle

enqueueComposerScript()

enqueueComposerScript(string  $handle,array<mixed,string>  $deps = array(),string  $src = 'index.js',boolean  $in_footer = true): string

Enqueue a composer package script from our multi-package repository.

Parameters

string $handle

Name of the package.

array<mixed,string> $deps

An array of registered scripts handles this script depends on.

string $src

The file to use in dist or dev folder.

boolean $in_footer

Whether to enqueue the script before instead of in the .

Returns

string —

The used handle

enqueueComposerStyle()

enqueueComposerStyle(string  $handle,array<mixed,string>  $deps = array(),string  $src = 'index.css',string  $media = 'all'): string

Enqueue a composer package style from our multi-package repository.

Parameters

string $handle

Name of the package.

array<mixed,string> $deps

An array of registered scripts handles this script depends on.

string $src

The file to use in dist or dev folder.

string $media

The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.

Returns

string —

The used handle

admin_enqueue_scripts()

admin_enqueue_scripts(string  $hook_suffix)

Enqueue scripts and styles for admin pages.

Parameters

string $hook_suffix

The current admin page

wp_enqueue_scripts()

wp_enqueue_scripts()

Enqueue scripts and styles for frontend pages.

login_enqueue_scripts()

login_enqueue_scripts()

customize_controls_print_scripts()

customize_controls_print_scripts()

Enqueue scripts in customize (not preview!)

setLazyScriptTranslations()

setLazyScriptTranslations(string  $handle,string  $domain,string  $path)

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.

In factory i18n.tsx the window.wpi18nLazy is automatically detected and the plugin gets localized.

Parameters

string $handle
string $domain
string $path

load_script_translation_file()

load_script_translation_file(string  $file)

Fix correct filename for enqueued composer packages.

Parameters

string $file

load_script_textdomain_relative_path()

load_script_textdomain_relative_path(string  $src)

Force the basename for the md5 of a loaded JSON translation file.

Parameters

string $src

getCachebusterVersion()

getCachebusterVersion(string  $src,boolean  $isLib = false,string  $default = null): 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.

Parameters

string $src

The src relative to public/ folder

boolean $isLib

If true the cachebuster-lib.php cachebuster is used

string $default

Returns

string —

_VERSION or cachebuster timestamp

anonymous_localize_script()

anonymous_localize_script(string  $handle,string  $object_name,array  $l10n,array<mixed,string>  $makeBase64Encoded = array(),boolean  $use_core = false)

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.

Use this instead of wp_localize_script.

Parameters

string $handle

Name of the script to attach data to.

string $object_name

Name of the variable that will contain the data.

array $l10n

Array of data to localize.

array<mixed,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 $use_core

Use wp_localize_script internally instead of custom localize script

getPluginsUrl()

getPluginsUrl(string  $asset,boolean  $isLib = false): string

Wrapper for plugins_url. It respects the public folder depending on the SCRIPTS_DEBUG constant.

Parameters

string $asset

The file name relative to the public folder path (dist or dev)

boolean $isLib

If true the public/lib/ folder is used.

Returns

string

getPublicFolder()

getPublicFolder(boolean  $isLib = false): string

Gets a public folder depending on the debug mode relative to the plugins folder with trailing slash.

Parameters

boolean $isLib

If true the public/lib/ folder is returned.

Returns

string

getAsciiUrl()

getAsciiUrl(string  $url): string

Convert a complete URL to IDN url. This is necessery if you use a URIBuilder like lil-url in your frontend.

Parameters

string $url

The url

Returns

string

useNonMinifiedSources()

useNonMinifiedSources(): boolean

Check if SCRIPT_DEBUG is set to true.

Returns

boolean

probablyDeregisterWhenNewerVersion()

probablyDeregisterWhenNewerVersion(string  $handle,string  $newVersion,string  $type = 'script')

Probably deregister a given handle when our requested version is higher than the current enqueued version script / style.

Parameters

string $handle
string $newVersion
string $type

isScreenBase()

isScreenBase(string  $base): boolean

Checks if a specific screen is active.

Parameters

string $base

The base

Returns

boolean

getFirstAssetsToEnqueueComposer()

getFirstAssetsToEnqueueComposer()

Get first found instance of utils' Assets class. This is needed to we can enqueue assets from their.

isSomeWelcomePage()

isSomeWelcomePage()

Get initiator if the current page is a welcome page.

instance()

instance()

New instance.

getTranslationSuffixByBasename()

getTranslationSuffixByBasename(string  $basename)

Get the suffix for `chunks` localized variable including dependencies.

Parameters

string $basename

probablyEnqueueChunk()

probablyEnqueueChunk(string  $handle,boolean  $isLib,string  $src,array<mixed,string>  $deps,boolean  $in_footer,string  $media)

Checks if a `vendor-` file is created for a given script and enqueue it.

Parameters

string $handle
boolean $isLib
string $src
array<mixed,string> $deps
boolean $in_footer
string $media

enqueue()

enqueue(string  $handle,mixed  $src,array<mixed,string>  $deps = array(),boolean  $isLib = false,string  $type = 'script',boolean  $in_footer = true,string  $media = 'all'): string|boolean

Enqueue helper for entry points and libraries. See dependents for more documentation.

Parameters

string $handle
mixed $src
array<mixed,string> $deps
boolean $isLib
string $type

Can be 'script' or 'style'

boolean $in_footer
string $media

Returns

string|boolean —

The used handle

probablyEnqueueComposerChunk()

probablyEnqueueComposerChunk(string  $handle,string  $src,array<mixed,string>  $deps,boolean  $in_footer,string  $media)

Checks if a `vendor-` file is created for a given script in a composer package and enqueue it.

Parameters

string $handle
string $src
array<mixed,string> $deps
boolean $in_footer
string $media

enqueueComposer()

enqueueComposer(string  $handle,string  $src = 'index.js',array<mixed,string>  $deps = array(),string  $type = 'script',boolean  $in_footer = true,string  $media = 'all',string  $vendorHandle = null): string|boolean

Enqueue helper for monorepo packages. See dependents for more documentation.

Parameters

string $handle
string $src
array<mixed,string> $deps
string $type

Can be 'script' or 'style'

boolean $in_footer
string $media
string $vendorHandle

Returns

string|boolean —

The used handle

enqueueFeedback()

enqueueFeedback()

Enqueue script for plugins page so "Deactivate" opens a popup.

enqueueWelcome()

enqueueWelcome()

Enqueue script for welcome page.

enqueueCrossSelling()

enqueueCrossSelling()

Enqueue cross selling script if possible.

enqueueHelper()

enqueueHelper()

Enqueue helper from each initiator until one valid is found.

__construct()

__construct()

C'tor.