| @@ -3,24 +3,64 @@ | ||
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | 4 | exit; |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | +/** | |
| 8 | + * Class Hostinger_Admin_Assets | |
| 9 | + * | |
| 10 | + * Handles the enqueueing of styles and scripts for the Hostinger admin pages. | |
| 11 | + */ | |
| 7 | 12 | class Hostinger_Admin_Assets { |
| 13 | + /** | |
| 14 | + * @var Hostinger_Helper Instance of the Hostinger_Helper class. | |
| 15 | + */ | |
| 16 | + private Hostinger_Helper $helper; | |
| 17 | + | |
| 8 | 18 | public function __construct() { |
| 9 | - add_action( 'admin_enqueue_scripts', [ $this, 'admin_styles' ] ); | |
| 10 | - add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] ); | |
| 19 | + $this->helper = new Hostinger_Helper(); | |
| 20 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); | |
| 21 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); | |
| 11 | 22 | } |
| 12 | 23 | |
| 24 | + /** | |
| 25 | + * Enqueues styles for the Hostinger admin pages. | |
| 26 | + */ | |
| 13 | 27 | public function admin_styles(): void { |
| 14 | - wp_enqueue_style( 'hostinger_main_styles', HOSTINGER_ASSETS_URL . '/css/main.css', [], HOSTINGER_VERSION ); | |
| 28 | + if ( $this->helper->is_hostinger_admin_page() ) { | |
| 29 | + wp_enqueue_style( 'hostinger_main_styles', HOSTINGER_ASSETS_URL . '/css/main.css', array(), HOSTINGER_VERSION ); | |
| 30 | + } | |
| 31 | + | |
| 32 | + if ( $this->helper->is_preview_domain() && is_user_logged_in() ) { | |
| 33 | + wp_enqueue_style( 'hostinger-preview-styles', HOSTINGER_ASSETS_URL . '/css/hts-preview.css', array(), HOSTINGER_VERSION ); | |
| 34 | + } | |
| 15 | 35 | } |
| 16 | 36 | |
| 37 | + /** | |
| 38 | + * Enqueues scripts for the Hostinger admin pages. | |
| 39 | + */ | |
| 17 | 40 | public function admin_scripts(): void { |
| 18 | - wp_enqueue_script( 'hostinger_main_scripts', HOSTINGER_ASSETS_URL . '/js/main.js', [ 'jquery', 'wp-i18n' ], HOSTINGER_VERSION, false ); | |
| 19 | - wp_localize_script('hostinger_main_scripts', 'ajax_var', array( | |
| 20 | - 'url' => admin_url('admin-ajax.php'), | |
| 21 | - 'nonce' => wp_create_nonce('hts-ajax-nonce') | |
| 22 | - )); | |
| 41 | + if ( $this->helper->is_hostinger_admin_page() ) { | |
| 42 | + wp_enqueue_script( 'hostinger_main_scripts', HOSTINGER_ASSETS_URL . '/js/main.js', array( | |
| 43 | + 'jquery', | |
| 44 | + 'wp-i18n', | |
| 45 | + ), HOSTINGER_VERSION, false ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + wp_enqueue_script( 'hostinger_global_scripts', HOSTINGER_ASSETS_URL . '/js/global-scripts.js', array( | |
| 49 | + 'jquery', | |
| 50 | + 'wp-i18n', | |
| 51 | + ), HOSTINGER_VERSION, false ); | |
| 52 | + | |
| 53 | + if ( ! empty( Hostinger_Helper::get_api_token() ) ) { | |
| 54 | + wp_enqueue_script( 'hostinger_requests_scripts', HOSTINGER_ASSETS_URL . '/js/requests.js', array( | |
| 55 | + 'jquery', | |
| 56 | + 'wp-i18n', | |
| 57 | + ), HOSTINGER_VERSION, false ); | |
| 58 | + wp_localize_script( 'hostinger_requests_scripts', 'hostingerContainer', array( | |
| 59 | + 'url' => admin_url( 'admin-ajax.php' ), | |
| 60 | + 'nonce' => wp_create_nonce( 'hts-ajax-nonce' ), | |
| 61 | + ) ); | |
| 62 | + } | |
| 23 | 63 | } |
| 24 | 64 | } |
| 25 | 65 | |
| 26 | 66 | new Hostinger_Admin_Assets(); |