| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
class Helper { |
| 8 |
public const HOSTINGER_FREE_SUBDOMAIN_URL = 'hostingersite.com'; |
| 9 |
public const HOSTINGER_PAGE = '/wp-admin/admin.php?page=hostinger'; |
| 10 |
public const CLIENT_WOO_COMPLETED_ACTIONS = 'woocommerce_task_list_tracked_completed_tasks'; |
| 11 |
private const PROMOTIONAL_LINKS = array( |
| 12 |
'fr_FR' => 'https://www.hostinger.fr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 13 |
'es_ES' => 'https://www.hostinger.es/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 14 |
'ar' => 'https://www.hostinger.ae/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 15 |
'zh_CN' => 'https://www.hostinger.com.hk/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 16 |
'id_ID' => 'https://www.hostinger.co.id/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 17 |
'lt_LT' => 'https://www.hostinger.lt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 18 |
'pt_PT' => 'https://www.hostinger.pt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 19 |
'uk' => 'https://www.hostinger.com.ua/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 20 |
'tr_TR' => 'https://www.hostinger.com.tr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 21 |
'en_US' => 'https://www.hostinger.com/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin', |
| 22 |
); |
| 23 |
|
| 24 |
private const HPANEL_DOMAIN_URL = 'https://hpanel.hostinger.com/websites/'; |
| 25 |
|
| 26 |
/** |
| 27 |
* |
| 28 |
* Check if plugin is active |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @access public |
| 32 |
*/ |
| 33 |
public static function is_plugin_active( $plugin_slug ): bool { |
| 34 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
| 35 |
foreach ( $active_plugins as $active_plugin ) { |
| 36 |
if ( strpos( $active_plugin, $plugin_slug . '.php' ) !== false ) { |
| 37 |
return true; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
public function is_preview_domain( $headers = null ): bool { |
| 45 |
// @codeCoverageIgnoreStart |
| 46 |
if ( $headers === null && function_exists( 'getallheaders' ) ) { |
| 47 |
$headers = getallheaders(); |
| 48 |
} |
| 49 |
// @codeCoverageIgnoreEnd |
| 50 |
if ( isset( $headers['X-Preview-Indicator'] ) && $headers['X-Preview-Indicator'] ) { |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
public static function woocommerce_onboarding_choice(): bool { |
| 58 |
return (bool) get_option( 'hostinger_woo_onboarding_choice', false ); |
| 59 |
} |
| 60 |
|
| 61 |
public static function generate_bypass_code( $length ) { |
| 62 |
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 63 |
$code = ''; |
| 64 |
$max_index = strlen( $characters ) - 1; |
| 65 |
|
| 66 |
for ( $i = 0; $i < $length; $i++ ) { |
| 67 |
$random_index = wp_rand( 0, $max_index ); |
| 68 |
$code .= $characters[ $random_index ]; |
| 69 |
} |
| 70 |
|
| 71 |
return $code; |
| 72 |
} |
| 73 |
|
| 74 |
public function should_plugin_split_notice_shown() { |
| 75 |
$plugin_split_notice_hidden = get_transient( 'hts_plugin_split_notice_hidden' ); |
| 76 |
|
| 77 |
if ( $plugin_split_notice_hidden !== false ) { |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
if ( ! version_compare( HOSTINGER_VERSION, '3.0.0', '>=' ) ) { |
| 82 |
return false; |
| 83 |
} |
| 84 |
|
| 85 |
if ( is_plugin_active( 'hostinger-easy-onboarding/hostinger-easy-onboarding.php' ) ) { |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
return true; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
$hostinger_helper = new Helper(); |
| 94 |
|