| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Help Center Script loader. |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace Extendify\HelpCenter; |
| 8 |
|
| 9 |
defined('ABSPATH') || die('No direct access.'); |
| 10 |
|
| 11 |
use Extendify\Config; |
| 12 |
use Extendify\HelpCenter\Controllers\RouterController; |
| 13 |
use Extendify\HelpCenter\Controllers\SupportArticlesController; |
| 14 |
use Extendify\HelpCenter\Controllers\TourController; |
| 15 |
use Extendify\PartnerData; |
| 16 |
|
| 17 |
/** |
| 18 |
* This class handles any file loading for the admin area. |
| 19 |
*/ |
| 20 |
|
| 21 |
class Admin |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Adds various actions to set up the page |
| 25 |
* |
| 26 |
* @return self|void |
| 27 |
*/ |
| 28 |
public function __construct() |
| 29 |
{ |
| 30 |
\add_action('admin_enqueue_scripts', [$this, 'loadGlobalScripts']); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Adds scripts to every page. |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function loadGlobalScripts() |
| 39 |
{ |
| 40 |
$version = Config::$environment === 'PRODUCTION' ? Config::$version : uniqid(); |
| 41 |
$scriptAssetPath = EXTENDIFY_PATH . 'public/build/' . Config::$assetManifest['extendify-help-center.php']; |
| 42 |
$fallback = [ |
| 43 |
'dependencies' => [], |
| 44 |
'version' => $version, |
| 45 |
]; |
| 46 |
$scriptAsset = file_exists($scriptAssetPath) ? require $scriptAssetPath : $fallback; |
| 47 |
|
| 48 |
foreach ($scriptAsset['dependencies'] as $style) { |
| 49 |
\wp_enqueue_style($style); |
| 50 |
} |
| 51 |
|
| 52 |
\wp_enqueue_script( |
| 53 |
Config::$slug . '-help-center-scripts', |
| 54 |
EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-help-center.js'], |
| 55 |
array_merge([Config::$slug . '-shared-scripts'], $scriptAsset['dependencies']), |
| 56 |
$scriptAsset['version'], |
| 57 |
true |
| 58 |
); |
| 59 |
|
| 60 |
$partnerData = PartnerData::getPartnerData(); |
| 61 |
|
| 62 |
\wp_add_inline_script( |
| 63 |
Config::$slug . '-help-center-scripts', |
| 64 |
'window.extHelpCenterData = ' . \wp_json_encode([ |
| 65 |
'userData' => [ |
| 66 |
'tourData' => \wp_json_encode(TourController::get()->get_data()), |
| 67 |
'supportArticlesData' => \wp_json_encode(SupportArticlesController::get()->get_data()), |
| 68 |
'routerData' => \wp_json_encode(RouterController::get()->get_data()), |
| 69 |
], |
| 70 |
]), |
| 71 |
'before' |
| 72 |
); |
| 73 |
|
| 74 |
\wp_set_script_translations( |
| 75 |
Config::$slug . '-help-center-scripts', |
| 76 |
'extendify-local', |
| 77 |
EXTENDIFY_PATH . 'languages/js' |
| 78 |
); |
| 79 |
|
| 80 |
\wp_enqueue_style( |
| 81 |
Config::$slug . '-help-center-styles', |
| 82 |
EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-help-center.css'], |
| 83 |
[], |
| 84 |
Config::$version, |
| 85 |
'all' |
| 86 |
); |
| 87 |
} |
| 88 |
} |
| 89 |
|