1 | | where should we add this? ive added this in themes function.php file, but didnt work as expected.does it delete automatically all the expired tables ? |
2 | | |
3 | | Replying to [comment:3 scamartist26]: |
4 | | > For what it's worth, we have this same issue on our multisite install. I do not see any reason to keep tables around at all. We created this little guy as a workaround: |
5 | | > |
6 | | > {{{#!php |
7 | | > <?php |
8 | | > |
9 | | > /** |
10 | | > * Cleanup orphaned tables during site deletion |
11 | | > * |
12 | | > * @param $blog_id |
13 | | > * @param $drop |
14 | | > */ |
15 | | > add_action( 'delete_blog', 'delete_blog_43162', 10, 2 ); |
16 | | > function delete_blog_43162( $blog_id, $drop ) { |
17 | | > |
18 | | > if ( true == $drop ) { |
19 | | > |
20 | | > /** |
21 | | > * SELECT all tables relating to a specific blog id and add them to wpmu_drop_tables |
22 | | > */ |
23 | | > global $wpdb; |
24 | | > $prep_query = $wpdb->prepare( "SELECT table_name FROM information_schema.TABLES WHERE table_name LIKE %s;", $wpdb->esc_like( "{$wpdb->base_prefix}{$blog_id}_" ) . '%' ); |
25 | | > $table_list = $wpdb->get_results( $prep_query, ARRAY_A ); |
26 | | > |
27 | | > add_filter( 'wpmu_drop_tables', function ( $filter_list ) use ( $table_list ) { |
28 | | > |
29 | | > foreach( $table_list as $index => $data ) { |
30 | | > $filter_list[] = $data['table_name']; |
31 | | > } |
32 | | > |
33 | | > return array_unique( $filter_list ); |
34 | | > |
35 | | > }); |
36 | | > } |
37 | | > } |
38 | | > }}} |