PluginProbe
Hostinger Tools / 3.0.33
Hostinger Tools v3.0.33
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 2.0.1 2.0.4 All 108 releases
hostinger / includes / Helper.php

Helper.php in Hostinger Tools 3.0.33, at includes/Helper.php

173 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hostinger;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Helper {
8 const HOSTINGER_LOCALES = [
9 'lt_LT' => 'hostinger.lt',
10 'uk_UA' => 'hostinger.com.ua',
11 'id_ID' => 'hostinger.co.id',
12 'en_US' => 'hostinger.com',
13 'es_ES' => 'hostinger.es',
14 'es_AR' => 'hostinger.com.ar',
15 'es_MX' => 'hostinger.mx',
16 'es_CO' => 'hostinger.co',
17 'pt_BR' => 'hostinger.com.br',
18 'ro_RO' => 'hostinger.ro',
19 'fr_FR' => 'hostinger.fr',
20 'it_IT' => 'hostinger.it',
21 'pl_PL' => 'hostinger.pl',
22 'en_PH' => 'hostinger.ph',
23 'ar_AE' => 'hostinger.ae',
24 'ms_MY' => 'hostinger.my',
25 'ko_KR' => 'hostinger.kr',
26 'vi_VN' => 'hostinger.vn',
27 'th_TH' => 'hostinger.in.th',
28 'tr_TR' => 'hostinger.web.tr',
29 'pt_PT' => 'hostinger.pt',
30 'de_DE' => 'hostinger.de',
31 'en_IN' => 'hostinger.in',
32 'ja_JP' => 'hostinger.jp',
33 'nl_NL' => 'hostinger.nl',
34 'en_GB' => 'hostinger.co.uk',
35 'el_GR' => 'hostinger.gr',
36 'cs_CZ' => 'hostinger.cz',
37 'hu_HU' => 'hostinger.hu',
38 'sv_SE' => 'hostinger.se',
39 'da_DK' => 'hostinger.dk',
40 'fi_FI' => 'hostinger.fi',
41 'sk_SK' => 'hostinger.sk',
42 'no_NO' => 'hostinger.no',
43 'hr_HR' => 'hostinger.hr',
44 'zh_HK' => 'hostinger.com.hk',
45 'he_IL' => 'hostinger.co.il',
46 'lv_LV' => 'hostinger.lv',
47 'et_EE' => 'hostinger.ee',
48 'ur_PK' => 'hostinger.pk',
49 ];
50
51 /**
52 *
53 * Check if plugin is active
54 *
55 * @since 1.0.0
56 * @access public
57 */
58 public static function is_plugin_active( $plugin_slug ): bool {
59 $active_plugins = (array) get_option( 'active_plugins', array() );
60 foreach ( $active_plugins as $active_plugin ) {
61 if ( strpos( $active_plugin, $plugin_slug . '.php' ) !== false ) {
62 return true;
63 }
64 }
65
66 return false;
67 }
68
69 public function is_preview_domain( $headers = null ): bool {
70 // @codeCoverageIgnoreStart
71 if ( $headers === null && function_exists( 'getallheaders' ) ) {
72 $headers = getallheaders();
73 }
74 // @codeCoverageIgnoreEnd
75 if ( isset( $headers['X-Preview-Indicator'] ) && $headers['X-Preview-Indicator'] ) {
76 return true;
77 }
78
79 return false;
80 }
81
82 public static function woocommerce_onboarding_choice(): bool {
83 return (bool) get_option( 'hostinger_woo_onboarding_choice', false );
84 }
85
86 public static function generate_bypass_code( $length ) {
87 $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
88 $code = '';
89 $max_index = strlen( $characters ) - 1;
90
91 for ( $i = 0; $i < $length; $i++ ) {
92 $random_index = wp_rand( 0, $max_index );
93 $code .= $characters[ $random_index ];
94 }
95
96 return $code;
97 }
98
99 public function should_plugin_split_notice_shown() {
100 $plugin_split_notice_hidden = get_option( 'hts_plugin_split_notice_hidden', false );
101
102 if ( $plugin_split_notice_hidden !== false ) {
103 return false;
104 }
105
106 if ( ! version_compare( HOSTINGER_VERSION, '3.0.0', '>=' ) ) {
107 return false;
108 }
109
110 if ( is_plugin_active( 'hostinger-easy-onboarding/hostinger-easy-onboarding.php' ) ) {
111 return false;
112 }
113
114 return true;
115 }
116
117 public function get_hostinger_plugin_url() : string {
118 $websiteLocale = get_locale() ?? 'en_US';
119 $resellerLocale = get_option( 'hostinger_reseller', '' );
120 $baseDomain = $resellerLocale ? : ( self::HOSTINGER_LOCALES[$websiteLocale] ?? 'hostinger.com' );
121
122 $pluginUrl = rtrim( $baseDomain, '/' ) . '/';
123 $pluginUrl .= str_replace( ABSPATH, '', HOSTINGER_ABSPATH );
124
125 return $pluginUrl;
126 }
127
128 public function get_recommended_php_version(): string {
129 $wp_version = get_bloginfo('version');
130
131 if (empty($wp_version)) {
132 return '8.2';
133 }
134
135 // Remove any additional version info (like -RC1, -beta1, etc.)
136 $wp_version = preg_replace('/[-+].*$/', '', $wp_version);
137
138 // Version specific recommendations
139 if (version_compare($wp_version, '6.6', '>=')) {
140 return '8.2'; // Latest recommended version for WP 6.6+
141 }
142
143 if (version_compare($wp_version, '6.3', '>=')) {
144 return '8.1'; // Recommended for WP 6.3-6.5
145 }
146
147 if (version_compare($wp_version, '5.3', '>=')) {
148 return '7.4'; // Recommended for WP 5.3-6.2
149 }
150
151 if (version_compare($wp_version, '5.0', '>=')) {
152 return '7.3'; // Recommended for WP 5.0-5.2
153 }
154
155 if (version_compare($wp_version, '4.9', '=')) {
156 return '7.2'; // Recommended for WP 4.9
157 }
158
159 if (version_compare($wp_version, '4.7', '>=')) {
160 return '7.1'; // Recommended for WP 4.7-4.8
161 }
162
163 if (version_compare($wp_version, '4.4', '>=')) {
164 return '7.0'; // Recommended for WP 4.4-4.6
165 }
166
167 // For versions below 4.9
168 return '5.6';
169 }
170 }
171
172 $hostinger_helper = new Helper();
173