Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,28 @@ class Asset {
protected array $groups = [];

/**
* Should the asset be loaded in the footer?
* Whether the asset should be loaded in the footer.
*
* @var bool
*/
protected bool $in_footer = true;

/**
* Should the asset be marked as async?
* Whether the asset should be marked as async.
*
* @var bool
*/
protected bool $is_async = false;

/**
* Should the asset be marked as deferred?
* Whether the asset should be marked as deferred.
*
* @var bool
*/
protected bool $is_deferred = false;

/**
* Is the asset enqueued?
* Whether the asset has been enqueued.
*
* @var bool
*/
Expand All @@ -113,21 +113,21 @@ class Asset {
protected bool $is_module = false;

/**
* Is the asset printed?
* Whether the asset has been printed.
*
* @var bool
*/
protected bool $is_printed = false;

/**
* Is the asset registered?
* Whether the asset has been registered.
*
* @var bool
*/
protected bool $is_registered = false;

/**
* Is the asset a vendor asset?
* Whether this is a vendor asset.
*
* @var bool
*/
Expand Down Expand Up @@ -344,6 +344,8 @@ public function add_to_group_path( string $group_path_name ) {
* @param string $file The asset file path.
* @param string|null $version The asset version.
* @param string|null $root_path The path to the root of the plugin.
*
* @return self
*/
public static function add( string $slug, string $file, string $version = null, $root_path = null ) {
return Assets::init()->add( new self( $slug, $file, $version, $root_path ) );
Expand Down Expand Up @@ -534,7 +536,7 @@ protected function build_asset_url(): string {
$url = $plugin_base_url . $resource_path . $resource;

/**
* Filters the asset URL
* Filters the asset URL.
*
* @param string $url Asset URL.
* @param string $slug Asset slug.
Expand Down Expand Up @@ -681,11 +683,11 @@ public function clone_to( string $clone_type, ...$dependencies ) {
$source_type = $this->get_type();

if ( $clone_type === $source_type ) {
throw new \InvalidArgumentException( 'The clone type must be different from the source type.' );
throw new InvalidArgumentException( 'The clone type must be different from the source type.' );
}

if ( ! in_array( $clone_type, [ 'css', 'js' ], true ) ) {
throw new \InvalidArgumentException( 'The clone type must be either "css" or "js".' );
throw new InvalidArgumentException( 'The clone type must be either "css" or "js".' );
}

$slug = $this->slug;
Expand Down
9 changes: 4 additions & 5 deletions src/Assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,21 @@ public static function asset( string $slug, string $file, string $version = null
*
* @param Asset $asset Register an asset.
*
* @return Asset|false The registered object or false on error.
* @return Asset|VendorAsset The registered object.
* @since 1.0.0
*
*/
public function add( Asset $asset ) {
// Prevent weird stuff here.
// Check if the slug is registered, and if so return the previously-registered Asset.
$slug = $asset->get_slug();

if ( $this->exists( $slug ) ) {
return $this->get( $slug );
}

// Set the Asset on the array of notices.
// Add the asset to the array of assets.
$this->assets[ $slug ] = $asset;

// Return the Slug because it might be modified.
return $asset;
}

Expand Down Expand Up @@ -193,7 +192,7 @@ public function filter_print_before_after_script( $tag, $handle ): string {
* @param string|array $slug Slug of the Asset.
* @param boolean $sort If we should do any sorting before returning.
*
* @return array|Asset Array of asset objects, single asset object, or null if looking for a single asset but
* @return array|Asset|VendorAsset Array of asset objects, single asset object, or null if looking for a single asset but
* it was not in the array of objects.
* @since 1.0.0
*
Expand Down
Loading
Loading