PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.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 / php-version.php

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

113 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_Defender\Component\Security_Tweaks;
4
5 use Calotes\Base\Component;
6
7 /**
8 * Class PHP_Version
9 * @package WP_Defender\Component\Security_Tweaks
10 */
11 class PHP_Version extends Component {
12 public $slug = 'php-version';
13 public $min_php = null;
14 public $stable_php = null;
15 public $current_php = PHP_VERSION;
16
17 /**
18 * Check whether the issue has been resolved or not.
19 *
20 * @return bool
21 */
22 public function check() {
23 return $this->is_resolved();
24 }
25
26 /**
27 * Here is the code for processing, if the return is true, we add it to resolve list, WP_Error if any error.
28 *
29 * @return bool
30 */
31 public function process() {
32 return true;
33 }
34
35 /**
36 * This is for un-do stuff that has be done in @process.
37 *
38 * @return bool
39 */
40 public function revert() {
41 return true;
42 }
43
44 /**
45 * Shield up.
46 *
47 * @return bool
48 */
49 public function shield_up() {
50 return true;
51 }
52
53 /**
54 * Check wheter the issue is resolved or not.
55 *
56 * @return bool
57 */
58 private function is_resolved() {
59 $this->set_php_versions();
60
61 return version_compare( $this->current_php, $this->min_php, '>' );
62 }
63
64 /**
65 * Setup PHP versions.
66 *
67 * @return void
68 */
69 private function set_php_versions() {
70 if ( ! function_exists( 'wp_check_php_version' ) ) {
71 $info = defender_wp_check_php_version();
72 } else {
73 $info = wp_check_php_version();
74 }
75
76 if ( ! $info ) {
77 $this->min_php = 'n/a';
78 $this->stable_php = 'n/a';
79
80 return;
81 }
82
83 $supported_php = apply_filters( "defender_{$this->slug}_supported_php", [ '7.2', '7.3', '7.4', '8.0', '8.1' ] );
84 $this->stable_php = $info['recommended_version'];
85 $position = array_search( $this->stable_php, $supported_php, true );
86
87 if ( false !== $position && ! empty( $supported_php[ $position ] ) ) {
88 $this->min_php = $supported_php[ $position ];
89 }
90 }
91
92 /**
93 * Return a summary data of this tweak.
94 *
95 * @return array
96 */
97 public function to_array() {
98 $this->set_php_versions();
99
100 return [
101 'slug' => $this->slug,
102 'title' => __( 'Update PHP to latest version', 'wpdef' ),
103 'errorReason' => sprintf( __( "PHP versions older than %s are no longer supported. For security and stability we strongly recommend you upgrade your PHP version to version %s or newer as soon as possible.", 'wpdef' ), $this->min_php, $this->min_php ),
104 'successReason' => __( 'You have the latest version of PHP installed, good stuff!', 'wpdef' ),
105 'misc' => [
106 'php_version' => $this->current_php,
107 'min_php_version' => $this->min_php,
108 'stable_php_version' => $this->stable_php,
109 ],
110 ];
111 }
112 }
113