| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
class Helper { |
| 8 |
const HOSTINGER_LOCALES = array( |
| 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 |
public const HOMEPAGE_DISPLAY = 'page'; |
| 52 |
|
| 53 |
/** |
| 54 |
* |
| 55 |
* Check if plugin is active |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* @access public |
| 59 |
*/ |
| 60 |
public static function is_plugin_active( $plugin_slug ): bool { |
| 61 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
| 62 |
foreach ( $active_plugins as $active_plugin ) { |
| 63 |
if ( strpos( $active_plugin, $plugin_slug . '.php' ) !== false ) { |
| 64 |
return true; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
public function is_preview_domain( $headers = null ): bool { |
| 72 |
// @codeCoverageIgnoreStart |
| 73 |
if ( $headers === null && function_exists( 'getallheaders' ) ) { |
| 74 |
$headers = getallheaders(); |
| 75 |
} |
| 76 |
// @codeCoverageIgnoreEnd |
| 77 |
if ( isset( $headers['X-Preview-Indicator'] ) && $headers['X-Preview-Indicator'] ) { |
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
public static function woocommerce_onboarding_choice(): bool { |
| 85 |
return (bool) get_option( 'hostinger_woo_onboarding_choice', false ); |
| 86 |
} |
| 87 |
|
| 88 |
public static function generate_bypass_code( $length ) { |
| 89 |
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 90 |
$code = ''; |
| 91 |
$max_index = strlen( $characters ) - 1; |
| 92 |
|
| 93 |
for ( $i = 0; $i < $length; $i++ ) { |
| 94 |
$random_index = wp_rand( 0, $max_index ); |
| 95 |
$code .= $characters[ $random_index ]; |
| 96 |
} |
| 97 |
|
| 98 |
return $code; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function get_hostinger_plugin_url(): string { |
| 104 |
$website_locale = get_locale() ?? 'en_US'; |
| 105 |
$reseller_locale = get_option( 'hostinger_reseller', null ); |
| 106 |
$base_domain = $reseller_locale ?? ( self::HOSTINGER_LOCALES[ $website_locale ] ?? 'hostinger.com' ); |
| 107 |
|
| 108 |
$plugin_url = rtrim( $base_domain, '/' ) . '/'; |
| 109 |
$plugin_url .= str_replace( ABSPATH, '', HOSTINGER_ABSPATH ); |
| 110 |
|
| 111 |
return $plugin_url; |
| 112 |
} |
| 113 |
|
| 114 |
public function get_recommended_php_version(): string { |
| 115 |
$wp_version = get_bloginfo( 'version' ); |
| 116 |
|
| 117 |
if ( empty( $wp_version ) ) { |
| 118 |
return '8.2'; |
| 119 |
} |
| 120 |
|
| 121 |
// Remove any additional version info (like -RC1, -beta1, etc.). |
| 122 |
$wp_version = preg_replace( '/[-+].*$/', '', $wp_version ); |
| 123 |
|
| 124 |
if ( version_compare( $wp_version, '6.6', '>=' ) ) { |
| 125 |
return '8.2'; |
| 126 |
} |
| 127 |
|
| 128 |
if ( version_compare( $wp_version, '6.3', '>=' ) ) { |
| 129 |
return '8.1'; |
| 130 |
} |
| 131 |
|
| 132 |
if ( version_compare( $wp_version, '5.3', '>=' ) ) { |
| 133 |
return '7.4'; |
| 134 |
} |
| 135 |
|
| 136 |
if ( version_compare( $wp_version, '5.0', '>=' ) ) { |
| 137 |
return '7.3'; |
| 138 |
} |
| 139 |
|
| 140 |
if ( version_compare( $wp_version, '4.9', '=' ) ) { |
| 141 |
return '7.2'; |
| 142 |
} |
| 143 |
|
| 144 |
if ( version_compare( $wp_version, '4.7', '>=' ) ) { |
| 145 |
return '7.1'; |
| 146 |
} |
| 147 |
|
| 148 |
if ( version_compare( $wp_version, '4.4', '>=' ) ) { |
| 149 |
return '7.0'; |
| 150 |
} |
| 151 |
|
| 152 |
return '5.6'; |
| 153 |
} |
| 154 |
|
| 155 |
public function get_edit_site_url(): string { |
| 156 |
if ( wp_is_block_theme() ) { |
| 157 |
return add_query_arg( |
| 158 |
array( |
| 159 |
'canvas' => 'edit', |
| 160 |
), |
| 161 |
admin_url( 'site-editor.php' ) |
| 162 |
); |
| 163 |
} |
| 164 |
|
| 165 |
$show_on_front = get_option( 'show_on_front' ); |
| 166 |
$front_page_id = get_option( 'page_on_front' ); |
| 167 |
|
| 168 |
if ( $show_on_front === self::HOMEPAGE_DISPLAY && $front_page_id ) { |
| 169 |
return add_query_arg( |
| 170 |
array( |
| 171 |
'post' => $front_page_id, |
| 172 |
'action' => 'edit', |
| 173 |
), |
| 174 |
admin_url( 'post.php' ) |
| 175 |
); |
| 176 |
} |
| 177 |
|
| 178 |
return ''; |
| 179 |
} |
| 180 |
} |
| 181 |
|