File "class-wp-rocket-requirements-check.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/wp-rocket/inc/classes/class-wp-rocket-requirements-check.php
File
size: 5.03 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
defined('ABSPATH') || exit;
class WP_Rocket_Requirements_Check
{
private $plugin_name;
private $plugin_file;
private $plugin_version;
private $plugin_last_version;
private $wp_version;
private $php_version;
private $options;
public function __construct($args)
{
foreach (['plugin_name', 'plugin_file', 'plugin_version', 'plugin_last_version', 'wp_version', 'php_version'] as $setting) {
if (isset($args[$setting])) {
$this->{$setting} = $args[$setting];
}
}
$this->plugin_last_version = version_compare(PHP_VERSION, '5.3') >= 0 ? $this->plugin_last_version : '2.10.12';
$this->options = get_option('wp_rocket_settings');
}
public function check()
{
if (!$this->php_passes() || !$this->wp_passes()) {
add_action('admin_notices', [$this, 'notice']);
add_action('admin_post_rocket_rollback', [$this, 'rollback']);
add_filter('http_request_args', [$this, 'add_own_ua'], 10, 2);
return false;
}
return true;
}
private function php_passes()
{
return version_compare(PHP_VERSION, $this->php_version) >= 0;
}
private function wp_passes()
{
global $wp_version;
return version_compare($wp_version, $this->wp_version) >= 0;
}
public function notice()
{
if (!current_user_can('manage_options')) {
return;
}
$message = '<p>' . sprintf(__('To function properly, %1$s %2$s requires at least:', 'rocket'), $this->plugin_name, $this->plugin_version) . '</p><ul>';
if (!$this->php_passes()) {
$message .= '<li>' . sprintf(__('PHP %1$s. To use this WP Rocket version, please ask your web host how to upgrade your server to PHP %1$s or higher.', 'rocket'), $this->php_version) . '</li>';
}
if (!$this->wp_passes()) {
$message .= '<li>' . sprintf(__('WordPress %1$s. To use this WP Rocket version, please upgrade WordPress to version %1$s or higher.', 'rocket'), $this->wp_version) . '</li>';
}
$message .= '</ul><p>' . __('If you are not able to upgrade, you can rollback to the previous version by using the button below.', 'rocket') . '</p><p><a href="' . wp_nonce_url(admin_url('admin-post.php?action=rocket_rollback'), 'rocket_rollback') . '" class="button">' . sprintf(__('Re-install version %s', 'rocket'), $this->plugin_last_version) . '</a></p>';
echo '<div class="notice notice-error">' . wp_kses_post($message) . '</div>';
}
public function rollback()
{
check_ajax_referer('rocket_rollback');
if (!current_user_can('manage_options')) {
wp_die();
}
$consumer_key = isset($this->options['consumer_key']) ? $this->options['consumer_key'] : false;
if (!$consumer_key && defined('WP_ROCKET_KEY')) {
$consumer_key = WP_ROCKET_KEY;
}
$plugin_transient = get_site_transient('update_plugins');
$plugin_folder = plugin_basename(dirname($this->plugin_file));
$plugin_file = basename($this->plugin_file);
$url = sprintf('https://wp-rocket.me/%s/wp-rocket_%s.zip', $consumer_key, $this->plugin_last_version);
$temp_array = ['slug' => $plugin_folder, 'new_version' => $this->plugin_last_version, 'url' => 'https://wp-rocket.me', 'package' => $url];
$temp_object = (object) $temp_array;
$plugin_transient->response[$plugin_folder . '/' . $plugin_file] = $temp_object;
set_site_transient('update_plugins', $plugin_transient);
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$title = sprintf(__('%s Update Rollback', 'rocket'), $this->plugin_name);
$plugin = 'wp-rocket/wp-rocket.php';
$nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . rawurlencode($plugin);
$upgrader_skin = new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin'));
$upgrader = new Plugin_Upgrader($upgrader_skin);
remove_filter('site_transient_update_plugins', 'rocket_check_update', 1);
$upgrader->upgrade($plugin);
wp_die('', sprintf(esc_html__('%s Update Rollback', 'rocket'), esc_html($this->plugin_name)), ['response' => 200]);
}
public function add_own_ua($request, $url)
{
if (strpos($url, 'wp-rocket.me') === false) {
return $request;
}
$consumer_key = isset($this->options['consumer_key']) ? $this->options['consumer_key'] : false;
if (!$consumer_key && defined('WP_ROCKET_KEY')) {
$consumer_key = WP_ROCKET_KEY;
}
$consumer_email = isset($this->options['consumer_email']) ? $this->options['consumer_email'] : false;
if (!$consumer_email && defined('WP_ROCKET_EMAIL')) {
$consumer_email = WP_ROCKET_EMAIL;
}
$request['user-agent'] = sprintf('%s;WP-Rocket|%s%s|%s|%s|%s|;', $request['user-agent'], $this->plugin_version, '', $consumer_key, $consumer_email, esc_url(home_url()));
return $request;
}
}