| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Class Hostinger_Admin_Assets |
| 9 |
* |
| 10 |
* Handles the enqueueing of styles and scripts for the Hostinger admin pages. |
| 11 |
*/ |
| 12 |
class Hostinger_Admin_Assets { |
| 13 |
/** |
| 14 |
* @var Hostinger_Helper Instance of the Hostinger_Helper class. |
| 15 |
*/ |
| 16 |
private Hostinger_Helper $helper; |
| 17 |
|
| 18 |
public function __construct() { |
| 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' ) ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Enqueues styles for the Hostinger admin pages. |
| 26 |
*/ |
| 27 |
public function admin_styles(): void { |
| 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 |
if ( Hostinger_Helper::show_woocommerce_onboarding() ) { |
| 32 |
wp_enqueue_style( 'hostinger_woo_onboarding', HOSTINGER_ASSETS_URL . '/css/woo-onboarding.css', array(), HOSTINGER_VERSION ); |
| 33 |
} |
| 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 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Enqueues scripts for the Hostinger admin pages. |
| 45 |
*/ |
| 46 |
public function admin_scripts(): void { |
| 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 |
); |
| 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 |
|
| 84 |
if ( ! empty( Hostinger_Helper::get_api_token() ) ) { |
| 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 |
); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
new Hostinger_Admin_Assets(); |
| 108 |
|