PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
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-wp-version.php

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

145 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles
4 *
5 * @package WP_Defender\Component\Security_Tweaks
6 */
7
8 namespace WP_Defender\Component\Security_Tweaks;
9
10 /**
11 * Class WP_Version
12 */
13 class WP_Version extends Abstract_Security_Tweaks {
14
15 /**
16 * Component slug name.
17 *
18 * @var string
19 */
20 public string $slug = 'wp-version';
21
22 /**
23 * Check whether the issue has been resolved or not.
24 *
25 * @return bool
26 */
27 public function check() {
28 return $this->is_resolved();
29 }
30
31 /**
32 * Here is the code for processing.
33 *
34 * @return bool
35 */
36 public function process() {
37 return true;
38 }
39
40 /**
41 * This is for un-do stuff that has be done in @process.
42 *
43 * @return bool
44 */
45 public function revert() {
46 return true;
47 }
48
49 /**
50 * Shield up.
51 *
52 * @return bool
53 */
54 public function shield_up() {
55 return true;
56 }
57
58 /**
59 * Check whether the issue is resolved or not.
60 *
61 * @return bool
62 */
63 private function is_resolved() {
64 global $wp_version;
65
66 return version_compare( $wp_version, $this->get_latest_version(), '=' );
67 }
68
69 /**
70 * Get the latest WordPress version.
71 *
72 * @return string|false on failure
73 */
74 public function get_latest_version() {
75 if ( ! function_exists( 'get_core_updates' ) ) {
76 include_once ABSPATH . 'wp-admin/includes/update.php';
77 }
78
79 $data = get_core_updates();
80
81 if ( ! is_array( $data ) || array() === $data ) {
82 wp_version_check( array(), true );
83 $data = get_core_updates( array( 'dismissed' => true ) );
84 }
85
86 // For bool value and empty array.
87 if ( ! is_array( $data ) || array() === $data ) {
88 return false;
89 }
90
91 return reset( $data )->version;
92 }
93
94 /**
95 * Retrieve the tweak's label.
96 *
97 * @return string
98 */
99 public function get_label(): string {
100 return wp_strip_all_tags( 'Update WordPress', 'wpdef' );
101 }
102
103 /**
104 * Get the error reason.
105 *
106 * @return string
107 */
108 public function get_error_reason(): string {
109 return sprintf(
110 /* translators: 1. Open tag. 2. Close tag. */
111 esc_html__(
112 '%1$sWordPress is out of date%2$s and may expose details hackers can use.',
113 'defender-security'
114 ),
115 '<strong>',
116 '</strong>',
117 );
118 }
119
120 /**
121 * Return a summary data of this tweak.
122 *
123 * @return array
124 */
125 public function to_array(): array {
126 return array(
127 'slug' => $this->slug,
128 'title' => $this->get_label(),
129 'errorReason' => $this->get_error_reason(),
130 'successReason' => wp_strip_all_tags( 'WordPress is up to date.', 'wpdef' ),
131 'misc' => array(
132 'latest_wp' => $this->get_latest_version(),
133 'core_update_url' => network_admin_url( 'update-core.php' ),
134 'show_revert_button' => false,
135 'show_action_button' => false,
136 ),
137 'bulk_description' => wp_strip_all_tags(
138 'Outdated WordPress installs can leave your site vulnerable. Update WordPress to the latest version to help protect your site and keep security up to date.',
139 'wpdef'
140 ),
141 'bulk_title' => $this->get_label(),
142 );
143 }
144 }
145