| @@ -3,32 +3,104 @@ | ||
| 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 ); | |
| 16 | 30 | |
| 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 ); | |
| 31 | + if ( Hostinger_Helper::show_woocommerce_onboarding() ) { | |
| 32 | + wp_enqueue_style( 'hostinger_woo_onboarding', HOSTINGER_ASSETS_URL . '/css/woo-onboarding.css', array(), HOSTINGER_VERSION ); | |
| 33 | + } | |
| 19 | 34 | } |
| 35 | + | |
| 36 | + wp_enqueue_style( 'hostinger_global_styles', HOSTINGER_ASSETS_URL . '/css/global.css', array(), HOSTINGER_VERSION ); | |
| 37 | + | |
| 38 | + if ( $this->helper->is_preview_domain() && is_user_logged_in() ) { | |
| 39 | + wp_enqueue_style( 'hostinger-preview-styles', HOSTINGER_ASSETS_URL . '/css/hts-preview.css', array(), HOSTINGER_VERSION ); | |
| 40 | + } | |
| 20 | 41 | } |
| 21 | 42 | |
| 43 | + /** | |
| 44 | + * Enqueues scripts for the Hostinger admin pages. | |
| 45 | + */ | |
| 22 | 46 | 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 ); | |
| 47 | + if ( $this->helper->is_hostinger_admin_page() ) { | |
| 48 | + wp_enqueue_script( | |
| 49 | + 'hostinger_main_scripts', | |
| 50 | + HOSTINGER_ASSETS_URL . '/js/main.js', | |
| 51 | + array( | |
| 52 | + 'jquery', | |
| 53 | + 'wp-i18n', | |
| 54 | + ), | |
| 55 | + HOSTINGER_VERSION, | |
| 56 | + false | |
| 57 | + ); | |
| 24 | 58 | |
| 59 | + if ( Hostinger_Helper::show_woocommerce_onboarding() ) { | |
| 60 | + wp_enqueue_script( | |
| 61 | + 'hostinger_woo_onboarding', | |
| 62 | + HOSTINGER_ASSETS_URL . '/js/woo-onboarding.js', | |
| 63 | + array( | |
| 64 | + 'jquery', | |
| 65 | + 'wp-i18n', | |
| 66 | + ), | |
| 67 | + HOSTINGER_VERSION, | |
| 68 | + false | |
| 69 | + ); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + wp_enqueue_script( | |
| 74 | + 'hostinger_global_scripts', | |
| 75 | + HOSTINGER_ASSETS_URL . '/js/global-scripts.js', | |
| 76 | + array( | |
| 77 | + 'jquery', | |
| 78 | + 'wp-i18n', | |
| 79 | + ), | |
| 80 | + HOSTINGER_VERSION, | |
| 81 | + false | |
| 82 | + ); | |
| 83 | + | |
| 25 | 84 | 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 | - )); | |
| 85 | + wp_enqueue_script( | |
| 86 | + 'hostinger_requests_scripts', | |
| 87 | + HOSTINGER_ASSETS_URL . '/js/requests.js', | |
| 88 | + array( | |
| 89 | + 'jquery', | |
| 90 | + 'wp-i18n', | |
| 91 | + ), | |
| 92 | + HOSTINGER_VERSION, | |
| 93 | + false | |
| 94 | + ); | |
| 95 | + wp_localize_script( | |
| 96 | + 'hostinger_requests_scripts', | |
| 97 | + 'hostingerContainer', | |
| 98 | + array( | |
| 99 | + 'url' => admin_url( 'admin-ajax.php' ), | |
| 100 | + 'nonce' => wp_create_nonce( 'hts-ajax-nonce' ), | |
| 101 | + ) | |
| 102 | + ); | |
| 31 | 103 | } |
| 32 | 104 | } |
| 33 | 105 | } |
| 34 | 106 | |