Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions admin/class-gdpr-requests-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,64 @@ public function reassign_content() {
wp_send_json_error( esc_html__( 'Something went wrong. Please try again.', 'gdpr' ) );
}

/**
* Reset all plugin data
* @since 1.0.0
* @author Moutushi Mandal <moutushi82@gmail.com>
*/
public function reset_plugin_data() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename to reset_plugin_settings

if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['nonce'] ) ), 'gdpr_reset_data' ) ) { // phpcs:ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gdpr_reset_settings

wp_send_json_error( esc_html__( 'We could not verify the security token. Please try again.', 'gdpr' ) );
}

// Add new options
update_option( 'gdpr_disable_css', false );
update_option( 'gdpr_use_recaptcha', false );
update_option( 'gdpr_recaptcha_site_key', '' );
update_option( 'gdpr_recaptcha_secret_key', '' );
update_option( 'gdpr_add_consent_checkboxes_registration', true );
update_option( 'gdpr_add_consent_checkboxes_checkout', true );
update_option(
'gdpr_cookie_popup_content', array(
'necessary' => array(
'name' => 'Necessary',
'status' => 'required',
'cookies_used' => '',
'how_we_use' => '',
),
'advertising' => array(
'name' => 'Advertising',
'status' => 'on',
'cookies_used' => '',
'how_we_use' => '',
),
'analytics' => array(
'name' => 'Analytics',
'status' => 'on',
'cookies_used' => '',
'how_we_use' => '',
),
'other' => array(
'name' => 'Other',
'status' => 'on',
'cookies_used' => '',
'how_we_use' => '',
),
)
);
update_option( 'gdpr_refresh_after_preferences_update', true );
update_option( 'gdpr_enable_privacy_bar', true );
update_option( 'gdpr_display_cookie_categories_in_bar', false );
update_option( 'gdpr_hide_from_bots', true );
update_option( 'gdpr_reconsent_template', 'modal' );
update_option( 'gdpr_cookie_banner_content', '' );
update_option( 'gdpr_cookie_privacy_excerpt', '' );
update_option( 'gdpr_consent_types', '' );
update_option( 'gdpr_privacy_bar_position', 'bottom' );

GDPR_Audit_Log::log( $user->ID, sprintf( esc_html__( 'Plugin data reset on %1$s.', 'gdpr' ), date( 'm/d/Y' ) ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rephrase this to "Plugin Settings were reset on %1$s"

wp_send_json_success();

}

}
12 changes: 12 additions & 0 deletions admin/partials/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@
<?php endforeach ?>
<?php endif ?>
</div>

<hr>
<h2><?php esc_html_e( 'Reset Data', 'gdpr' ); ?></h2>
<p>
<?php
echo sprintf(
/* translators: External link with instructions on how to proceed. */
esc_html__( 'To reset plugin data please click %s.', 'gdpr' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"To reset these settings, please click %s"

'<a href="#" class="gdpr-reset-data" data-nonce="' . esc_attr( wp_create_nonce( 'gdpr_reset_data' ) ) .'">' . esc_html__( 'here', 'gdpr' ) . '</a>'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gdpr-reset-settings

)
?>
</p>
<?php
do_action( 'gdpr_extra_settings' );
submit_button();
Expand Down
1 change: 1 addition & 0 deletions includes/class-gdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ private function define_admin_hooks() {
add_action( 'admin_post_gdpr_mark_resolved', array( $requests_admin, 'mark_resolved' ) );
add_action( 'wp_ajax_gdpr_anonymize_comments', array( $requests_admin, 'anonymize_comments' ) );
add_action( 'wp_ajax_gdpr_reassign_content', array( $requests_admin, 'reassign_content' ) );
add_action( 'wp_ajax_gdpr_reset_plugin_data', array( $requests_admin, 'reset_plugin_data' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the new function name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it should also bee wp_ajax_gdpr_reset_plugin_settings


// CRON JOBS
add_action( 'clean_gdpr_requests', array( $requests, 'clean_requests' ) );
Expand Down
18 changes: 18 additions & 0 deletions src/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,22 @@ $( function() {
);
} );

$( document ).on( 'click', '.gdpr-reset-data', function( e ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gdpr-reset-settings

e.preventDefault();
if ( confirm( 'Are you sure! This action will delete all previous settings.' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Are you sure? This action will delete all existing settings."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be translatable.

const nonce = $( this ).data( 'nonce' );
$.post(
ajaxurl,
{
action: 'gdpr_reset_plugin_data',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gdpr_reset_plugin_settings

nonce: nonce
},
function( res ) {
alert( 'All data deleted successfully!' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All settings deleted successfully!

This also needs to be translatable.

location.reload();
}
);

}
});
} );
4 changes: 4 additions & 0 deletions src/scss/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,7 @@
}
}
}

.gdpr-reset-data {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gdpr-reset-settings

color: red;
}