Skip to content

Commit

Permalink
fix: restore database cleanup functionality (#37) (#38)
Browse files Browse the repository at this point in the history
The cleanup request was no longer precessed since we refactored the
settings page in v1.7.0 to use the WP settings API. Process the request
including nonce verification during page creation restores it.
  • Loading branch information
stklcode committed Jun 6, 2024
1 parent 13809ae commit 4290aed
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion inc/class-statifyblacklist-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,27 @@ public static function create_settings_page() {
?>
<div class="wrap">
<h1><?php esc_html_e( 'Statify Filter', 'statify-blacklist' ); ?></h1>
<?php
if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && ! empty( $_POST['cleanup'] ) ) {
// Database cleanup requested.
if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'statify-blacklist-options' ) ) {
// Nonce verification successful, proceed with cleanup.
StatifyBlacklist_Admin::cleanup_database();
?>
<div class="notice notice-success is-dismissible">
<p><?php esc_html_e( 'Database cleanup successful', 'statify-blacklist' ); ?></p>
</div>
<?php
} else {
// Nonce verification failed.
?>
<div class="notice notice-error is-dismissible">
<p><?php esc_html_e( 'Database cleanup request failed', 'statify-blacklist' ); ?></p>
</div>
<?php
}
}
?>

<form id="statify-settings" method="post" action="options.php">
<?php
Expand All @@ -178,7 +199,8 @@ public static function create_settings_page() {
submit_button();
?>
<hr>
<input class="button-secondary" type="submit" name="cleanUp"
<input class="button-secondary" type="submit" name="cleanup"
formaction=""
value="<?php esc_html_e( 'CleanUp Database', 'statify-blacklist' ); ?>"
onclick="return confirm('<?php echo esc_js( __( 'Do you really want to apply filters to database? This cannot be undone.', 'statify-blacklist' ) ); ?>');">
<p class="description">
Expand Down

0 comments on commit 4290aed

Please sign in to comment.