← All changes
|
includes/class-wp-optimize-http-error-codes-trait.php
+14
-7
3.7.1
→
4.7.0
View file →
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -if (!defined('WPO_VERSION')) die('No direct access allowed'); | |
| 2 | +if (!defined('ABSPATH')) die('No direct access allowed'); | |
| 3 | 3 | |
| 4 | 4 | if (!trait_exists('WP_Optimize_HTTP_Error_Codes_Trait')) : |
| 5 | 5 | trait WP_Optimize_HTTP_Error_Codes_Trait { |
| 6 | 6 | |
| @@ -140,23 +140,28 @@ | ||
| 140 | 140 | |
| 141 | 141 | if (is_wp_error($response)) return $response; |
| 142 | 142 | |
| 143 | 143 | $response_code = wp_remote_retrieve_response_code($response); |
| 144 | - if (200 != $response_code) { | |
| 144 | + if (200 !== $response_code) { | |
| 145 | 145 | $link = sprintf('<a href="%s" target="_blank">%s</a>', $style, $style); |
| 146 | 146 | |
| 147 | - if (401 == $response_code) { | |
| 147 | + if (401 === $response_code) { | |
| 148 | 148 | $error = '<b>' . esc_html__('401 Unauthorized', 'wp-optimize') . '</b>'; |
| 149 | + // translators: %s is a `401 Unauthorized` error message | |
| 149 | 150 | $error_string = sprintf(esc_html__('The server responded with a %s error.', 'wp-optimize'), $error) . ' ' |
| 150 | 151 | . esc_html__('This usually happens when the site requires authentication to access it.', 'wp-optimize') . ' ' |
| 152 | + // translators: %s is a link to the style.css file | |
| 151 | 153 | . sprintf(esc_html__('Please temporarily disable authentication for the following URL: %s and retry.', 'wp-optimize'), $link); |
| 152 | - } elseif (404 == $response_code) { | |
| 153 | - $error = '<b>' . esc_html__('404 File Not Found', 'wp-optmize') . '</b>'; | |
| 154 | + } elseif (404 === $response_code) { | |
| 155 | + $error = '<b>' . esc_html__('404 File Not Found', 'wp-optimize') . '</b>'; | |
| 156 | + // translators: %s is a `404 File Not Found` error message | |
| 154 | 157 | $error_string = sprintf(esc_html__('The server responded with a %s error', 'wp-optimize'), $error) . ' ' |
| 158 | + // translators: %s is a link to the style.css file | |
| 155 | 159 | . sprintf(esc_html__('Please temporarily restore the file under URL: %s, or just create an empty file and try again.', 'wp-optimize'), $link); |
| 156 | 160 | } else { |
| 157 | 161 | $error = '<b>' . $response_code . ' ' . $this->get_http_code_label($response_code) . '</b>'; |
| 158 | - $error_string = sprintf(esc_html__('The server responded with a %s error whilst trying to open the URL: %s.', 'wp-optimize'), $error, $link) . ' ' | |
| 162 | + // translators: %1$s is an HTTP error response code, %2$s is a link to the style.css file | |
| 163 | + $error_string = sprintf(esc_html__('The server responded with a %1$s error whilst trying to open the URL: %2$s.', 'wp-optimize'), $error, $link) . ' ' | |
| 159 | 164 | . esc_html__('Please contact your website administrator to resolve this.', 'wp-optimize') . ' ' . esc_html__('Once the issue is addressed, try again.', 'wp-optimize'); |
| 160 | 165 | } |
| 161 | 166 | |
| 162 | 167 | return new WP_Error('unauthorized', $error_string); |
| @@ -181,8 +186,10 @@ | ||
| 181 | 186 | if (!isset($this->http_codes)) { |
| 182 | 187 | $this->set_codes(); |
| 183 | 188 | } |
| 184 | 189 | |
| 185 | - return $code . " " . !empty($this->http_codes[$code]) ? $this->http_codes[$code] : esc_html__("HTTP Code", "wp-optimize"); | |
| 190 | + $message = $this->http_codes[$code] ?? esc_html__("HTTP Code", "wp-optimize"); | |
| 191 | + | |
| 192 | + return $code . " " . $message; | |
| 186 | 193 | } |
| 187 | 194 | } |
| 188 | 195 | endif; |