LLMS_Assets::get( string $type, string $handle )
Retrieve an asset definition by type and handle
Description Description
Locates the asset by type and handle and merges a potentially impartial asset definition with default values from the get_defaults() method.
Parameters Parameters
- $type
-
(string) (Required) The asset type. Accepts either "script" or "style".
- $handle
-
(string) (Required) The asset handle.
Return Return
(array|false) An asset definition array or false if an asset definition could not be located.
- 'file_name'
(string) The file name of the asset. Excludes the path, suffix, and extension, eg: 'llms' for 'llms.js'. Defaults to the asset's handle. - 'base_url'
(string) The base URL used to locate the asset on the server. Defaults toLLMS_PLUGIN_URL. - 'path'
(string) The relative path to the asset within the plugin directory. Defaults toassets/jsfor scripts andassets/cssfor styles. - 'extension'
(string) The filename extension for the asset. Defaults to.jsfor scripts and.cssfor styles. - 'suffix'
(string) The file suffix for the asset, for example.minfor minified files. Defaults toLLMS_ASSETS_SUFFIX. - 'dependencies'
(string[]) An array of asset handles the asset depends on. These assets do not necessarily need to be assets defined by LifterLMS, for example WP Core scripts, such asjquery, can be used. - 'version'
(string) The asset version. Defaults toLLMS_VERSION. - 'package_id'
(string) An ID used to identify the originating plugin or theme that defined the asset. - 'in_footer'
(boolean) (Forscriptassets only) Whether or not the script should be output in the footer. Defaults totrue. - 'translate'
(boolean) (Forscriptassets only) Whether or not script translations should be set. Defaults tofalse. - 'asset_file'
(boolean) (Forscriptassets only) Whether or not the script has an asset file (generated via the @wordpress/dependency-extraction-webpack-plugin). - 'rtl'
(boolean) (Forstyleassets only) Whether or not to automatically add RTL style data for the stylesheet. Defaults totrue. - 'media'
(boolean) (Forstyleassets only) The stylesheet's media type. Defaults toall.
Source Source
File: includes/class-llms-assets.php
* }
*/
protected function get( $type, $handle ) {
$list = $this->get_definitions( $type );
$asset = isset( $list[ $handle ] ) ? $list[ $handle ] : false;
/**
* Filter static asset data prior to preparing the definition
*
* The definition is "prepared" by merging its data with the default data and preparing its src.
*
* The dynamic portion of this filter, `{$type}`, refers to the asset type. Either "script" or "style".
*
* @since 4.4.0
*
* @param array|false $asset Array of asset data or `false` if the asset has not been defined with LifterLMS.
* @param string $handle The asset handle.
* @param string $package_id An ID used to identify the originating plugin or theme that defined the asset.
*/
$asset = apply_filters( "llms_get_{$type}_asset_before_prep", $asset, $handle, $this->package_id );
if ( false !== $asset && is_array( $asset ) ) {
$asset = wp_parse_args( $asset, $this->get_defaults( $type ) );
$asset['handle'] = $handle;
$asset['package_id'] = $this->package_id;
$asset['file_name'] = ! empty( $asset['file_name'] ) ? $asset['file_name'] : $handle;
$asset['src'] = ! empty( $asset['src'] ) ? $asset['src'] : implode(
'',
array(
trailingslashit( $asset['base_url'] ),
trailingslashit( $asset['path'] ),
$asset['file_name'],
$asset['suffix'],
$asset['extension'],
)
);
$asset = $this->merge_asset_file( $asset );
}
/**
* Filter static asset data prior to enqueueing or registering it with the WordPress core
*
* The dynamic portion of this filter, `{$type}`, refers to the asset type. Either "script" or "style".
*
* @since 4.4.0
*
* @param array|false $asset Array of asset data or `false` if the asset has not been defined with LifterLMS.
* @param string $handle The asset handle.
*/
return apply_filters( "llms_get_{$type}_asset", $asset, $handle );
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.5.0 | Load dependency and version info from an asset.php file when $asset_file is true. |
| 4.4.1 | Replace truthy check with an strict check against false to ensure assets defined with an empty array signifying all default values should be used. |
| 4.4.0 | Introduced. |