| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Assets. |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace Extendify\Notifications; |
| 8 |
|
| 9 |
defined('ABSPATH') || die('No direct access.'); |
| 10 |
|
| 11 |
use Extendify\Config; |
| 12 |
|
| 13 |
/** |
| 14 |
* The one bundle every slot renders from, admin or front end. |
| 15 |
*/ |
| 16 |
class Assets |
| 17 |
{ |
| 18 |
/** |
| 19 |
* @return void |
| 20 |
*/ |
| 21 |
public static function enqueue() |
| 22 |
{ |
| 23 |
$manifest = Config::$assetManifest; |
| 24 |
if ( |
| 25 |
empty($manifest['extendify-notifications.php']) |
| 26 |
|| empty($manifest['extendify-notifications.js']) |
| 27 |
) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
$version = constant('EXTENDIFY_DEVMODE') ? uniqid() : Config::$version; |
| 32 |
$scriptAssetPath = EXTENDIFY_PATH . 'public/build/' |
| 33 |
. $manifest['extendify-notifications.php']; |
| 34 |
$fallback = [ |
| 35 |
'dependencies' => [], |
| 36 |
'version' => $version, |
| 37 |
]; |
| 38 |
$scriptAsset = file_exists($scriptAssetPath) ? require $scriptAssetPath : $fallback; |
| 39 |
|
| 40 |
foreach ($scriptAsset['dependencies'] as $style) { |
| 41 |
\wp_enqueue_style($style); |
| 42 |
} |
| 43 |
|
| 44 |
\wp_enqueue_script( |
| 45 |
Config::$slug . '-notifications-scripts', |
| 46 |
EXTENDIFY_BASE_URL . 'public/build/' . $manifest['extendify-notifications.js'], |
| 47 |
array_merge([Config::$slug . '-shared-scripts'], $scriptAsset['dependencies']), |
| 48 |
$scriptAsset['version'], |
| 49 |
true |
| 50 |
); |
| 51 |
|
| 52 |
\wp_set_script_translations( |
| 53 |
Config::$slug . '-notifications-scripts', |
| 54 |
'extendify-local', |
| 55 |
EXTENDIFY_PATH . 'languages/js' |
| 56 |
); |
| 57 |
|
| 58 |
if (empty($manifest['extendify-notifications.css'])) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
\wp_enqueue_style( |
| 63 |
Config::$slug . '-notifications-styles', |
| 64 |
EXTENDIFY_BASE_URL . 'public/build/' . $manifest['extendify-notifications.css'], |
| 65 |
[], |
| 66 |
Config::$version, |
| 67 |
'all' |
| 68 |
); |
| 69 |
} |
| 70 |
} |
| 71 |
|