WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a plugin that creates tables when activated or when a new blog is added to a network. When a blog is deleted I would like to be able to remove those tables for that blog. Is there a hook available to do this?

I imagine it would be something similar to wpmu_new_blog, but I can't find an equivalent for deleting.

share|improve this question
up vote 1 down vote accepted

The function wpmu_delete_blog in /wp-admin/includes/ms.php has an action hook called delete_blog. This hook passes the variable of $blog_id

You could try plugging into that hook, although it is executed right at the beginning of the function.

share|improve this answer
Thank you! Even more interesting is that the function is identifying tables to drop based on the table prefix, then using apply_filters to allow modifying the list. Looks like I can just add my tables using the filter and have wpmu_delete_blog delete them for me. If this works I'll mark your answer as the correct one. – Dave Carlile Feb 8 '12 at 14:42

This is arguably the better way to do it if you're just deleting tables, but nothingtosee's answer is also valid, and would be the required way if you need to do something besides dropping tables.

add_filter("wpmu_drop_tables", "DropTablesForBlog");

function DropTablesForBlog($tables)
  global $wpdb;

  $tables[] = $wpdb->prefix . "my_plugin_table_1";
  $tables[] = $wpdb->prefix . "my_plugin_table_2";
  $tables[] = $wpdb->prefix . "my_plugin_table_2";

  return $tables;
share|improve this answer
I guess this should be the accepted answer since this is the cleaner way to do it. – Sudar Mar 30 '14 at 3:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.