| @@ -43,9 +43,8 @@ | ||
| 43 | 43 | |
| 44 | 44 | if ( file_exists( $token_file ) && ! empty( file_get_contents( $token_file ) ) ) { |
| 45 | 45 | $api_token = file_get_contents( $token_file ); |
| 46 | 46 | } |
| 47 | - | |
| 48 | 47 | return $api_token; |
| 49 | 48 | } |
| 50 | 49 | |
| 51 | 50 | /** |
| @@ -54,11 +53,10 @@ | ||
| 54 | 53 | * |
| 55 | 54 | * @since 1.7.0 |
| 56 | 55 | * @access public |
| 57 | 56 | */ |
| 58 | - | |
| 59 | 57 | public function get_host_info(): string { |
| 60 | - $host = $_SERVER['HTTP_HOST'] ?? ''; | |
| 58 | + $host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( $_SERVER['HTTP_HOST'] ) : ''; | |
| 61 | 59 | $site_url = get_site_url(); |
| 62 | 60 | $site_url = preg_replace( '#^https?://#', '', $site_url ); |
| 63 | 61 | |
| 64 | 62 | if ( ! empty( $site_url ) && ! empty( $host ) && strpos( $site_url, $host ) === 0 ) { |
| @@ -176,8 +174,28 @@ | ||
| 176 | 174 | return $domain_url; |
| 177 | 175 | } |
| 178 | 176 | |
| 179 | 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 | + | |
| 193 | + } catch ( Exception $exception ) { | |
| 194 | + // If there's an exception, log the error and return false | |
| 195 | + $this->helper->error_log( 'Error checking eligibility: ' . $exception->getMessage() ); | |
| 196 | + return false; | |
| 197 | + } | |
| 180 | 198 | } |
| 181 | 199 | } |
| 182 | 200 | |
| 183 | 201 | $hostinger_helper = new Hostinger_Helper(); |