All features

Cherry Blossom feature

Frontend Enqueues: Script base

Registers scripts and resolves their loading strategy and localization.

Registers scripts and resolves their loading strategy and localization.

Capabilities and extension points

The loading strategy for the script.

This property corresponds to the `strategy` argument of the `wp_register_script()` function. It determines how the script is loaded, either `defer` or `async`.

  • since 1.0.0
  • var string|null $strategy The loading strategy for the script; get_args() treats an unset value as null.

Assigns file and/or minified file to the object.

This method is used to define the files.

  • param string|false $file Unminified file URL.
  • param string|false $file_minified Minified file URL.
  • throws \Exception If neither a minified nor a regular file is defined.

Sets the file locations for the object.

  • param string|null $location Unminified file location.
  • param string|null $location_minified Minified file location.

Builds the arguments passed to wp_register_script().

  • return array{strategy: string|null, in_footer: bool} Registration arguments.

Registers the script with WordPress.

We register and enqueue scripts separately. This gives us more control over the enqueues.

  • return self

Enqueues the script with WordPress.

If the script was not registered, this also registers it.

  • return self

Deregisters the script when this object registered it.

  • return self Current script object for method chaining.

Filters the script registration arguments.

The handle-specific filter runs first, followed by the generic filter. Both receive the current arguments, original arguments, and script handle.

  • param array $args Enqueue arguments.
  • return array Enqueue arguments.

Sets the JavaScript object name used for localization.

  • param string $key JavaScript object name.

Gets the configured localization object name.

  • return string|false Object name, or false when localization is disabled.

Sets static or lazily resolved localization data.

The callback receives no arguments and must return a localization array. It is evaluated when the script is enqueued. The backing property currently supports array and string callback forms only; closures and invokable objects accepted by the signature trigger a TypeError when assigned.

  • param array|callable $localization Localization data or provider.
  • throws \TypeError When a callable is neither an array nor a string.

Resolves and filters localization data for this script.

  • return array Filtered localization data.

Localizes the registered script once when data and an object name exist.

Source reference

This editable reference page is based on the PHP documentation in frontend/enqueues/abstract-script.php.