| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
class Hostinger_Admin_Assets { |
| 8 |
public function __construct() { |
| 9 |
add_action( 'admin_enqueue_scripts', [ $this, 'admin_styles' ] ); |
| 10 |
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] ); |
| 11 |
} |
| 12 |
|
| 13 |
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 ); |
| 16 |
|
| 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 ); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
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 ); |
| 24 |
|
| 25 |
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 |
)); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
new Hostinger_Admin_Assets(); |
| 36 |
|