Skip to content

Commit

Permalink
Support for asset collections and arrays (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
A---- authored Jul 30, 2020
1 parent 9851b4b commit 85313c5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions classes/plugin/ShortcodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,23 @@ public function __construct()
* add CSS and JS assets to the Manager so that they can be saved to cache
* for subsequent cached pages
*
* @param mixed $action the type of asset, JS or CSS, or an array of stuff
* @param mixed $actionOrAsset the type of asset (JS or CSS) or, if the second parameter is omitted,
* a collection or an array of asset.
* @param string $asset the asset path in question
*/
public function addAssets($action, $asset)
public function addAssets($actionOrAsset, $asset = null)
{
if (is_array($action)) {
$this->assets['add'] [] = $action;
if ($asset == null) {
if (is_array($actionOrAsset)) {
$this->assets[''] = array_merge($this->assets[''] ?? array(), $actionOrAsset);
} else {
$this->assets[''] [] = $actionOrAsset;
}
} else {
if (isset($this->assets[$action]) && in_array($asset, $this->assets[$action], true)) {
if (isset($this->assets[$actionOrAsset]) && in_array($asset, $this->assets[$actionOrAsset], true)) {
return;
}
$this->assets[$action] [] = $asset;
$this->assets[$actionOrAsset] [] = $asset;
}
}

Expand Down

0 comments on commit 85313c5

Please sign in to comment.