3

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.

2 Answers 2

1

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.

1
  • 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. Commented Feb 8, 2012 at 14:42
3

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;
}
1
  • I guess this should be the accepted answer since this is the cleaner way to do it.
    – Sudar
    Commented Mar 30, 2014 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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