| @@ -1,12 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Hostinger; |
| 4 | 4 | |
| 5 | + | |
| 6 | +use Hostinger\LlmsTxtGenerator\LlmsTxtFileHelper; | |
| 7 | + | |
| 5 | 8 | defined( 'ABSPATH' ) || exit; |
| 6 | 9 | |
| 7 | 10 | class Helper { |
| 8 | - const HOSTINGER_LOCALES = array( | |
| 11 | + const HOSTINGER_LOCALES = [ | |
| 9 | 12 | 'lt_LT' => 'hostinger.lt', |
| 10 | 13 | 'uk_UA' => 'hostinger.com.ua', |
| 11 | 14 | 'id_ID' => 'hostinger.co.id', |
| 12 | 15 | 'en_US' => 'hostinger.com', |
| @@ -45,122 +48,137 @@ | ||
| 45 | 48 | 'he_IL' => 'hostinger.co.il', |
| 46 | 49 | 'lv_LV' => 'hostinger.lv', |
| 47 | 50 | 'et_EE' => 'hostinger.ee', |
| 48 | 51 | 'ur_PK' => 'hostinger.pk', |
| 49 | - ); | |
| 52 | + ]; | |
| 50 | 53 | |
| 51 | 54 | public const HOMEPAGE_DISPLAY = 'page'; |
| 52 | 55 | |
| 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 | - } | |
| 56 | + /** | |
| 57 | + * | |
| 58 | + * Check if plugin is active | |
| 59 | + * | |
| 60 | + * @since 1.0.0 | |
| 61 | + * @access public | |
| 62 | + */ | |
| 63 | + public static function is_plugin_active( $plugin_slug ): bool { | |
| 64 | + $active_plugins = (array) get_option( 'active_plugins', array() ); | |
| 65 | + foreach ( $active_plugins as $active_plugin ) { | |
| 66 | + if ( strpos( $active_plugin, $plugin_slug . '.php' ) !== false ) { | |
| 67 | + return true; | |
| 68 | + } | |
| 69 | + } | |
| 67 | 70 | |
| 68 | - return false; | |
| 69 | - } | |
| 71 | + return false; | |
| 72 | + } | |
| 70 | 73 | |
| 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 | - } | |
| 74 | + public function is_preview_domain( $headers = null ): bool { | |
| 75 | + // @codeCoverageIgnoreStart | |
| 76 | + if ( $headers === null && function_exists( 'getallheaders' ) ) { | |
| 77 | + $headers = getallheaders(); | |
| 78 | + } | |
| 79 | + // @codeCoverageIgnoreEnd | |
| 80 | + if ( isset( $headers['X-Preview-Indicator'] ) && $headers['X-Preview-Indicator'] ) { | |
| 81 | + return true; | |
| 82 | + } | |
| 80 | 83 | |
| 81 | - return false; | |
| 82 | - } | |
| 84 | + return false; | |
| 85 | + } | |
| 83 | 86 | |
| 84 | - public static function woocommerce_onboarding_choice(): bool { | |
| 85 | - return (bool) get_option( 'hostinger_woo_onboarding_choice', false ); | |
| 86 | - } | |
| 87 | + public static function woocommerce_onboarding_choice(): bool { | |
| 88 | + return (bool) get_option( 'hostinger_woo_onboarding_choice', false ); | |
| 89 | + } | |
| 87 | 90 | |
| 88 | - public static function generate_bypass_code( $length ) { | |
| 89 | - $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
| 90 | - $code = ''; | |
| 91 | - $max_index = strlen( $characters ) - 1; | |
| 91 | + public static function generate_bypass_code( $length ) { | |
| 92 | + $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
| 93 | + $code = ''; | |
| 94 | + $max_index = strlen( $characters ) - 1; | |
| 92 | 95 | |
| 93 | - for ( $i = 0; $i < $length; $i++ ) { | |
| 94 | - $random_index = wp_rand( 0, $max_index ); | |
| 95 | - $code .= $characters[ $random_index ]; | |
| 96 | + for ( $i = 0; $i < $length; $i++ ) { | |
| 97 | + $random_index = wp_rand( 0, $max_index ); | |
| 98 | + $code .= $characters[ $random_index ]; | |
| 99 | + } | |
| 100 | + | |
| 101 | + return $code; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public function should_plugin_split_notice_shown() { | |
| 105 | + $plugin_split_notice_hidden = get_option( 'hts_plugin_split_notice_hidden', false ); | |
| 106 | + | |
| 107 | + if ( $plugin_split_notice_hidden !== false ) { | |
| 108 | + return false; | |
| 96 | 109 | } |
| 97 | 110 | |
| 98 | - return $code; | |
| 99 | - } | |
| 111 | + if ( ! version_compare( HOSTINGER_VERSION, '3.0.0', '>=' ) ) { | |
| 112 | + return false; | |
| 113 | + } | |
| 100 | 114 | |
| 115 | + if ( is_plugin_active( 'hostinger-easy-onboarding/hostinger-easy-onboarding.php' ) ) { | |
| 116 | + return false; | |
| 117 | + } | |
| 101 | 118 | |
| 119 | + return true; | |
| 120 | + } | |
| 102 | 121 | |
| 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' ); | |
| 122 | + public function get_hostinger_plugin_url() : string { | |
| 123 | + $websiteLocale = get_locale() ?? 'en_US'; | |
| 124 | + $resellerLocale = get_option( 'hostinger_reseller', '' ); | |
| 125 | + $baseDomain = $resellerLocale ? : ( self::HOSTINGER_LOCALES[$websiteLocale] ?? 'hostinger.com' ); | |
| 107 | 126 | |
| 108 | - $plugin_url = rtrim( $base_domain, '/' ) . '/'; | |
| 109 | - $plugin_url .= str_replace( ABSPATH, '', HOSTINGER_ABSPATH ); | |
| 127 | + $pluginUrl = rtrim( $baseDomain, '/' ) . '/'; | |
| 128 | + $pluginUrl .= str_replace( ABSPATH, '', HOSTINGER_ABSPATH ); | |
| 110 | 129 | |
| 111 | - return $plugin_url; | |
| 130 | + return $pluginUrl; | |
| 112 | 131 | } |
| 113 | 132 | |
| 114 | 133 | public function get_recommended_php_version(): string { |
| 115 | - $wp_version = get_bloginfo( 'version' ); | |
| 134 | + $wp_version = get_bloginfo('version'); | |
| 116 | 135 | |
| 117 | - if ( empty( $wp_version ) ) { | |
| 136 | + if (empty($wp_version)) { | |
| 118 | 137 | return '8.2'; |
| 119 | 138 | } |
| 120 | 139 | |
| 121 | - // Remove any additional version info (like -RC1, -beta1, etc.). | |
| 122 | - $wp_version = preg_replace( '/[-+].*$/', '', $wp_version ); | |
| 140 | + // Remove any additional version info (like -RC1, -beta1, etc.) | |
| 141 | + $wp_version = preg_replace('/[-+].*$/', '', $wp_version); | |
| 123 | 142 | |
| 124 | - if ( version_compare( $wp_version, '6.6', '>=' ) ) { | |
| 125 | - return '8.2'; | |
| 143 | + // Version specific recommendations | |
| 144 | + if (version_compare($wp_version, '6.6', '>=')) { | |
| 145 | + return '8.2'; // Latest recommended version for WP 6.6+ | |
| 126 | 146 | } |
| 127 | 147 | |
| 128 | - if ( version_compare( $wp_version, '6.3', '>=' ) ) { | |
| 129 | - return '8.1'; | |
| 148 | + if (version_compare($wp_version, '6.3', '>=')) { | |
| 149 | + return '8.1'; // Recommended for WP 6.3-6.5 | |
| 130 | 150 | } |
| 131 | 151 | |
| 132 | - if ( version_compare( $wp_version, '5.3', '>=' ) ) { | |
| 133 | - return '7.4'; | |
| 152 | + if (version_compare($wp_version, '5.3', '>=')) { | |
| 153 | + return '7.4'; // Recommended for WP 5.3-6.2 | |
| 134 | 154 | } |
| 135 | 155 | |
| 136 | - if ( version_compare( $wp_version, '5.0', '>=' ) ) { | |
| 137 | - return '7.3'; | |
| 156 | + if (version_compare($wp_version, '5.0', '>=')) { | |
| 157 | + return '7.3'; // Recommended for WP 5.0-5.2 | |
| 138 | 158 | } |
| 139 | 159 | |
| 140 | - if ( version_compare( $wp_version, '4.9', '=' ) ) { | |
| 141 | - return '7.2'; | |
| 160 | + if (version_compare($wp_version, '4.9', '=')) { | |
| 161 | + return '7.2'; // Recommended for WP 4.9 | |
| 142 | 162 | } |
| 143 | 163 | |
| 144 | - if ( version_compare( $wp_version, '4.7', '>=' ) ) { | |
| 145 | - return '7.1'; | |
| 164 | + if (version_compare($wp_version, '4.7', '>=')) { | |
| 165 | + return '7.1'; // Recommended for WP 4.7-4.8 | |
| 146 | 166 | } |
| 147 | 167 | |
| 148 | - if ( version_compare( $wp_version, '4.4', '>=' ) ) { | |
| 149 | - return '7.0'; | |
| 168 | + if (version_compare($wp_version, '4.4', '>=')) { | |
| 169 | + return '7.0'; // Recommended for WP 4.4-4.6 | |
| 150 | 170 | } |
| 151 | 171 | |
| 172 | + // For versions below 4.9 | |
| 152 | 173 | return '5.6'; |
| 153 | 174 | } |
| 154 | 175 | |
| 155 | 176 | public function get_edit_site_url(): string { |
| 156 | 177 | if ( wp_is_block_theme() ) { |
| 157 | - return add_query_arg( | |
| 158 | - array( | |
| 159 | - 'canvas' => 'edit', | |
| 160 | - ), | |
| 161 | - admin_url( 'site-editor.php' ) | |
| 162 | - ); | |
| 178 | + return add_query_arg( [ | |
| 179 | + 'canvas' => 'edit', | |
| 180 | + ], admin_url( 'site-editor.php' ) ); | |
| 163 | 181 | } |
| 164 | 182 | |
| 165 | 183 | $show_on_front = get_option( 'show_on_front' ); |
| 166 | 184 | $front_page_id = get_option( 'page_on_front' ); |
| @@ -165,16 +183,14 @@ | ||
| 165 | 183 | $show_on_front = get_option( 'show_on_front' ); |
| 166 | 184 | $front_page_id = get_option( 'page_on_front' ); |
| 167 | 185 | |
| 168 | 186 | 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 | - ); | |
| 187 | + return add_query_arg( [ | |
| 188 | + 'post' => $front_page_id, | |
| 189 | + 'action' => 'edit', | |
| 190 | + ], admin_url( 'post.php' ) ); | |
| 176 | 191 | } |
| 177 | 192 | |
| 178 | 193 | return ''; |
| 179 | 194 | } |
| 195 | + | |
| 180 | 196 | } |