← All changes
|
src/component/security-tweaks/class-php-version.php
+32
-11
5.4.1
→
6.3.0
View file →
| @@ -105,20 +105,36 @@ | ||
| 105 | 105 | // Ref: https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/. |
| 106 | 106 | $supported_php = apply_filters( |
| 107 | 107 | "defender_{$this->slug}_supported_php", |
| 108 | 108 | array( |
| 109 | - '7.4', | |
| 110 | 109 | '8.0', |
| 111 | 110 | '8.1', |
| 112 | 111 | '8.2', |
| 113 | 112 | '8.3', |
| 113 | + '8.4', | |
| 114 | 114 | ) |
| 115 | 115 | ); |
| 116 | 116 | $this->stable_php = $info['recommended_version']; |
| 117 | - $position = array_search( $this->stable_php, $supported_php, true ); | |
| 118 | 117 | |
| 119 | - if ( false !== $position && ! empty( $supported_php[ $position ] ) ) { | |
| 118 | + // If the recommended version is lower than plugin's minimum requirement. | |
| 119 | + if ( version_compare( $this->stable_php, WP_DEFENDER_MIN_PHP_VERSION, '<' ) ) { | |
| 120 | + // WordPress may recommend a PHP version older than what plugin requires. | |
| 121 | + // In that case, use plugin's minimum requirement instead. | |
| 122 | + $this->stable_php = WP_DEFENDER_MIN_PHP_VERSION; | |
| 123 | + } | |
| 124 | + | |
| 125 | + $position = array_search( $this->stable_php, $supported_php, true ); | |
| 126 | + | |
| 127 | + if ( | |
| 128 | + false !== $position | |
| 129 | + && isset( $supported_php[ $position ] ) | |
| 130 | + && is_string( $supported_php[ $position ] ) | |
| 131 | + && '' !== $supported_php[ $position ] | |
| 132 | + ) { | |
| 120 | 133 | $this->min_php = $supported_php[ $position ]; |
| 134 | + } else { | |
| 135 | + // Fallback to first supported version if search fails. | |
| 136 | + $this->min_php = reset( $supported_php ); | |
| 121 | 137 | } |
| 122 | 138 | } |
| 123 | 139 | |
| 124 | 140 | /** |
| @@ -126,9 +142,9 @@ | ||
| 126 | 142 | * |
| 127 | 143 | * @return string |
| 128 | 144 | */ |
| 129 | 145 | public function get_label(): string { |
| 130 | - return esc_html__( 'Update PHP to latest version', 'defender-security' ); | |
| 146 | + return esc_html__( 'Update PHP', 'defender-security' ); | |
| 131 | 147 | } |
| 132 | 148 | |
| 133 | 149 | /** |
| 134 | 150 | * Get the error reason. |
| @@ -139,11 +155,11 @@ | ||
| 139 | 155 | $this->set_php_versions(); |
| 140 | 156 | |
| 141 | 157 | return sprintf( |
| 142 | 158 | /* translators: %s: Min PHP version. %s: Min PHP version. */ |
| 143 | - esc_html__( | |
| 159 | + wp_strip_all_tags( | |
| 144 | 160 | 'PHP versions older than %1$s are no longer supported. For security and stability we strongly recommend you upgrade your PHP version to version %2$s or newer as soon as possible.', |
| 145 | - 'defender-security' | |
| 161 | + 'wpdef' | |
| 146 | 162 | ), |
| 147 | 163 | $this->min_php, |
| 148 | 164 | $this->min_php |
| 149 | 165 | ); |
| @@ -157,16 +173,21 @@ | ||
| 157 | 173 | public function to_array(): array { |
| 158 | 174 | $this->set_php_versions(); |
| 159 | 175 | |
| 160 | 176 | return array( |
| 161 | - 'slug' => $this->slug, | |
| 162 | - 'title' => $this->get_label(), | |
| 163 | - 'errorReason' => $this->get_error_reason(), | |
| 164 | - 'successReason' => esc_html__( 'You have the latest version of PHP installed, good stuff!', 'defender-security' ), | |
| 165 | - 'misc' => array( | |
| 177 | + 'slug' => $this->slug, | |
| 178 | + 'title' => $this->get_label(), | |
| 179 | + 'errorReason' => $this->get_error_reason(), | |
| 180 | + 'successReason' => wp_strip_all_tags( __( 'You have the latest version of PHP installed, good stuff!', 'defender-security' ) ), | |
| 181 | + 'misc' => array( | |
| 166 | 182 | 'php_version' => $this->current_php, |
| 167 | 183 | 'min_php_version' => $this->min_php, |
| 168 | 184 | 'stable_php_version' => $this->stable_php, |
| 185 | + 'show_revert_button' => false, | |
| 186 | + 'show_action_button' => false, | |
| 187 | + ), | |
| 188 | + 'bulk_description' => array( | |
| 189 | + wp_strip_all_tags( __( 'PHP powers WordPress by processing code and generating your site’s pages. Update PHP to keep your site fast, reliable, secure, and compatible with supported versions.', 'defender-security' ) ), | |
| 169 | 190 | ), |
| 170 | 191 | ); |
| 171 | 192 | } |
| 172 | 193 | } |