PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.3.1
Defender Security – Malware Scanner, Login Security & Firewall v5.3.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / security-tweaks / class-php-version.php

class-php-version.php in Defender Security – Malware Scanner, Login Security & Firewall 5.3.1, at src/component/security-tweaks/class-php-version.php

172 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles checks and operations related to the PHP version used by the server.
4 *
5 * @package WP_Defender\Component\Security_Tweaks
6 */
7
8 namespace WP_Defender\Component\Security_Tweaks;
9
10 /**
11 * Handles checks and operations related to the PHP version used by the server.
12 */
13 class PHP_Version extends Abstract_Security_Tweaks {
14
15 /**
16 * Identifier slug for the component.
17 *
18 * @var string
19 */
20 public string $slug = 'php-version';
21 /**
22 * Minimum PHP version required.
23 *
24 * @var string|null
25 */
26 public $min_php = null;
27 /**
28 * Recommended stable PHP version.
29 *
30 * @var string|null
31 */
32 public $stable_php = null;
33
34 /**
35 * Current PHP version of the server.
36 *
37 * @var string
38 */
39 public $current_php = PHP_VERSION;
40
41 /**
42 * Check whether the issue has been resolved or not.
43 *
44 * @return bool
45 */
46 public function check() {
47 return $this->is_resolved();
48 }
49
50 /**
51 * Here is the code for processing.
52 *
53 * @return bool
54 */
55 public function process(): bool {
56 return true;
57 }
58
59 /**
60 * This is for un-do stuff that has to be done in @process.
61 *
62 * @return bool
63 */
64 public function revert(): bool {
65 return true;
66 }
67
68 /**
69 * Shield up.
70 *
71 * @return bool
72 */
73 public function shield_up(): bool {
74 return true;
75 }
76
77 /**
78 * Check wheter the issue is resolved or not.
79 *
80 * @return bool
81 */
82 private function is_resolved() {
83 $this->set_php_versions();
84
85 return version_compare( $this->current_php, $this->min_php, '>' );
86 }
87
88 /**
89 * Setup PHP versions.
90 *
91 * @return void
92 */
93 private function set_php_versions() {
94 if ( ! function_exists( 'wp_check_php_version' ) ) {
95 require_once ABSPATH . 'wp-admin/includes/misc.php';
96 }
97 $info = wp_check_php_version();
98
99 if ( ! $info ) {
100 $this->min_php = 'n/a';
101 $this->stable_php = 'n/a';
102
103 return;
104 }
105
106 $supported_php = apply_filters(
107 "defender_{$this->slug}_supported_php",
108 array(
109 '7.4',
110 '8.0',
111 '8.1',
112 '8.2',
113 )
114 );
115 $this->stable_php = $info['recommended_version'];
116 $position = array_search( $this->stable_php, $supported_php, true );
117
118 if ( false !== $position && ! empty( $supported_php[ $position ] ) ) {
119 $this->min_php = $supported_php[ $position ];
120 }
121 }
122
123 /**
124 * Retrieve the tweak's label.
125 *
126 * @return string
127 */
128 public function get_label(): string {
129 return esc_html__( 'Update PHP to latest version', 'defender-security' );
130 }
131
132 /**
133 * Get the error reason.
134 *
135 * @return string
136 */
137 public function get_error_reason(): string {
138 $this->set_php_versions();
139
140 return sprintf(
141 /* translators: %s: Min PHP version. %s: Min PHP version. */
142 esc_html__(
143 '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.',
144 'defender-security'
145 ),
146 $this->min_php,
147 $this->min_php
148 );
149 }
150
151 /**
152 * Return a summary data of this tweak.
153 *
154 * @return array
155 */
156 public function to_array(): array {
157 $this->set_php_versions();
158
159 return array(
160 'slug' => $this->slug,
161 'title' => $this->get_label(),
162 'errorReason' => $this->get_error_reason(),
163 'successReason' => esc_html__( 'You have the latest version of PHP installed, good stuff!', 'defender-security' ),
164 'misc' => array(
165 'php_version' => $this->current_php,
166 'min_php_version' => $this->min_php,
167 'stable_php_version' => $this->stable_php,
168 ),
169 );
170 }
171 }
172