replyto/uninstall.php
2026-11-03 17:39:56 +00:00

66 lines
1.9 KiB
PHP

<?php
/**
* Uninstall script for Reply-To for WP_Mail
*
* This file is executed when the plugin is uninstalled via the WordPress admin.
* Since 2.1.0 plugin data is preserved by default; it is only removed when the
* user opted in via the "Delete plugin data on uninstall" setting.
*
* @package replyto
* @since 1.1.0
* @version 2.1.0 - Data removal is now opt-in; cleanup honours the per-site setting.
*/
// If uninstall not called from WordPress, exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
if ( ! function_exists( 'wp_mail_replyto_uninstall_cleanup' ) ) {
/**
* Deletes this site's plugin options when the user opted in to removal.
*
* The opt-in flag itself is only removed together with the rest of the
* data; when data is preserved the flag is preserved too, so a later
* deactivate/reactivate/uninstall cycle keeps honouring the choice.
*
* @since 2.1.0
*
* @return void
*/
function wp_mail_replyto_uninstall_cleanup() {
// Inlined opt-in check (uninstall.php runs without the main plugin file).
$delete_data = get_option( 'wp_mail_replyto_delete_on_uninstall', false );
if ( '1' !== $delete_data && true !== $delete_data ) {
return;
}
// Legacy options (v1.0.0 - v1.0.3).
delete_option( 'wp_mail_replyto_email' );
delete_option( 'wp_mail_replyto_name' );
// Context-based configuration (v2.0.0+).
delete_option( 'wp_mail_replyto_contexts' );
delete_option( 'wp_mail_replyto_migration_v200' );
// The opt-in flag itself (v2.1.0+).
delete_option( 'wp_mail_replyto_delete_on_uninstall' );
}
}
if ( is_multisite() ) {
// Delete options from every site; each site's own opt-in decides its data.
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
foreach ( get_sites(
array(
'fields' => 'ids',
'number' => 0,
)
) as $site_id ) {
switch_to_blog( (int) $site_id );
wp_mail_replyto_uninstall_cleanup();
restore_current_blog();
}
} else {
wp_mail_replyto_uninstall_cleanup();
}