<?php
/*
Plugin Name: Sample Uninstallable Plugin
Plugin URI: [insert the plugin uri here]
Description: A sample plugin for testing the uninstaller
Author: Andrew Rickmann
Version: 0.1
Author URI: http://www.wp-fun.co.uk
Generated At: www.wp-fun.co.uk;
*/ 

if ( !is_plugin_active( __FILE__ ) ) {

//THIS IS THE UNINSTALL FUNCTIONS

	class fw_uninstallation_sample_uninstall {
	
		function uninstall_me(){
			global $wpdb;
	
			$db_table_name = $wpdb->prefix . "sample_uninstallable_plugin";
			
			$sql = 'DROP TABLE IF EXISTS '.$db_table_name;
			$wpdb->query( $sql );
			
			delete_option( "sample_uninstallable_plugin_db_version" );
	
	}

}

return;

}



//start of the plugin as normal

if (!class_exists('fw_uninstallation_sample')) {
    class fw_uninstallation_sample	{
		
		/**
		* @var string   The name of the database table used by the plugin
		*/	
		var $db_table_name = '';

		
		/**
		* PHP 4 Compatible Constructor
		*/
		function fw_uninstallation_sample(){$this->__construct();}
		
		/**
		* PHP 5 Constructor
		*/		
		function __construct(){
			global $wpdb;


		register_activation_hook(__FILE__,array(&$this,"install_on_activation"));
		
		$this->db_table_name = $wpdb->prefix . "sample_uninstallable_plugin";

		}
		

		
		/**
		* Creates or updates the database table, and adds a database table version number to the WordPress options.
		*/
		function install_on_activation() {
			global $wpdb;
			
			//**************************** UNINSTALLER
			register_uninstall_hook( 'uninstall_sample' , __FILE__ , array( 'fw_uninstallation_sample_uninstall' , 'uninstall_me' ) );
			//*******************************************
			
			
			$plugin_db_version = "0.1";
			$installed_ver = get_option( "sample_uninstallable_plugin_db_version" );
			//only run installation if not installed or if previous version installed
			if ($installed_ver === false || $installed_ver != $plugin_db_version) {
		
				//*****************************************************************************************
				// Create the sql - You will need to edit this to include the columns you need
				// Using the dbdelta function to allow the table to be updated if this is an update.
				// Read the limitations of the dbdelta function here: http://codex.wordpress.org/Creating_Tables_with_Plugins
				// remember to update the version number every time you want to make a change.
				//*****************************************************************************************
				$sql = "CREATE TABLE " . $this->db_table_name . " (
				id mediumint(9) NOT NULL AUTO_INCREMENT,
				test_field VARCHAR(255),
				UNIQUE KEY id (id)
				);";
			
				require_once(ABSPATH . "wp-admin/upgrade-functions.php");
				dbDelta($sql);
				//add a database version number for future upgrade purposes
				update_option("sample_uninstallable_plugin_db_version", $plugin_db_version);
			}
		}

    }
}

//instantiate the class
if (class_exists('fw_uninstallation_sample')) {
	$fw_uninstallation_sample = new fw_uninstallation_sample();
}



?>
