wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Restore settings after Safe Mode

Open camilamadronero-zz opened this issue 2 years ago • 9 comments

Is your feature request related to a problem? Please describe. Once you enable Safe Mode, there is no way to restore the old settings. This can cause the loss of multiple exclusions across multiple features.

Describe the solution you'd like There is a way to restore the old settings after enabling Safe Mode instead of starting over and create double work in tricky configuration and exclusions.

Describe alternatives you've considered These are the options I have in mind:

  1. Adding a download link to export the current settings in the Safe Mode option in the Deactivation form image
  2. Adding a Revert Safe Mode option in the plugins page: image
  3. Not related to Safe Mode, but the deactivation form could have a Export settings link/button, just in case anyone wants to save current settings before deleting WP Rocket.

Additional context Ticket: https://secure.helpscout.net/conversation/1898851114/345290/

Thanks!

camilamadronero-zz avatar May 27 '22 20:05 camilamadronero-zz

This is related: https://github.com/wp-media/wp-rocket/issues/5037

piotrbak avatar May 30 '22 08:05 piotrbak

Related ticket: https://secure.helpscout.net/conversation/1910733609/346845?folderId=2135277 The request is in the video sent by the customer.

vmanthos avatar Jun 07 '22 08:06 vmanthos

Related: https://secure.helpscout.net/conversation/1921475913/348681/

girlie avatar Jun 15 '22 18:06 girlie

https://secure.helpscout.net/conversation/1922616083/348892?folderId=377611

webtrainingwheels avatar Jun 17 '22 15:06 webtrainingwheels

Related - https://secure.helpscout.net/conversation/1930196188/350454

DahmaniAdame avatar Jun 25 '22 09:06 DahmaniAdame

Related: https://secure.helpscout.net/conversation/1940815032/354058/

viobru avatar Jul 07 '22 12:07 viobru

Related: https://secure.helpscout.net/conversation/1960171738/358167/

girlie avatar Jul 27 '22 15:07 girlie

Related: https://secure.helpscout.net/conversation/1963065900/358738/

girlie avatar Jul 30 '22 15:07 girlie

Related https://secure.helpscout.net/conversation/2003206887/367177/

camilamadronero-zz avatar Sep 09 '22 21:09 camilamadronero-zz

Related https://secure.helpscout.net/conversation/2046099120/376624/

camilamadronero-zz avatar Oct 24 '22 17:10 camilamadronero-zz

related https://secure.helpscout.net/conversation/2053599939/378432

worldwildweb avatar Nov 02 '22 10:11 worldwildweb

related https://secure.helpscout.net/conversation/2054232260/378555/

camilamadronero-zz avatar Nov 02 '22 16:11 camilamadronero-zz

To solve this problem we'll add a checkbox under Yes, apply "Safe Mode". export

Acceptance criteria:

  1. Additional checkbox is checked by default
  2. When it's checked and customer click Confirm, export file will be downloaded
  3. When it's unchecked, the export file won't be downloaded
  4. When customer switches to No, deactivate and snooze this message for radio, the checkbox won't be displayed image
  5. When checkbox was checked and customer switches to No, deactivate and snooze this message for and click on Confirm, the file won't be downloaded.
  6. Wording for the checkbox and export WP Rocket settings **(Recommended as current settings will be deleted)**

piotrbak avatar Nov 11 '22 15:11 piotrbak

Related: https://secure.helpscout.net/conversation/2068256522/381670/

juricazuanovic avatar Nov 15 '22 16:11 juricazuanovic

We will add a checkbox after this line https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/views/deactivation-intent/form.php#L49 and set a checked attribute in it to be checked by default with name attribute maybe export_settings and id as export_settings too. Then we will make some changes to our rocket_do_options_export https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/admin/admin.php#L214 to put 223-227 https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/admin/admin.php#L223-L227 in a new function maybe rocket_get_current_options_to_be_exported and this new function will return the options in the json encoded format, then we can pass it back down to the rocket_do_options_export. We will check if the checkbox is set here: https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/Engine/Admin/Deactivation/Subscriber.php#L80 $export_settings = isset( $_POST['export_settings'] ) ? true : false;

