Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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. –  Crappy Coding Guy Feb 8 '12 at 14:42
add comment

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 at 3:23
add comment

Your Answer

 
discard

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.