| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class file contains class WP_Version. |
| 4 |
* |
| 5 |
* @package WP_Defender\Component\Security_Tweaks |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Component\Security_Tweaks; |
| 9 |
|
| 10 |
use Calotes\Base\Component; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class WP_Version |
| 14 |
* |
| 15 |
* @package WP_Defender\Component\Security_Tweaks |
| 16 |
*/ |
| 17 |
class WP_Version extends Component { |
| 18 |
/** |
| 19 |
* Component slug name. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
public $slug = 'wp-version'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Check whether the issue has been resolved or not. |
| 27 |
* |
| 28 |
* @return bool |
| 29 |
*/ |
| 30 |
public function check() { |
| 31 |
return $this->is_resolved(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Here is the code for processing, if the return is true, we add it to resolve list, WP_Error if any error. |
| 36 |
* |
| 37 |
* @return bool |
| 38 |
*/ |
| 39 |
public function process() { |
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* This is for un-do stuff that has be done in @process. |
| 45 |
* |
| 46 |
* @return bool |
| 47 |
*/ |
| 48 |
public function revert() { |
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Shield up. |
| 54 |
* |
| 55 |
* @return bool |
| 56 |
*/ |
| 57 |
public function shield_up() { |
| 58 |
return true; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Check whether the issue is resolved or not. |
| 63 |
* |
| 64 |
* @return bool |
| 65 |
*/ |
| 66 |
private function is_resolved() { |
| 67 |
global $wp_version; |
| 68 |
|
| 69 |
return version_compare( $wp_version, $this->get_latest_version(), '=' ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Get the latest WordPress version. |
| 74 |
* |
| 75 |
* @return string|false on failure |
| 76 |
*/ |
| 77 |
private function get_latest_version() { |
| 78 |
if ( ! function_exists( 'get_core_updates' ) ) { |
| 79 |
include_once ABSPATH . 'wp-admin/includes/update.php'; |
| 80 |
} |
| 81 |
|
| 82 |
$data = get_core_updates(); |
| 83 |
|
| 84 |
if ( empty( $data ) ) { |
| 85 |
wp_version_check( array(), true ); |
| 86 |
$data = get_core_updates( array( 'dismissed' => true ) ); |
| 87 |
} |
| 88 |
|
| 89 |
// For bool value and empty array. |
| 90 |
if ( empty( $data ) ) { |
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
return reset( $data )->version; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Return a summary data of this tweak. |
| 99 |
* |
| 100 |
* @return array |
| 101 |
*/ |
| 102 |
public function to_array() { |
| 103 |
return array( |
| 104 |
'slug' => $this->slug, |
| 105 |
'title' => __( 'Update WordPress to latest version', 'wpdef' ), |
| 106 |
/* translators: %s: WP Version */ |
| 107 |
'errorReason' => sprintf( __( 'Your current WordPress version is out of date, which means you could be missing out on the latest security patches in v%s', 'wpdef' ), $this->get_latest_version() ), |
| 108 |
'successReason' => __( 'You are using the latest version of WordPress, great job!', 'wpdef' ), |
| 109 |
'misc' => array( |
| 110 |
'latest_wp' => $this->get_latest_version(), |
| 111 |
'core_update_url' => network_admin_url( 'update-core.php' ), |
| 112 |
), |
| 113 |
'bulk_description' => __( 'Your current WordPress version is out of date, which means you could be missing out on the latest update. We will upgrade WordPress version to the latest.', 'wpdef' ), |
| 114 |
'bulk_title' => __( 'WordPress Version', 'wpdef' ), |
| 115 |
); |
| 116 |
} |
| 117 |
} |
| 118 |
|