We will then call this new function rocket_get_current_options_to_be_exported with a check here just before this line: https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/Engine/Admin/Deactivation/Subscriber.php#L82

if ( export_settings ) {
  $options = rocket_get_current_options_to_be_exported();
}

just before we update safe mode options that way we still have last state of option then we will set our headers after this line: https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/Engine/Admin/Deactivation/Subscriber.php#L82

if ( export_settings ) {
  nocache_headers();
  @header( 'Content-Type: application/json' );
  @header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
  @header( 'Content-Transfer-Encoding: binary' );
  @header( 'Content-Length: ' . strlen( $options ) );
  @header( 'Connection: close' );
  echo $options;
  exit();
}

When customer switches to No, deactivate and snooze this message for radio, the checkbox won't be displayed.

For this we can update https://github.com/wp-media/wp-rocket/blob/develop/assets/js/wpr-admin-common.js to add:

$('#deactivate').click(function(){
 $('#export_settings').prop('checked', false);
 $('#export_settings').hide();
})

$('#safe_mode').click(function(){
 $('#export_settings').show();
 $('#export_settings').prop('checked', true);
})

Maybe update tests also.

Estimate the effort

[S]

@Tabrisrp @engahmeds3ed what do you think of this grooming?

jeawhanlee avatar Nov 23 '22 19:11 jeawhanlee

We will add a checkbox after this line

https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/views/deactivation-intent/form.php#L49 and set a checked attribute in it to be checked by default with name attribute maybe export_settings and id as export_settings too. Then we will make some changes to our rocket_do_options_export

https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/admin/admin.php#L214 to put 223-227

https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/admin/admin.php#L223-L227 in a new function maybe rocket_get_current_options_to_be_exported and this new function will return the options in the json encoded format, then we can pass it back down to the rocket_do_options_export. We will check if the checkbox is set here:

https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/Engine/Admin/Deactivation/Subscriber.php#L80 $export_settings = isset( $_POST['export_settings'] ) ? true : false;

We will then call this new function rocket_get_current_options_to_be_exported with a check here just before this line:

https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/Engine/Admin/Deactivation/Subscriber.php#L82

if ( export_settings ) {
  $options = rocket_get_current_options_to_be_exported();
}

just before we update safe mode options that way we still have last state of option then we will set our headers after this line:

https://github.com/wp-media/wp-rocket/blob/0918f5017d02fcc9d438c6419af5e891a589d848/inc/Engine/Admin/Deactivation/Subscriber.php#L82

if ( export_settings ) {
  nocache_headers();
  @header( 'Content-Type: application/json' );
  @header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
  @header( 'Content-Transfer-Encoding: binary' );
  @header( 'Content-Length: ' . strlen( $options ) );
  @header( 'Connection: close' );
  echo $options;
  exit();
}

When customer switches to No, deactivate and snooze this message for radio, the checkbox won't be displayed.

For this we can update https://github.com/wp-media/wp-rocket/blob/develop/assets/js/wpr-admin-common.js to add:

$('#deactivate').click(function(){
 $('#export_settings').prop('checked', false);
 $('#export_settings').hide();
})

$('#safe_mode').click(function(){
 $('#export_settings').show();
 $('#export_settings').prop('checked', true);
})

Maybe update tests also.

Estimate the effort

[S]

@Tabrisrp @engahmeds3ed what do you think of this grooming?

@jeawhanlee the only problem with this grooming is that we block the user on the popup page as we don't redirect him anymore.

I think we should search a way to send two requests when we need to export.

CrochetFeve0251 avatar Dec 02 '22 13:12 CrochetFeve0251