| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger\Admin; |
| 4 |
|
| 5 |
use Hostinger\Helper; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
/** |
| 10 |
* Class Hostinger_Admin_Assets |
| 11 |
* |
| 12 |
* Handles the enqueueing of styles and scripts for the Hostinger admin pages. |
| 13 |
*/ |
| 14 |
class Assets { |
| 15 |
/** |
| 16 |
* @var Helper Instance of the Hostinger_Helper class. |
| 17 |
*/ |
| 18 |
private Helper $helper; |
| 19 |
|
| 20 |
public function __construct() { |
| 21 |
$this->helper = new Helper(); |
| 22 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); |
| 23 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Enqueues styles for the Hostinger admin pages. |
| 28 |
*/ |
| 29 |
public function admin_styles(): void { |
| 30 |
if ( $this->helper->is_hostinger_admin_page() ) { |
| 31 |
wp_enqueue_style( 'hostinger_main_styles', HOSTINGER_ASSETS_URL . '/css/main.css', array(), HOSTINGER_VERSION ); |
| 32 |
|
| 33 |
if ( Helper::show_woocommerce_onboarding() ) { |
| 34 |
wp_enqueue_style( 'hostinger_woo_onboarding', HOSTINGER_ASSETS_URL . '/css/woo-onboarding.css', array(), HOSTINGER_VERSION ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
wp_enqueue_style( 'hostinger_global_styles', HOSTINGER_ASSETS_URL . '/css/global.css', array(), HOSTINGER_VERSION ); |
| 39 |
|
| 40 |
if ( $this->helper->is_preview_domain() && is_user_logged_in() ) { |
| 41 |
wp_enqueue_style( 'hostinger-preview-styles', HOSTINGER_ASSETS_URL . '/css/hts-preview.css', array(), HOSTINGER_VERSION ); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Enqueues scripts for the Hostinger admin pages. |
| 47 |
*/ |
| 48 |
public function admin_scripts(): void { |
| 49 |
if ( $this->helper->is_hostinger_admin_page() ) { |
| 50 |
wp_enqueue_script( |
| 51 |
'hostinger_main_scripts', |
| 52 |
HOSTINGER_ASSETS_URL . '/js/main.js', |
| 53 |
array( |
| 54 |
'jquery', |
| 55 |
'wp-i18n', |
| 56 |
), |
| 57 |
HOSTINGER_VERSION, |
| 58 |
false |
| 59 |
); |
| 60 |
|
| 61 |
if ( Helper::show_woocommerce_onboarding() ) { |
| 62 |
wp_enqueue_script( |
| 63 |
'hostinger_woo_onboarding', |
| 64 |
HOSTINGER_ASSETS_URL . '/js/woo-onboarding.js', |
| 65 |
array( |
| 66 |
'jquery', |
| 67 |
'wp-i18n', |
| 68 |
), |
| 69 |
HOSTINGER_VERSION, |
| 70 |
false |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
wp_enqueue_script( |
| 76 |
'hostinger_global_scripts', |
| 77 |
HOSTINGER_ASSETS_URL . '/js/global-scripts.js', |
| 78 |
array( |
| 79 |
'jquery', |
| 80 |
'wp-i18n', |
| 81 |
), |
| 82 |
HOSTINGER_VERSION, |
| 83 |
false |
| 84 |
); |
| 85 |
|
| 86 |
if ( ! empty( Helper::get_api_token() ) ) { |
| 87 |
wp_enqueue_script( |
| 88 |
'hostinger_requests_scripts', |
| 89 |
HOSTINGER_ASSETS_URL . '/js/requests.js', |
| 90 |
array( |
| 91 |
'jquery', |
| 92 |
'wp-i18n', |
| 93 |
), |
| 94 |
HOSTINGER_VERSION, |
| 95 |
array( 'strategy' => 'defer' ) |
| 96 |
); |
| 97 |
wp_localize_script( |
| 98 |
'hostinger_requests_scripts', |
| 99 |
'hostingerContainer', |
| 100 |
array( |
| 101 |
'url' => admin_url( 'admin-ajax.php' ), |
| 102 |
'nonce' => wp_create_nonce( 'hts-ajax-nonce' ), |
| 103 |
) |
| 104 |
); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|