From 914b1cfef23c9355de0aa3b0492921a32c839fce Mon Sep 17 00:00:00 2001 From: Jordan Knott Date: Wed, 18 Oct 2017 12:23:30 -0500 Subject: [PATCH] Add plugin; Add README --- README.md | 12 +++++++++ db-cleaner.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 README.md create mode 100644 db-cleaner.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..5eb31d5 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# WordPress DB Cleaner # + +A very simple plugin that lets you clean up tables left over from previous deleted sites on a multisite installation. +While WordPress will delete the tables it creates for a new site, tables created by plugins will remain. + +This plugin adds a page under tools. In the textfield on this page, a list of site IDs can be given. The plugin will go through and delete all the tables that contain that ID. + +Multiple IDs can be given my comma seperating them. + +# License # + +MIT License. A copy can be found in the root of this repository. diff --git a/db-cleaner.php b/db-cleaner.php new file mode 100644 index 0000000..a4fd290 --- /dev/null +++ b/db-cleaner.php @@ -0,0 +1,68 @@ +dbname; + + $data = array(); + foreach($ids as $id) { + $sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME like '%_\_" . $id . "\__%' and TABLE_SCHEMA = '$dbname'"; + $table_names = $wpdb->get_results($sql); + foreach($table_names as $key => $row) { + array_push($data, $row->TABLE_NAME); + $query = "DROP TABLE IF EXISTS $row->TABLE_NAME"; + $wpdb->query($query); + } + } + echo join(":", $data); + wp_die(); +} + +function myplugin_admin_page(){ + ?> + +
+

DB Cleaner

+ + +
+
+ +
+