Jobs
10 months ago
Options
9 months ago
Views
1 year ago
Ajax.php
1 year ago
Assets.php
2 months ago
Hooks.php
9 months ago
Menu.php
1 year ago
PluginSettings.php
9 months ago
Proxy.php
11 months ago
Redirects.php
1 year ago
Assets.php
185 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Admin; |
| 4 | |
| 5 | use Hostinger\Admin\Menu; |
| 6 | use Hostinger\LlmsTxtGenerator\LlmsTxtFileHelper; |
| 7 | use Hostinger\WpMenuManager\Menus; |
| 8 | use Hostinger\Helper; |
| 9 | use Hostinger\WpHelper\Utils; |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * Class Hostinger_Admin_Assets |
| 15 | * |
| 16 | * Handles the enqueueing of styles and scripts for the Hostinger admin pages. |
| 17 | */ |
| 18 | class Assets { |
| 19 | /** |
| 20 | * @var Helper Instance of the Hostinger_Helper class. |
| 21 | */ |
| 22 | private Helper $helper; |
| 23 | |
| 24 | /** |
| 25 | * @var LlmsTxtFileHelper |
| 26 | */ |
| 27 | private LlmsTxtFileHelper $llms_txt_file_helper; |
| 28 | |
| 29 | /** |
| 30 | * @var Utils |
| 31 | */ |
| 32 | private Utils $utils; |
| 33 | |
| 34 | public function __construct() { |
| 35 | $this->llms_txt_file_helper = new LlmsTxtFileHelper(); |
| 36 | $this->helper = new Helper(); |
| 37 | $this->utils = new Utils(); |
| 38 | $admin_path = parse_url( admin_url(), PHP_URL_PATH ); |
| 39 | |
| 40 | // Load assets only on Hostinger admin pages. |
| 41 | if ( $this->utils->isThisPage( $admin_path . 'admin.php?page=' . Menu::MENU_SLUG ) || $this->utils->isThisPage( $admin_path . 'admin.php?page=' . Menus::MENU_SLUG ) ) { |
| 42 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); |
| 43 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
| 44 | } |
| 45 | if ( is_admin() ) { |
| 46 | add_action( 'admin_enqueue_scripts', array( $this, 'global_styles' ) ); |
| 47 | |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Enqueues styles for the Hostinger admin pages. |
| 53 | */ |
| 54 | public function admin_styles(): void { |
| 55 | // Vue frontend styles. |
| 56 | wp_enqueue_style( |
| 57 | 'hostinger_tools_styles', |
| 58 | HOSTINGER_VUE_ASSETS_URL . '/main.css', |
| 59 | array(), |
| 60 | HOSTINGER_WORDPRESS_PLUGIN_VERSION |
| 61 | ); |
| 62 | |
| 63 | // Plugin rating styles. |
| 64 | wp_enqueue_style( |
| 65 | 'hostinger_rating_styles', |
| 66 | HOSTINGER_ASSETS_URL . '/css/plugin-rating.min.css', |
| 67 | array(), |
| 68 | HOSTINGER_WORDPRESS_PLUGIN_VERSION |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | public function global_styles(): void { |
| 73 | wp_enqueue_style( |
| 74 | 'hostinger_tools_global_styles', |
| 75 | HOSTINGER_ASSETS_URL . 'css/hostinger-global.min.css', |
| 76 | array(), |
| 77 | HOSTINGER_WORDPRESS_PLUGIN_VERSION |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * Enqueues scripts for the Hostinger admin pages. |
| 85 | */ |
| 86 | public function admin_scripts(): void { |
| 87 | global $wp_version; |
| 88 | |
| 89 | wp_enqueue_script( |
| 90 | 'hostinger_tools_main_scripts', |
| 91 | HOSTINGER_VUE_ASSETS_URL . '/main.js', |
| 92 | array( |
| 93 | 'jquery', |
| 94 | 'wp-i18n', |
| 95 | ), |
| 96 | HOSTINGER_WORDPRESS_PLUGIN_VERSION, |
| 97 | false |
| 98 | ); |
| 99 | |
| 100 | wp_localize_script( |
| 101 | 'hostinger_tools_main_scripts', |
| 102 | 'hostinger_tools_data', |
| 103 | array( |
| 104 | 'home_url' => home_url(), |
| 105 | 'site_url' => get_site_url(), |
| 106 | 'plugin_url' => $this->helper->get_hostinger_plugin_url(), |
| 107 | 'asset_url' => HOSTINGER_PLUGIN_URL, |
| 108 | 'hplatform' => ! empty( $_SERVER['H_PLATFORM'] ) ? 1 : 0, |
| 109 | 'edit_site_url' => $this->helper->get_edit_site_url(), |
| 110 | 'llmstxt_file_url' => $this->llms_txt_file_helper->get_llmstxt_file_url(), |
| 111 | 'llmstxt_file_user_generated' => $this->llms_txt_file_helper->is_user_generated_file(), |
| 112 | 'translations' => array( |
| 113 | 'routes_tools' => __( 'Tools', 'hostinger' ), |
| 114 | 'hostinger_tools_open_guide' => __( 'Open guide', 'hostinger' ), |
| 115 | 'hostinger_tools_preview_site' => __( 'Preview site', 'hostinger' ), |
| 116 | 'hostinger_tools_edit_site' => __( 'Edit site', 'hostinger' ), |
| 117 | 'hostinger_tools_disable_public_access' => __( 'Disable public access to the site (WordPress admins will still be able to access)', 'hostinger' ), |
| 118 | 'hostinger_tools_skip_link_maintenance_mode' => __( 'Skip-link that bypasses the maintenance mode', 'hostinger' ), |
| 119 | 'hostinger_tools_reset_link' => __( 'Reset link', 'hostinger' ), |
| 120 | 'hostinger_tools_disable_xml_rpc' => __( 'Disable XML-RPC', 'hostinger' ), |
| 121 | 'hostinger_tools_xml_rpc_description' => __( 'XML-RPC allows apps to connect to your WordPress site, but might expose your site\'s security. Disable this feature if you don\'t need it', 'hostinger' ), |
| 122 | 'hostinger_tools_disable_authentication_password' => __( 'Disable application passwords', 'hostinger' ), |
| 123 | 'hostinger_tools_authentication_password_description' => __( 'WordPress application passwords allow users to authenticate API requests without using their main login credentials, allowing for third-party integrations.', 'hostinger' ), |
| 124 | |
| 125 | 'hostinger_tools_force_https' => __( 'Force HTTPS', 'hostinger' ), |
| 126 | 'hostinger_tools_force_https_description' => __( 'Redirects all HTTP URLs to HTTPS sites', 'hostinger' ), |
| 127 | 'hostinger_tools_force_www' => __( 'Force WWW', 'hostinger' ), |
| 128 | 'hostinger_tools_force_www_description' => __( 'Redirects all WWW URLs to non-WWW ones', 'hostinger' ), |
| 129 | 'hostinger_tools_force_www_description_not_available' => __( 'WWW and non-WWW domain records are not pointing to the same host. Redirect not possible.', 'hostinger' ), |
| 130 | 'hostinger_tools_php_version' => __( 'PHP version', 'hostinger' ), |
| 131 | 'hostinger_tools_wordpress_version' => __( 'WordPress version', 'hostinger' ), |
| 132 | 'hostinger_tools_php_version_description' => __( 'Various updates and fixes available in the newest version.', 'hostinger' ), |
| 133 | 'hostinger_tools_running_latest_version' => __( 'Running the latest version', 'hostinger' ), |
| 134 | 'hostinger_tools_update' => __( 'Update', 'hostinger' ), |
| 135 | 'hostinger_tools_update_to' => __( 'Update to', 'hostinger' ), |
| 136 | 'hostinger_tools_update_to_recommended' => __( 'is recommended', 'hostinger' ), |
| 137 | 'hostinger_tools_update_to_wordpress_version_description' => __( 'For improved security, ensure you use the latest version of WordPress', 'hostinger' ), |
| 138 | 'hostinger_tools_maintenance' => __( 'Maintenance', 'hostinger' ), |
| 139 | 'hostinger_tools_preview_my_website' => __( 'Preview my website', 'hostinger' ), |
| 140 | 'hostinger_tools_security' => __( 'Security', 'hostinger' ), |
| 141 | 'hostinger_tools_redirects' => __( 'Redirects', 'hostinger' ), |
| 142 | 'hostinger_tools_ai' => __( 'AI Tools', 'hostinger' ), |
| 143 | 'hostinger_tools_llms' => __( 'LLM Optimization', 'hostinger' ), |
| 144 | 'hostinger_tools_enable_llms_txt' => __( 'Create LLMs.txt file', 'hostinger' ), |
| 145 | 'hostinger_tools_llms_txt_description' => __( 'Let AI explore, understand, and interact with your WordPress site.', 'hostinger' ), |
| 146 | 'hostinger_tools_optin_mcp' => __( 'Web2Agent', 'hostinger' ), |
| 147 | 'hostinger_tools_optin_mcp_description' => __( 'Make your website easier for AI tools to understand. Website content updates will be tracked to keep the AI discovery service up to date.', 'hostinger' ), |
| 148 | 'hostinger_tools_llms_txt_learn_more' => __( 'Learn more', 'hostinger' ), |
| 149 | 'hostinger_tools_llms_txt_check_validity' => __( 'Check validity', 'hostinger' ), |
| 150 | 'hostinger_tools_llms_txt_llmstxt' => __( 'LLMS.txt', 'hostinger' ), |
| 151 | 'hostinger_tools_llms_txt_external_file_found' => __( 'An external LLMs.txt file was found. Switching on the toggle will replace it with a new one.', 'hostinger' ), |
| 152 | 'hostinger_tools_llms_txt_modal_title' => __( 'Create new LLMs.txt file?', 'hostinger' ), |
| 153 | 'hostinger_tools_llms_txt_modal_description' => __( 'This will replace the existing LLMs.txt file with a new one by Hostinger Tools. The original file can’t be restored.', 'hostinger' ), |
| 154 | 'hostinger_tools_llms_txt_modal_cancel' => __( 'Cancel', 'hostinger' ), |
| 155 | 'hostinger_tools_llms_txt_modal_create_file' => __( 'Create file', 'hostinger' ), |
| 156 | 'hostinger_tools_maintenance_mode' => __( 'Maintenance mode', 'hostinger' ), |
| 157 | 'hostinger_tools_bypass_link' => __( 'Bypass link', 'hostinger' ), |
| 158 | 'xml_security_modal_description' => __( ' Turning on XML-RPC might make your site less secure. Do you want to proceed?', 'hostinger' ), |
| 159 | 'xml_security_modal_title' => __( 'Disclaimer', 'hostinger' ), |
| 160 | 'xml_security_modal_cancel' => __( 'Cancel', 'hostinger' ), |
| 161 | 'xml_security_modal_proceed_anyway' => __( 'Proceed anyway', 'hostinger' ), |
| 162 | 'bypass_link_reset_modal_title' => __( 'Bypass link reset', 'hostinger' ), |
| 163 | 'bypass_link_reset_modal_description' => __( 'This will invalidate the currently generated link in use. This action cannot be undone, are you sure you want to proceed?', 'hostinger' ), |
| 164 | 'bypass_link_reset_modal_cancel' => __( 'Cancel', 'hostinger' ), |
| 165 | 'bypass_link_reset_modal_reset_link' => __( 'Reset link', 'hostinger' ), |
| 166 | 'bypass_link_reset_success' => __( 'Link has been reset', 'hostinger' ), |
| 167 | 'hostinger_tools_settings_updated' => __( 'Your settings have been updated', 'hostinger' ), |
| 168 | 'hostinger_tools_settings_error' => __( 'It was an error updating your settings', 'hostinger' ), |
| 169 | 'hostinger_tools_mcp_description' => __( 'Let Kodee manage your site on your behalf. This allows Kodee to perform actions like creating pages or updating settings. We will install and pre-configure the WordPress MCP plugin for you.', 'hostinger' ), |
| 170 | 'hostinger_tools_copied_successfully' => __( 'Copied successfully', 'hostinger' ), |
| 171 | 'hostinger_tools_text_copied_successfully' => __( 'Text has been copied successfully', 'hostinger' ), |
| 172 | 'hostinger_tools_free_domain_llm_unavailable' => __( 'LLM optimization features are not available for temporary subdomains. Connect a domain to unlock these features.', 'hostinger' ), |
| 173 | 'hostinger_tools_connect_domain_cta' => __( 'Connect domain', 'hostinger' ), |
| 174 | 'hostinger_tools_copy_agent_url' => __( 'Copy agent url', 'hostinger' ), |
| 175 | ), |
| 176 | 'rest_base_url' => esc_url_raw( rest_url() ), |
| 177 | 'nonce' => wp_create_nonce( 'wp_rest' ), |
| 178 | 'wp_version' => $wp_version, |
| 179 | 'php_version' => phpversion(), |
| 180 | 'recommended_php_version' => $this->helper->get_recommended_php_version(), |
| 181 | ) |
| 182 | ); |
| 183 | } |
| 184 | } |
| 185 |