s', 'rocket' ), $this->plugin_last_version )
. '
';
echo '' . wp_kses_post( $message ) . '
';
}
/**
* Do the rollback
*
* @since 3.0
* @author Remy Perona
*/
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://api.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';
// translators: %s is the plugin name.
$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(
'',
// translators: %s is the plugin name.
sprintf( esc_html__( '%s Update Rollback', 'rocket' ), esc_html( $this->plugin_name ) ),
[
'response' => 200,
]
);
}
/**
* Filters the User Agent when doing a request to WP Rocket server
*
* @since 3.0
* @author Remy Perona
*
* @param array $request Array of arguments associated with the request.
* @param string $url URL requested.
*/
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;
}
}