| 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 |
|
| 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 |
} |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Enqueues scripts for the Hostinger admin pages. |
| 39 |
*/ |
| 40 |
public function admin_scripts(): void { |
| 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 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
new Hostinger_Admin_Assets(); |
| 67 |
|