As we saw in Chapter 2, Plugin Framework Basics, all of the code contained in a file called uninstall.php gets executed when a plugin is deleted. In this case, our code's main purpose is to run a query against the website database to remove the bug table.
Before doing so, the first few lines of the file check for the presence of a variable (WP_UNINSTALL_PLUGIN) to confirm that the code has been called as part of the plugin deletion process and not by an external user.
Once the legitimacy of the execution has been confirmed, the code that runs is similar to the table creation code, where we first get access to the WordPress database management class, followed by a check to see whether the WordPress installation is a single site or a network installation. In the first case, we make a single call to the ch8bt_drop_table function to drop the bug table, while we make multiple calls to that function for every existing site under a network environment.
The query to remove the table is actually quite simple, making a call to the query method of the wpdb class to execute a DROP TABLE SQL command.