| @@ -3,32 +3,87 @@ | ||
| 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 | - $helper = new Hostinger_Helper(); | |
| 15 | - 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 | + } | |
| 16 | 31 | |
| 17 | - if( $helper->is_preview_domain() && is_user_logged_in() ) { | |
| 18 | - wp_enqueue_style( 'hostinger-preview-styles', HOSTINGER_ASSETS_URL . '/css/hts-preview.css', [], HOSTINGER_VERSION ); | |
| 32 | + wp_enqueue_style( 'hostinger_global_styles', HOSTINGER_ASSETS_URL . '/css/global.css', array(), HOSTINGER_VERSION ); | |
| 33 | + | |
| 34 | + if ( $this->helper->is_preview_domain() && is_user_logged_in() ) { | |
| 35 | + wp_enqueue_style( 'hostinger-preview-styles', HOSTINGER_ASSETS_URL . '/css/hts-preview.css', array(), HOSTINGER_VERSION ); | |
| 19 | 36 | } |
| 20 | 37 | } |
| 21 | 38 | |
| 39 | + /** | |
| 40 | + * Enqueues scripts for the Hostinger admin pages. | |
| 41 | + */ | |
| 22 | 42 | public function admin_scripts(): void { |
| 23 | - wp_enqueue_script( 'hostinger_main_scripts', HOSTINGER_ASSETS_URL . '/js/main.js', array( 'jquery', 'wp-i18n' ), HOSTINGER_VERSION, false ); | |
| 43 | + if ( $this->helper->is_hostinger_admin_page() ) { | |
| 44 | + wp_enqueue_script( | |
| 45 | + 'hostinger_main_scripts', | |
| 46 | + HOSTINGER_ASSETS_URL . '/js/main.js', | |
| 47 | + array( | |
| 48 | + 'jquery', | |
| 49 | + 'wp-i18n', | |
| 50 | + ), | |
| 51 | + HOSTINGER_VERSION, | |
| 52 | + false | |
| 53 | + ); | |
| 54 | + } | |
| 24 | 55 | |
| 56 | + wp_enqueue_script( | |
| 57 | + 'hostinger_global_scripts', | |
| 58 | + HOSTINGER_ASSETS_URL . '/js/global-scripts.js', | |
| 59 | + array( | |
| 60 | + 'jquery', | |
| 61 | + 'wp-i18n', | |
| 62 | + ), | |
| 63 | + HOSTINGER_VERSION, | |
| 64 | + false | |
| 65 | + ); | |
| 66 | + | |
| 25 | 67 | if ( ! empty( Hostinger_Helper::get_api_token() ) ) { |
| 26 | - wp_enqueue_script( 'hostinger_requests_scripts', HOSTINGER_ASSETS_URL . '/js/requests.js', array( 'jquery', 'wp-i18n' ), HOSTINGER_VERSION, false ); | |
| 27 | - wp_localize_script('hostinger_requests_scripts', 'ajax_var', array( | |
| 28 | - 'url' => admin_url('admin-ajax.php'), | |
| 29 | - 'nonce' => wp_create_nonce('hts-ajax-nonce') | |
| 30 | - )); | |
| 68 | + wp_enqueue_script( | |
| 69 | + 'hostinger_requests_scripts', | |
| 70 | + HOSTINGER_ASSETS_URL . '/js/requests.js', | |
| 71 | + array( | |
| 72 | + 'jquery', | |
| 73 | + 'wp-i18n', | |
| 74 | + ), | |
| 75 | + HOSTINGER_VERSION, | |
| 76 | + false | |
| 77 | + ); | |
| 78 | + wp_localize_script( | |
| 79 | + 'hostinger_requests_scripts', | |
| 80 | + 'hostingerContainer', | |
| 81 | + array( | |
| 82 | + 'url' => admin_url( 'admin-ajax.php' ), | |
| 83 | + 'nonce' => wp_create_nonce( 'hts-ajax-nonce' ), | |
| 84 | + ) | |
| 85 | + ); | |
| 31 | 86 | } |
| 32 | 87 | } |
| 33 | 88 | } |
| 34 | 89 | |