PluginProbe
Hostinger Tools / 2.0.9
Hostinger Tools v2.0.9
3.0.79 3.0.78 3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 All 110 releases
← All changes | includes/class-hostinger-helper.php +142 -5 2.0.0 → 2.0.9 View file →
@@ -1,10 +1,25 @@
1 1 <?php
2 2
3 3 class Hostinger_Helper {
4 4 public const HOSTINGER_FREE_SUBDOMAIN_URL = 'hostingersite.com';
5 - public const HOSTINGER_PAGE = '/wp-admin/admin.php?page=hostinger';
5 + public const HOSTINGER_PAGE = '/wp-admin/admin.php?page=hostinger';
6 + public const CLIENT_WOO_COMPLETED_ACTIONS = 'woocommerce_task_list_tracked_completed_tasks';
7 + private const PROMOTIONAL_LINKS = array(
8 + 'fr_FR' => 'https://www.hostinger.fr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
9 + 'es_ES' => 'https://www.hostinger.es/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
10 + 'ar' => 'https://www.hostinger.ae/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
11 + 'zh_CN' => 'https://www.hostinger.com.hk/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
12 + 'id_ID' => 'https://www.hostinger.co.id/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
13 + 'lt_LT' => 'https://www.hostinger.lt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
14 + 'pt_PT' => 'https://www.hostinger.pt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
15 + 'uk' => 'https://www.hostinger.com.ua/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
16 + 'tr_TR' => 'https://www.hostinger.com.tr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
17 + 'en_US' => 'https://www.hostinger.com/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
18 + );
6 19
20 + private const HPANEL_DOMAIN_URL = 'https://hpanel.hostinger.com/websites/';
21 +
7 22 /**
8 23 *
9 24 * Check if plugin is active
10 25 *
@@ -28,9 +43,8 @@
28 43
29 44 if ( file_exists( $token_file ) && ! empty( file_get_contents( $token_file ) ) ) {
30 45 $api_token = file_get_contents( $token_file );
31 46 }
32 -
33 47 return $api_token;
34 48 }
35 49
36 50 /**
@@ -39,11 +53,10 @@
39 53 *
40 54 * @since 1.7.0
41 55 * @access public
42 56 */
43 -
44 57 public function get_host_info(): string {
45 - $host = $_SERVER['HTTP_HOST'] ?? '';
58 + $host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( $_SERVER['HTTP_HOST'] ) : '';
46 59 $site_url = get_site_url();
47 60 $site_url = preg_replace( '#^https?://#', '', $site_url );
48 61
49 62 if ( ! empty( $site_url ) && ! empty( $host ) && strpos( $site_url, $host ) === 0 ) {
@@ -76,9 +89,9 @@
76 89 }
77 90
78 91 public function is_hostinger_admin_page(): bool {
79 92
80 - if( ! isset( $_SERVER['REQUEST_URI'] ) ) {
93 + if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
81 94 return false;
82 95 }
83 96
84 97 $current_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
@@ -108,8 +121,132 @@
108 121 public function error_log( string $message ): void {
109 122 if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
110 123 error_log( print_r( $message, true ) );
111 124 }
125 + }
126 +
127 + public function default_woocommerce_survey_steps_completed( array $steps ): bool {
128 + $completed_actions = get_option( self::CLIENT_WOO_COMPLETED_ACTIONS, array() );
129 +
130 + return empty( array_diff( $steps, $completed_actions ) );
131 + }
132 +
133 + public function is_this_page( string $page ): bool {
134 +
135 + if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
136 + return false;
137 + }
138 +
139 + $current_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
140 +
141 + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
142 + return false;
143 + }
144 +
145 + if ( isset( $current_uri ) && strpos( $current_uri, '/wp-json/' ) !== false ) {
146 + return false;
147 + }
148 +
149 + if ( strpos( $current_uri, $page ) !== false ) {
150 + return true;
151 + }
152 +
153 + return false;
154 + }
155 +
156 + public function get_promotional_link_url( string $locale ): string {
157 + if ( isset( self::PROMOTIONAL_LINKS[ $locale ] ) ) {
158 + return self::PROMOTIONAL_LINKS[ $locale ];
159 + }
160 +
161 + return self::PROMOTIONAL_LINKS['en_US'];
162 + }
163 +
164 + public function get_domain_from_url(): string {
165 + $host = parse_url( get_site_url(), PHP_URL_HOST );
166 +
167 + return $host === false ? self::HPANEL_DOMAIN_URL : $host;
168 + }
169 +
170 + public function get_hpanel_domain_url(): string {
171 + $domain_url = $this->get_domain_from_url();
172 +
173 + if ( $domain_url === self::HPANEL_DOMAIN_URL ) {
174 + return $domain_url;
175 + }
176 +
177 + return self::HPANEL_DOMAIN_URL . $domain_url;
178 + }
179 +
180 + public function check_transient_eligibility( $transient_request_key, $cache_time = 3600 ): bool {
181 + try {
182 + // Set transient
183 + set_transient( $transient_request_key, true, $cache_time );
184 +
185 + // Check if transient was set successfully
186 + if ( false === get_transient( $transient_request_key ) ) {
187 + throw new Exception( 'Unable to create transient in WordPress.' );
188 + }
189 +
190 + // If everything is fine, return true
191 + return true;
192 + } catch ( Exception $exception ) {
193 + // If there's an exception, log the error and return false
194 + $this->error_log( 'Error checking eligibility: ' . $exception->getMessage() );
195 + return false;
196 + }
197 + }
198 +
199 + public static function woocommerce_onboarding_choice(): bool {
200 + return (bool) get_option( 'hostinger_woo_onboarding_choice', false );
201 + }
202 +
203 + /**
204 + * @return bool
205 + */
206 + public static function is_woocommerce_site(): bool {
207 + return class_exists( 'WooCommerce' );
208 + }
209 +
210 + /**
211 + * @return bool
212 + */
213 + public static function show_woocommerce_onboarding(): bool {
214 + $woo_onboarding_enabled = get_option( 'hostinger_woo_onboarding_enabled', false );
215 + $woo_setup_wizard_completed = get_option( 'woocommerce_onboarding_profile', false );
216 +
217 + return ( self::is_woocommerce_site() && ! self::woocommerce_onboarding_choice() && $woo_onboarding_enabled && ! $woo_setup_wizard_completed );
218 + }
219 +
220 + /**
221 + * @return bool
222 + */
223 + public function can_show_store_ready_message(): bool {
224 + if ( ! self::is_woocommerce_site() || ! self::woocommerce_onboarding_choice() ) {
225 + return false;
226 + }
227 +
228 + $store_ready_message_shown = get_option( 'hostinger_woo_ready_message_shown', null );
229 +
230 + if ( $store_ready_message_shown === null ) {
231 + return false;
232 + }
233 +
234 + if ( (int) $store_ready_message_shown !== 0 ) {
235 + return false;
236 + }
237 +
238 + if ( ! $this->default_woocommerce_survey_completed() ) {
239 + return false;
240 + }
241 +
242 + return true;
243 + }
244 +
245 + public function default_woocommerce_survey_completed(): bool {
246 + $completed_actions = get_option( self::CLIENT_WOO_COMPLETED_ACTIONS, array() );
247 + $required_completed_actions = array( 'products', 'payments' );
248 + return empty( array_diff( $required_completed_actions, $completed_actions ) );
112 249 }
113 250 }
114 251
115 252 $hostinger_helper = new Hostinger_Helper();