Ajax.php
3 months ago
Assets.php
1 month ago
Loader.php
1 year ago
Rest.php
1 year ago
SurveyLoader.php
1 year ago
SurveyManager.php
1 month ago
Assets.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Surveys; |
| 4 | |
| 5 | class Assets |
| 6 | { |
| 7 | public Loader $surveys; |
| 8 | private string $assetsPath; |
| 9 | public function init(): void |
| 10 | { |
| 11 | add_action('admin_enqueue_scripts', [ $this, 'enqueueAdminAssets' ]); |
| 12 | $this->assetsPath = '/vendor/hostinger/hostinger-wp-surveys/assets'; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * @return void |
| 17 | */ |
| 18 | public function enqueueAdminAssets(): void |
| 19 | { |
| 20 | $pluginInfo = $this->surveys->getPluginInfo(); |
| 21 | $defaultVersion = '1.0.0'; |
| 22 | $jsScriptPath = __DIR__ . '/../assets/js/hostinger-surveys.min.js'; |
| 23 | $cssStylePath = __DIR__ . '/../assets/css/style.min.css'; |
| 24 | $jsVersion = $defaultVersion; |
| 25 | |
| 26 | if (file_exists($jsScriptPath)) { |
| 27 | $jsVersion = filemtime($jsScriptPath) ?: $defaultVersion; |
| 28 | } |
| 29 | |
| 30 | if (empty($pluginInfo)) { |
| 31 | $pluginInfo = get_stylesheet_directory_uri(); |
| 32 | } |
| 33 | |
| 34 | wp_enqueue_script('hostinger_surveys_scripts', $pluginInfo . $this->assetsPath . '/js/hostinger-surveys.min.js', [ 'jquery' ], $jsVersion, [ 'strategy' => 'defer' ]); |
| 35 | |
| 36 | wp_localize_script('hostinger_surveys_scripts', 'hostingerContainer', [ |
| 37 | 'url' => admin_url('admin-ajax.php'), |
| 38 | 'nonce' => wp_create_nonce('hts-ajax-nonce'), |
| 39 | ]); |
| 40 | |
| 41 | $cssVersion = $defaultVersion; |
| 42 | |
| 43 | if (file_exists($cssStylePath)) { |
| 44 | $cssVersion = filemtime($cssStylePath) ?: $defaultVersion; |
| 45 | } |
| 46 | |
| 47 | wp_enqueue_style('hostinger_surveys_styles', $pluginInfo . $this->assetsPath . '/css/style.min.css', [], $cssVersion); |
| 48 | } |
| 49 | } |
| 50 |