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.


Top ↑

Parameters Parameters

$type

(string) (Required) The asset type. Accepts either "script" or "style".

$handle

(string) (Required) The asset handle.


Top ↑

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 to LLMS_PLUGIN_URL.
  • 'path'
    (string) The relative path to the asset within the plugin directory. Defaults to assets/js for scripts and assets/css for styles.
  • 'extension'
    (string) The filename extension for the asset. Defaults to .js for scripts and .css for styles.
  • 'suffix'
    (string) The file suffix for the asset, for example .min for minified files. Defaults to LLMS_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 as jquery, can be used.
  • 'version'
    (string) The asset version. Defaults to LLMS_VERSION.
  • 'package_id'
    (string) An ID used to identify the originating plugin or theme that defined the asset.
  • 'in_footer'
    (boolean) (For script assets only) Whether or not the script should be output in the footer. Defaults to true.
  • 'translate'
    (boolean) (For script assets only) Whether or not script translations should be set. Defaults to false.
  • 'asset_file'
    (boolean) (For script assets only) Whether or not the script has an asset file (generated via the @wordpress/dependency-extraction-webpack-plugin).
  • 'rtl'
    (boolean) (For style assets only) Whether or not to automatically add RTL style data for the stylesheet. Defaults to true.
  • 'media'
    (boolean) (For style assets only) The stylesheet's media type. Defaults to all.


Top ↑

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 );


Top ↑

Changelog 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.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.