Delete Plugin Options with Verify

There are various opinions on this, but generally, if you’re “deleting” (as opposed to simply “deactivating”), you don’t necessarily need to confirm it. However, you certainly could.

The general approach to that is to include a setting to remove all settings upon delete or not. Let’s say it’s a checkbox in the plugin’s settings to “delete all” and if it’s not checked, you wont’ clear the options. (Also, in the example, assuming that all settings are a single array, with the settings as keys – but this is just an example)

// if uninstall.php is not called by WordPress, die
if (!defined('WP_UNINSTALL_PLUGIN')) {
    die;
}

$option_name="wporg_option";

// $option_name['delete_all'] contains my option setting to delete all settings.
if ( 1 == $option_name['delete_all'] ) {

     delete_option($option_name);

     // for site options in Multisite
     delete_site_option($option_name);

}