As a plugin developer, I want to ensure that my plugin doesn't leave any custom settings left behind from my plugin when upgrading from v1.0
to v2.0
.
Whenever a user uninstalls my plugin, I've created an uninstall.php
file (standard practice) which automatically removes all of my plugin's settings for a clean removal:
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) { // Exit if accessed directly
exit;
}
// Remove all plugin options with the prefix "myplugin_"
global $wpdb;
$plugin_options = $wpdb -> get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'myplugin_%'" );
foreach( $plugin_options as $option ) {
delete_option( $option -> option_name );
}
This script automatically removes all options that have the prefix of myplugin_
such as:
myplugin_some_option
myplugin_another_option_here
myplugin_yup_this_one_too
etc...
However, I am already working on a new version of my plugin with new options in my settings page. If a user has an older version of my plugin and is upgrading to the next version without uninstalling it, how do I ensure all of my old plugin options are removed for a clean upgrade? Does the uninstall.php
file automatically run when a user is upgrading to a new version of my plugin?