er.
* @param object $item The update offer.
* @return bool|null
*/
public function disable_auto_updates( $update, $item ) {
if ( isset( $item->plugin ) && ( 'clsop/clsop.php' === $item->plugin ) ) {
return false;
}
return $update;
}
/**
* Get the latest WPR update data from our server.
*
* @note CL
* @return \stdClass|\WP_Error {
* A \WP_Error object on failure. An object on success:
*
* @type string $slug The plugin slug.
* @type string $plugin The plugin base name.
* @type string $new_version The plugin new version.
* @type string $url URL to the plugin provider.
* @type string $package URL to the zip file of the new version.
* @type array $icons {
* A list of plugin’s icon URLs.
*
* @type string $2x URL to the High-DPI size (png or jpg). Optional.
* @type string $1x URL to the normal icon size (png or jpg). Mandatory.
* @type string $svg URL to the svg version of the icon. Optional.
* }
* }
*/
public function get_latest_version_data() {
$package = WP_ROCKET_PLUGIN_NAME;
$config_file = $this->local_path . DIRECTORY_SEPARATOR . 'clsop.ini';
if ( @is_readable( $config_file ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$plugin_data = parse_ini_file( $config_file, true );
$package = $this->local_path . DIRECTORY_SEPARATOR . 'clsop.zip';
} else {
// open_basedir restriction in effect.
do_action( 'accelerate_wp_set_error_handler' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$response = $this->api_socket->plugin_data();
$response = json_decode( $response, true );
if (
is_array( $response )
&&
isset( $response['data']['clsop_info'] )
) {
$plugin_data = $response['data'];
}
do_action( 'accelerate_wp_restore_error_handler' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
}
if ( ! isset( $plugin_data ) ) {
return $this->get_request_error(
[
'error_code' => 500,
'response' => 'Cannot parse ini-file',
]
);
}
// CL.
$obj = new \stdClass();
$obj->slug = $this->get_plugin_slug( $this->plugin_file );
$obj->plugin = plugin_basename( $this->plugin_file );
$obj->new_version = $plugin_data['clsop_info']['version'];
$obj->url = $this->vendor_url;
$obj->package = $package;
$obj->requires = $plugin_data['clsop_info']['wp_version'];
$obj->requires_php = $plugin_data['clsop_info']['php_version'];
$obj->stable_version = $plugin_data['clsop_info']['version'];
/**
* Filters the WP tested version value
*
* @since 3.10.7
*
* @param string $wp_tested_version WP tested version value.
*/
$obj->tested = apply_filters( 'rocket_wp_tested_version', $plugin_data['clsop_info']['wp_version_tested'] );
if ( $this->icons && ! empty( $this->icons['1x'] ) ) {
$obj->icons = $this->icons;
}
return $obj;
}
/**
* Prepare package link for installation process.
*
* @param bool $reply Reply.
* @param string $package Package link.
*
* @note CL.
* @return string|bool
*/
public function get_download_link( $reply, $package ) {
if ( false !== strpos( $package, WP_ROCKET_PLUGIN_NAME ) ) {
do_action( 'accelerate_wp_set_error_handler' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$response = $this->api_socket->get_plugin();
$response = json_decode( $response, true );
if (
is_array( $response )
&&
isset( $response['package'] )
) {
$link = $response['package'];
return str_replace( '|' . WP_ROCKET_PLUGIN_NAME, '', $link );
}
do_action( 'accelerate_wp_restore_error_handler' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
}
return false;
}
/**
* Get the cached version of the latest WPR update data.
*
* @return \stdClass|\WP_Error {
* A \WP_Error object on failure. An object on success:
*
* @type string $slug The plugin slug.
* @type string $plugin The plugin base name.
* @type string $new_version The plugin new version.
* @type string $url URL to the plugin provider.
* @type string $package URL to the zip file of the new version.
* @type array $icons {
* A list of plugin’s icon URLs.
*
* @type string $2x URL to the High-DPI size (png or jpg). Optional.
* @type string $1x URL to the normal icon size (png or jpg). Mandatory.
* @type string $svg URL to the svg version of the icon. Optional.
* }
* }
*/
public function get_cached_latest_version_data() {
static $response;
if ( isset( $response ) ) {
// "force update" won’t bypass the static cache: only one http request by page load.
return $response;
}
$force_update = is_string( filter_input( INPUT_GET, 'rocket_force_update' ) );
if ( ! $force_update ) {
// No "force update": try to get the result from a transient.
$response = get_site_transient( $this->cache_transient_name );
if ( $response && is_object( $response ) ) {
// Got something in cache.
return $response;
}
}
// Get fresh data.
$response = $this->get_latest_version_data();
$cache_duration = 12 * HOUR_IN_SECONDS;
if ( is_wp_error( $response ) ) {
$error_data = $response->get_error_data();
if ( ! empty( $error_data['error_code'] ) ) {
// `wp_remote_get()` returned an internal error ('error_code' contains a WP_Error code ).
$cache_duration = HOUR_IN_SECONDS;
} elseif ( ! empty( $error_data['http_code'] ) && $error_data['http_code'] >= 400 ) {
// We got a 4xx or 5xx HTTP error.
$cache_duration = 2 * HOUR_IN_SECONDS;
}
}
set_site_transient( $this->cache_transient_name, $response, $cache_duration );
return $response;
}
/**
* Delete WP Rocket update data cache.
*/
public function delete_rocket_update_data_cache() {
delete_site_transient( $this->cache_transient_name );
}
/**
* Do the rollback
*
* @since 2.4
*/
public function rollback() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rocket_rollback' ) ) {
wp_nonce_ays( '' );
}
if ( ! current_user_can( 'rocket_manage_options' ) ) {
wp_nonce_ays( '' );
}
/**
* Fires before doing the rollback
*/
do_action( 'rocket_before_rollback' );
$plugin_transient = get_site_transient( 'update_plugins' );
$plugin_folder = plugin_basename( dirname( WP_ROCKET_FILE ) );
$plugin = $plugin_folder . '/' . basename( WP_ROCKET_FILE );
$plugin_transient->response[ $plugin ] = (object) [
'slug' => $plugin_folder,
'new_version' => WP_ROCKET_LASTVERSION,
'url' => 'https://cloudlinux.com',
'package' => sprintf( 'https://cloudlinux.com/%s/clsop_%s.zip', get_rocket_option( 'consumer_key' ), WP_ROCKET_LASTVERSION ),
];
$this->event_manager->remove_callback( 'pre_set_site_transient_update_plugins', [ $this, 'maybe_add_rocket_update_data' ] );
set_site_transient( 'update_plugins', $plugin_transient );
// @phpstan-ignore-next-line
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// translators: %s is the plugin name.
$title = sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME );
$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 );
add_filter( 'update_plugin_complete_actions', [ $this, 'rollback_add_return_link' ] );
rocket_put_content( WP_CONTENT_DIR . '/advanced-cache.php', '' );
$upgrader->upgrade( $plugin );
wp_die(
'',
// translators: %s is the plugin name.
esc_html( sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME ) ),
[
'response' => 200,
]
);
}
/**
* After a rollback has been done, replace the "return to" link by a link pointing to WP Rocket's tools page.
* A link to the plugins page is kept in case the plugin is not reactivated correctly.
*
* @since 3.2.4
*
* @param array $update_actions Array of plugin action links.
* @return array The array of links where the "return to" link has been replaced.
*/
public function rollback_add_return_link( $update_actions ) {
if ( ! isset( $update_actions['plugins_page'] ) ) {
return $update_actions;
}
$update_actions['plugins_page'] = sprintf(
/* translators: 1 and 3 are link openings, 2 is a link closing. */
__( '%1$sReturn to AccelerateWP%2$s or %3$sgo to Plugins page%2$s', 'rocket' ),
'',
'',
''
);
return $update_actions;
}
/**
* Set plugin option before upgrade.
*
* @param mixed $return The result of the upgrade process.
* @param array $plugin The plugin data.
*
* @return mixed|WP_Error
*/
public function upgrade_pre_install_option( $return, $plugin = [] ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.returnFound
if ( is_wp_error( $return ) || ! $plugin ) {
return $return;
}
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
// CL.
if ( empty( $plugin ) || ( 'wp-rocket/wp-rocket.php' !== $plugin && 'clsop/clsop.php' !== $plugin ) ) {
return $return;
}
set_transient( 'wp_rocket_updating', true, MINUTE_IN_SECONDS );
return $return;
}
/**
* Update plugin option after upgrade.
*
* @param mixed $return The result of the upgrade process.
* @param array $plugin The plugin data.
*
* @return mixed|string|WP_Error
*/
public function upgrade_post_install_option( $return, $plugin = [] ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.returnFound
if ( is_wp_error( $return ) || ! $plugin ) {
return $return;
}
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
// CL.
if ( empty( $plugin ) || ( 'wp-rocket/wp-rocket.php' !== $plugin && 'clsop/clsop.php' !== $plugin ) ) {
return $return;
}
delete_transient( 'wp_rocket_updating' );
return $return;
}
/**
* Displays Renewal notice on the plugins page
*
* @return void
*/
public function display_renewal_notice() {
$latest_version_data = $this->get_cached_latest_version_data();
if ( is_wp_error( $latest_version_data ) ) {
return;
}
if ( ! isset( $latest_version_data->stable_version ) ) {
return;
}
$this->renewal_notice->renewal_notice( $latest_version_data->stable_version );
}
/**
* Adds styles for expired banner
*
* @return void
*/
public function add_expired_styles() {
$latest_version_data = $this->get_cached_latest_version_data();
if ( is_wp_error( $latest_version_data ) ) {
return;
}
if ( ! isset( $latest_version_data->stable_version ) ) {
return;
}
$this->renewal_notice->add_expired_styles( $latest_version_data->stable_version );
}
}