- Navigate to the WordPress plugin directory of your development installation.
- Create a text file called uninstall.php in the ch8-bug-tracker directory and open it in a code editor.
- Start the new script with the standard <?php opening tags.
- Implement a new function called ch8bt_drop_table by adding this code to the file:
function ch8bt_drop_table( $prefix ) {
global $wpdb;
$wpdb->query( 'DROP TABLE ' . $prefix . 'ch8_bug_data' );
}
- Add the following code to perform the deletion of tables created to store bugs from a single or network WordPress installation:
// Check that file was called from WordPress admin
if( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();
}
global $wpdb;
// Check if site is configured for network installation
if ( is_multisite() ) {
if ( !empty( $_GET['networkwide'] ) ) {
// Get blog list and cycle through all blogs
$start_blog = $wpdb->blogid;
$blog_list = $wpdb->get_col( 'SELECT blog_id FROM ' .
$wpdb->blogs );
foreach ( $blog_list as $blog ) {
switch_to_blog( $blog );
// Call function to delete bug table with prefix
ch8bt_drop_table( $wpdb->get_blog_prefix() );
}
switch_to_blog( $start_blog );
return;
}
}
ch8bt_drop_table( $wpdb->prefix );
- Save and close the code file.
- Navigate to the Plugins management page and Deactivate the Chapter 8 - Bug Tracker plugin.
- Make a copy of the entire plugin directory before performing the next step, to avoid deleting all of your work.
- Click on the plugin's Delete link and then click OK in the dialog that asks for confirmation before deleting the plugin and its data.
- Using phpMyAdmin, connect to your MySQL database to verify that the bug data table has been deleted.