diff --git a/changelog.txt b/changelog.txt
index 27aa4a3..fc6e06d 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,12 @@
+= 2.1.0 =
+
+* Added data management option to control whether plugin data is deleted on uninstall (disabled by default for data preservation).
+* Added reset plugin data functionality with site-level and network-level support.
+* Added unified uninstall cleanup system that handles all add-on data (Amazon SES, Newsletter).
+* Added automatic password clearing when both host and username fields are empty to prevent orphaned credentials.
+* Changed uninstall behavior to respect user preference: data is preserved by default unless explicitly enabled.
+* Changed add-on plugins (Amazon SES, Newsletter) to no longer perform cleanup on uninstall - all cleanup is centralized in the core plugin.
+
= 2.0.1 =
* Fixed automatic password clearing when both host and username fields are empty to prevent orphaned credentials.
diff --git a/includes/class-settings-page.php b/includes/class-settings-page.php
index 6ebc496..368b545 100644
--- a/includes/class-settings-page.php
+++ b/includes/class-settings-page.php
@@ -299,8 +299,12 @@ class Settings_Page {
add_action( 'admin_post_robotstxt_smtp_test_email', array( $this, 'handle_test_email' ) );
add_action( 'admin_post_robotstxt_smtp_clear_logs', array( $this, 'handle_clear_logs' ) );
add_action( 'admin_post_robotstxt_smtp_save_network_settings', array( $this, 'handle_save_network_settings' ) );
+ add_action( 'admin_post_robotstxt_smtp_reset_data', array( $this, 'handle_reset_data' ) );
+ add_action( 'admin_post_robotstxt_smtp_reset_data_network', array( $this, 'handle_reset_data_network' ) );
add_action( 'admin_notices', array( $this, 'display_test_email_notice' ) );
add_action( 'network_admin_notices', array( $this, 'display_test_email_notice' ) );
+ add_action( 'admin_notices', array( $this, 'display_reset_data_notice' ) );
+ add_action( 'network_admin_notices', array( $this, 'display_reset_data_notice' ) );
add_action( 'shutdown', array( $this, 'maybe_send_pending_site_test' ) );
add_action( 'updated_option', array( $this, 'handle_settings_option_updated' ), 10, 3 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
@@ -1075,6 +1079,7 @@ class Settings_Page {
public function render_site_settings_page(): void {
$this->ensure_capability( self::SCOPE_SITE );
$this->set_scope( self::SCOPE_SITE );
+ $settings = $this->get_settings();
?>
@@ -1085,6 +1090,36 @@ class Settings_Page {
do_settings_sections( self::PAGE_SLUG );
submit_button( esc_html__( 'Save Changes', 'robotstxt-smtp' ) );
?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
ensure_capability( self::SCOPE_SITE );
+
+ // Delete all plugin data for current site.
+ delete_option( self::OPTION_NAME );
+ delete_option( 'robotstxt_smtp_newsletter_options' );
+
+ // Delete logs.
+ Plugin::get_instance()->clear_all_logs();
+
+ // Clear transients.
+ $this->delete_transient_prefix( 'robotstxt_smtp_tool_' );
+ $this->delete_transient_prefix( 'robotstxt_smtp_test_result_' );
+ $this->delete_transient_prefix( 'robotstxt_smtp_amazonses_quota_' );
+
+ // Clear cron hooks.
+ wp_clear_scheduled_hook( 'robotstxt_smtp_cleanup_logs' );
+ wp_clear_scheduled_hook( 'robotstxt_smtp_cleanup_stats' );
+ wp_clear_scheduled_hook( 'robotstxt_smtp_amazonses_update_quota' );
+
+ // Redirect with success message.
+ $redirect = add_query_arg(
+ array(
+ 'page' => self::PAGE_SLUG,
+ 'robotstxt_smtp_reset' => 1,
+ ),
+ admin_url( 'options-general.php' )
+ );
+
+ wp_safe_redirect( $redirect );
+ exit;
+ }
+
+ /**
+ * Handles the reset plugin data request for network admin.
+ *
+ * @since 2.0.1
+ *
+ * @return void
+ */
+ public function handle_reset_data_network(): void {
+ $nonce_value = filter_input( INPUT_POST, '_wpnonce', FILTER_UNSAFE_RAW );
+
+ // Block reset unless the nonce matches the action button submission.
+ if ( ! is_string( $nonce_value ) || ! wp_verify_nonce( wp_unslash( $nonce_value ), 'robotstxt_smtp_reset_data_network' ) ) {
+ wp_die( esc_html__( 'The link you followed has expired.', 'robotstxt-smtp' ) );
+ }
+
+ if ( ! ROBOTSTXT_SMTP_IS_MULTISITE ) {
+ wp_die( esc_html__( 'Network reset is only available on multisite installations.', 'robotstxt-smtp' ) );
+ }
+
+ $this->ensure_capability( self::SCOPE_NETWORK );
+
+ // Delete network-wide data.
+ delete_site_option( self::NETWORK_OPTION_NAME );
+ delete_site_option( 'robotstxt_smtp_configuration_scope' );
+
+ // Delete statistics table.
+ global $wpdb;
+ $table_name = $wpdb->base_prefix . 'robotstxt_smtp_stats';
+ $wpdb->query( "DROP TABLE IF EXISTS {$table_name}" );
+ delete_site_option( 'robotstxt_smtp_stats_db_version' );
+
+ // Reset all sites in the network.
+ $sites = get_sites( array( 'fields' => 'ids' ) );
+ foreach ( $sites as $site_id ) {
+ switch_to_blog( (int) $site_id );
+
+ // Delete site options.
+ delete_option( self::OPTION_NAME );
+ delete_option( 'robotstxt_smtp_newsletter_options' );
+
+ // Clear logs.
+ Plugin::get_instance()->clear_all_logs();
+
+ // Clear transients.
+ $this->delete_transient_prefix( 'robotstxt_smtp_tool_' );
+ $this->delete_transient_prefix( 'robotstxt_smtp_test_result_' );
+ $this->delete_transient_prefix( 'robotstxt_smtp_amazonses_quota_' );
+
+ // Clear cron hooks.
+ wp_clear_scheduled_hook( 'robotstxt_smtp_cleanup_logs' );
+ wp_clear_scheduled_hook( 'robotstxt_smtp_cleanup_stats' );
+ wp_clear_scheduled_hook( 'robotstxt_smtp_amazonses_update_quota' );
+
+ restore_current_blog();
+ }
+
+ // Redirect with success message.
+ $redirect = add_query_arg(
+ array(
+ 'page' => self::NETWORK_PAGE_SLUG,
+ 'robotstxt_smtp_reset' => 1,
+ ),
+ network_admin_url( 'settings.php' )
+ );
+
+ wp_safe_redirect( $redirect );
+ exit;
+ }
+
+ /**
+ * Deletes transients with a specific prefix.
+ *
+ * @since 2.0.1
+ *
+ * @param string $prefix Transient prefix without internal storage prefix.
+ *
+ * @return void
+ */
+ private function delete_transient_prefix( string $prefix ): void {
+ global $wpdb;
+
+ $stored_prefix = '_transient_' . $prefix;
+ $timeout_prefix = '_transient_timeout_' . $prefix;
+
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $matches = $wpdb->get_col(
+ $wpdb->prepare(
+ "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
+ $wpdb->esc_like( $stored_prefix ) . '%',
+ $wpdb->esc_like( $timeout_prefix ) . '%'
+ )
+ );
+
+ if ( empty( $matches ) ) {
+ return;
+ }
+
+ foreach ( $matches as $option_name ) {
+ if ( ! is_string( $option_name ) ) {
+ continue;
+ }
+
+ if ( str_starts_with( $option_name, '_transient_timeout_' ) ) {
+ $transient_key = substr( $option_name, strlen( '_transient_timeout_' ) );
+ } else {
+ $transient_key = substr( $option_name, strlen( '_transient_' ) );
+ }
+
+ if ( '' === $transient_key ) {
+ continue;
+ }
+
+ delete_transient( $transient_key );
+ }
+ }
+
/**
* Renders the host field.
*
@@ -3990,6 +4218,9 @@ class Settings_Page {
$clean['rate_limit_per_day'] = absint( $options['rate_limit_per_day'] );
}
+ // Sanitize delete on uninstall option.
+ $clean['delete_data_on_uninstall'] = ! empty( $options['delete_data_on_uninstall'] );
+
/**
* Filters the sanitized SMTP options before they are persisted.
*
@@ -5243,6 +5474,7 @@ class Settings_Page {
'rate_limit_per_second' => 0,
'rate_limit_per_hour' => 0,
'rate_limit_per_day' => 0,
+ 'delete_data_on_uninstall' => false,
);
}
@@ -5630,6 +5862,49 @@ class Settings_Page {
+
+ 1, 'fields' => 'ids' ) );
+ $first_site_id = ! empty( $sites ) ? $sites[0] : 1;
+ $site_options = get_blog_option( $first_site_id, 'robotstxt_smtp_options', array() );
+ $should_delete_data = is_array( $site_options ) && ! empty( $site_options['delete_data_on_uninstall'] );
+ }
+} else {
+ $options = get_option( 'robotstxt_smtp_options', array() );
+ $should_delete_data = is_array( $options ) && ! empty( $options['delete_data_on_uninstall'] );
+}
+
+// Exit early if user doesn't want to delete data.
+if ( ! $should_delete_data ) {
+ return;
+}
+
if ( ! function_exists( 'robotstxt_smtp_uninstall_cleanup_site' ) ) {
/**
* Removes all plugin data for the current site.
@@ -18,12 +42,36 @@ if ( ! function_exists( 'robotstxt_smtp_uninstall_cleanup_site' ) ) {
* @return void
*/
function robotstxt_smtp_uninstall_cleanup_site(): void {
+ // Delete core SMTP plugin options.
delete_option( 'robotstxt_smtp_options' );
+ // Delete Newsletter add-on options.
+ delete_option( 'robotstxt_smtp_newsletter_options' );
+
+ // Delete logs (shared by core and add-ons).
robotstxt_smtp_uninstall_delete_logs();
+
+ // Delete core SMTP transients.
robotstxt_smtp_uninstall_delete_transient_prefix( 'robotstxt_smtp_tool_', false );
robotstxt_smtp_uninstall_delete_transient_prefix( 'robotstxt_smtp_test_result_', false );
+
+ // Delete Amazon SES transients.
+ robotstxt_smtp_uninstall_delete_transient_prefix( 'robotstxt_smtp_amazonses_quota_', false );
+
+ // Delete updater cache transients for all plugins.
+ $plugin_basenames = array(
+ 'robotstxt-smtp/robotstxt-smtp.php',
+ 'robotstxt-smtp-amazonses/robotstxt-smtp-amazonses.php',
+ 'robotstxt-smtp-newsletter/robotstxt-smtp-newsletter.php',
+ );
+ foreach ( $plugin_basenames as $basename ) {
+ delete_transient( 'robotstxt_updater_' . md5( $basename ) );
+ }
+
+ // Clear scheduled cron hooks.
wp_clear_scheduled_hook( 'robotstxt_smtp_cleanup_logs' );
+ wp_clear_scheduled_hook( 'robotstxt_smtp_cleanup_stats' );
+ wp_clear_scheduled_hook( 'robotstxt_smtp_amazonses_update_quota' );
}
}
@@ -36,11 +84,29 @@ if ( ! function_exists( 'robotstxt_smtp_uninstall_cleanup_network' ) ) {
* @return void
*/
function robotstxt_smtp_uninstall_cleanup_network(): void {
+ // Delete core SMTP network options.
delete_site_option( 'robotstxt_smtp_network_options' );
delete_site_option( 'robotstxt_smtp_configuration_scope' );
+ // Delete core SMTP site transients.
robotstxt_smtp_uninstall_delete_transient_prefix( 'robotstxt_smtp_tool_', true );
robotstxt_smtp_uninstall_delete_transient_prefix( 'robotstxt_smtp_test_result_', true );
+
+ // Delete Amazon SES site transients.
+ robotstxt_smtp_uninstall_delete_transient_prefix( 'robotstxt_smtp_amazonses_quota_', true );
+
+ // Delete updater cache site transients for all plugins.
+ $plugin_basenames = array(
+ 'robotstxt-smtp/robotstxt-smtp.php',
+ 'robotstxt-smtp-amazonses/robotstxt-smtp-amazonses.php',
+ 'robotstxt-smtp-newsletter/robotstxt-smtp-newsletter.php',
+ );
+ foreach ( $plugin_basenames as $basename ) {
+ delete_site_transient( 'robotstxt_updater_' . md5( $basename ) );
+ }
+
+ // Clear WordPress update cache.
+ delete_site_transient( 'update_plugins' );
}
}
@@ -140,8 +206,30 @@ if ( ! function_exists( 'robotstxt_smtp_uninstall_delete_logs' ) ) {
}
}
+if ( ! function_exists( 'robotstxt_smtp_uninstall_delete_statistics_table' ) ) {
+ /**
+ * Drops the statistics table from the database.
+ *
+ * @since 2.0.1
+ *
+ * @return void
+ */
+ function robotstxt_smtp_uninstall_delete_statistics_table(): void {
+ global $wpdb;
+ $table_name = $wpdb->base_prefix . 'robotstxt_smtp_stats';
+
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
+ $wpdb->query( "DROP TABLE IF EXISTS {$table_name}" );
+
+ // Delete the database version option.
+ delete_site_option( 'robotstxt_smtp_stats_db_version' );
+ }
+}
+
+// Clean up network-wide data.
robotstxt_smtp_uninstall_cleanup_network();
+// Clean up site-specific data.
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
$robotstxt_smtp_sites = get_sites( array( 'fields' => 'ids' ) );
@@ -153,3 +241,6 @@ if ( function_exists( 'is_multisite' ) && is_multisite() ) {
} else {
robotstxt_smtp_uninstall_cleanup_site();
}
+
+// Drop the statistics table (global, only once).
+robotstxt_smtp_uninstall_delete_statistics_table();
diff --git a/update.json b/update.json
index ff6b339..1869ce4 100644
--- a/update.json
+++ b/update.json
@@ -1,20 +1,20 @@
{
"name": "SMTP (by ROBOTSTXT)",
"slug": "robotstxt-smtp",
- "version": "2.0.0",
- "download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp/releases/download/2.0.0/robotstxt-smtp-2.0.0.zip",
+ "version": "2.1.0",
+ "download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp/releases/download/2.1.0/robotstxt-smtp-2.1.0.zip",
"requires": "6.5",
"requires_php": "8.2",
"tested": "6.9",
- "last_updated": "2026-01-29",
+ "last_updated": "2026-02-09",
"author": "ROBOTSTXT",
"author_profile": "https://www.robotstxt.es/",
"homepage": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp",
"description": "Configure WordPress to send emails through SMTP with detailed controls. Supports multiple SMTP providers, logging, diagnostics, and network/site-level configuration.",
- "changelog": "2.0.0 - 2026-01-29
- Security: Comprehensive security audit and hardening
- Security: Enhanced nonce validation across all forms and actions
- Security: Improved input sanitization and validation
- Security: Enhanced password encryption and migration
- Security: Secure handling of superglobals and transients
- Security: Strengthened regex patterns and port number validation
- Added: Reply-To header support for Amazon SES
- Fixed: Access control and form handling improvements
- Fixed: WordPress Multisite rate limiting enhancements
- Fixed: Empty password field handling
- Improved: Code quality and PHPDoc documentation
1.2.0 - 2026-01-27
- Enhanced DNS blacklist checking with error handling
- Added rate limiting for DNSBL queries
- Improved caching mechanism for DNS results
- Fixed warnings in SMTP diagnostics
- Security improvements and code optimization
",
+ "changelog": "2.1.0 - 2026-02-09
- Added: Data management option to control whether plugin data is deleted on uninstall (disabled by default for data preservation)
- Added: Reset plugin data functionality with site-level and network-level support
- Added: Unified uninstall cleanup system that handles all add-on data (Amazon SES, Newsletter)
- Added: Automatic password clearing when both host and username fields are empty to prevent orphaned credentials
- Changed: Uninstall behavior now respects user preference: data is preserved by default unless explicitly enabled
- Changed: Add-on plugins (Amazon SES, Newsletter) no longer perform cleanup on uninstall - all cleanup is centralized in the core plugin
- Technical: Centralized data cleanup logic in core plugin for better maintainability
- Technical: Enhanced uninstall.php to check delete_data_on_uninstall option before performing cleanup
2.0.0 - 2026-01-29
- Security: Comprehensive security audit and hardening
- Security: Enhanced nonce validation across all forms and actions
- Security: Improved input sanitization and validation
- Security: Enhanced password encryption and migration
- Security: Secure handling of superglobals and transients
- Security: Strengthened regex patterns and port number validation
- Added: Reply-To header support for Amazon SES
- Fixed: Access control and form handling improvements
- Fixed: WordPress Multisite rate limiting enhancements
- Fixed: Empty password field handling
- Improved: Code quality and PHPDoc documentation
",
"sections": {
"description": "Configure WordPress to send emails through SMTP with detailed controls. Supports multiple SMTP providers, logging, diagnostics, and network/site-level configuration.",
- "changelog": "2.0.0 - 2026-01-29
- Security: Comprehensive security audit and hardening
- Security: Enhanced nonce validation across all forms and actions
- Security: Improved input sanitization and validation
- Security: Enhanced password encryption and migration
- Security: Secure handling of superglobals and transients
- Security: Strengthened regex patterns and port number validation
- Added: Reply-To header support for Amazon SES
- Fixed: Access control and form handling improvements
- Fixed: WordPress Multisite rate limiting enhancements
- Fixed: Empty password field handling
- Improved: Code quality and PHPDoc documentation
1.2.0 - 2026-01-27
- Enhanced DNS blacklist checking with error handling
- Added rate limiting for DNSBL queries
- Improved caching mechanism for DNS results
- Fixed warnings in SMTP diagnostics
- Security improvements and code optimization
"
+ "changelog": "2.1.0 - 2026-02-09
- Added: Data management option to control whether plugin data is deleted on uninstall (disabled by default for data preservation)
- Added: Reset plugin data functionality with site-level and network-level support
- Added: Unified uninstall cleanup system that handles all add-on data (Amazon SES, Newsletter)
- Added: Automatic password clearing when both host and username fields are empty to prevent orphaned credentials
- Changed: Uninstall behavior now respects user preference: data is preserved by default unless explicitly enabled
- Changed: Add-on plugins (Amazon SES, Newsletter) no longer perform cleanup on uninstall - all cleanup is centralized in the core plugin
- Technical: Centralized data cleanup logic in core plugin for better maintainability
- Technical: Enhanced uninstall.php to check delete_data_on_uninstall option before performing cleanup
2.0.0 - 2026-01-29
- Security: Comprehensive security audit and hardening
- Security: Enhanced nonce validation across all forms and actions
- Security: Improved input sanitization and validation
- Security: Enhanced password encryption and migration
- Security: Secure handling of superglobals and transients
- Security: Strengthened regex patterns and port number validation
- Added: Reply-To header support for Amazon SES
- Fixed: Access control and form handling improvements
- Fixed: WordPress Multisite rate limiting enhancements
- Fixed: Empty password field handling
- Improved: Code quality and PHPDoc documentation
"
},
"banners": {
"low": "",