Skip to content

Commit

Permalink
Julio 21/11/14 - Rollback
Browse files Browse the repository at this point in the history
wp-rocket.php
****************
- Ajout de la constante WP_ROCKET_LASTVERSION qui contient par défaut l'avant dernière version de rocket, peut être prédéfinie via wp-config.php

inc/admin/admin.php
************************
- Ajout de la fonctionnalité du rollback

inc/admin/options.php
*************************
- Ajout de l'outil sous forme de bouton pour rollback
- Modification du message autoupdate*

(notices, supprime un comm de debug dev)
  • Loading branch information
JulioPotier committed Nov 21, 2014
1 parent 2f00c12 commit f5e1b8c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 9 deletions.
60 changes: 59 additions & 1 deletion inc/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,62 @@ function __rocket_activate_autoupdate()
wp_safe_redirect( wp_get_referer() );
die();

}
}

/**
* Do the rollback
*
* @since 2.4
*/
add_action( 'admin_post_rocket_rollback', '__rocket_rollback' );
function __rocket_rollback()
{
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'rocket_rollback' ) ) {
wp_nonce_ays( '' );
}
$plugin_transient = get_site_transient( 'update_plugins' );
$plugin_folder = plugin_basename( dirname( WP_ROCKET_FILE ) );
$plugin_file = basename( WP_ROCKET_FILE );
$version = WP_ROCKET_LASTVERSION;
$c_key = get_rocket_option( 'consumer_key' );
$url = sprintf( 'http://support.wp-rocket.me/%s/wp-rocket_%s.zip', $c_key, $version );
$temp_array = array(
'slug' => $plugin_folder,
'new_version' => $version,
'url' => 'http://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 );

$c_key = get_rocket_option( 'consumer_key' );
$transient = get_transient( 'rocket_warning_rollback' );

if ( false == $transient ) {

require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$actual_version = WP_ROCKET_VERSION;
$title = sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME );
$plugin = 'wp-rocket/wp-rocket.php';
$nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ) );
if ( $upgrader->upgrade( $plugin ) ) {
$text = __( 'A rollback has been performed from v%1$s to v%2$s.', 'rocket' );
$options = get_option( WP_ROCKET_SLUG );
$options['last_version'] = WP_ROCKET_VERSION;
$options['version'] = $version;
unset( $options['autoupdate'] );
update_option( WP_ROCKET_SLUG, $options );
} else {
$text = __( 'We tried to rollback from v%1$s to v%2$s, but an error occured.', 'rocket' );
}
$msg = sprintf( $text, $actual_version, $version );
}

wp_die( $msg, sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME ), array( 'response' => 200 ) );

}

1 change: 0 additions & 1 deletion inc/admin/notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ function rocket_warning_autoupdate()
&& rocket_valid_key() ) {

$boxes = get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true );
// var_dump( $boxes );
if ( ! in_array( __FUNCTION__, (array) $boxes ) ) {
$class = $msg['class'];
$text = $msg['msg'];
Expand Down
42 changes: 35 additions & 7 deletions inc/admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,20 +962,17 @@ function rocket_display_options()
array(
array(
'type' => 'checkbox',
'label' => __( 'Yes, please update the plugins for <b>Minor</b> & <b>Fix Bugs</b> versions.', 'rocket' ),
'label' => apply_filters( 'rocket_autoupdate_only_minor_versions', false ) ?
__( 'Yes, please update this plugin automatically for next available <b>Minor</b> & <b>Fix Bugs</b> versions.', 'rocket' ) :
__( 'Yes, please update this plugin for next available <b>all</b> versions.', 'rocket' ),
'label_for' => 'autoupdate',
'label_screen' => __( 'Auto-update', 'rocket' )
),
array(
'type' => 'helper_description',
'name' => 'autoupdate',
'description' => __( 'Like WordPress do for its minor versions, you can also let us auto-update the plugin automatically.', 'rocket' )
'description' => __( 'Like WordPress do for its versions, you can also let us auto-update the plugin automatically.', 'rocket' )
),
array(
'type' => 'helper_warning',
'name' => 'autoupdate2',
'description' => __( 'We will <b>never</b> update a Major version using this feature.', 'rocket' )
)
)
);

Expand Down Expand Up @@ -1057,6 +1054,37 @@ function rocket_display_options()

);

if ( current_user_can( 'update_plugins' ) ) {
$temp_description = __( 'Please backup you settings before, use the "Download options" button above.', 'rocket' );
if ( get_rocket_option( 'autoupdate' ) ) {
$temp_description .= __( '<br>Also, the "Auto-update" feature will be deactivated, do not activate it again if ou don\'t want to upgrade.', 'rocket' );
}
add_settings_field(
'rocket_rollback',
__( 'Update Rollback', 'rocket' ),
'rocket_button',
'tools',
'rocket_display_tools',
array(
'button'=>array(
'button_label' => sprintf( __( 'Reinstall v%s', 'rocket' ), WP_ROCKET_LASTVERSION ),
'url' => wp_nonce_url( admin_url( 'admin-post.php?action=rocket_rollback' ), 'rocket_rollback' ),
),
'helper_description'=>array(
'name' => 'rollback',
'description' => sprintf( __( 'The version %s is causing you some issues? You can ask for a rollback and reinstall the last version you used before.', 'rocket' ), WP_ROCKET_VERSION )
),
'helper_warning'=>array(
'name' => 'rollback2',
'description' => $temp_description,
),
)

);
}
unset( $temp_description );


add_settings_section( 'rocket_display_tutorials', __( 'Tutorials', 'rocket' ), '__return_false', 'tutorials' );
add_settings_field(
'tuto_preload_cache',
Expand Down
3 changes: 3 additions & 0 deletions wp-rocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
if ( ! defined( 'CHMOD_WP_ROCKET_CACHE_DIRS' ) ) {
define( 'CHMOD_WP_ROCKET_CACHE_DIRS', 0755 );
}
if ( ! defined( 'WP_ROCKET_LASTVERSION' ) ) {
define( 'WP_ROCKET_LASTVERSION' , '2.3.7' );
}

require( WP_ROCKET_INC_PATH . '/compat.php' );

Expand Down

0 comments on commit f5e1b8c

Please sign in to comment.