How to remove wordpress plugin data on uninstall

When creating wordpress plugins, especially for the public wordpress directory, you must make sure that all plugin data is deleted on plugin uninstall. In this tutorial I`ll show you how to remove the plugins options when user decides to uninstall it.

Using the wordpress api this is a fairly simple task. You just have to create a file called “uninstall.php” with the following contents and put it in your plugin folder.

if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
// Check if options exist and delete it
if ( get_option( 'awp_option' ) != false ) {
delete_option( 'awp_option' );

Now when a user uninstalls the plugin it will delete the “awp_option” you should repeat this action for all your options and your house-keeping function is ready.