[wp-trac] [WordPress Trac] #43162: Deleting a site from a multisite network leaves orphaned database tables and files

WordPress Trac noreply at wordpress.org
Fri Nov 19 12:20:24 UTC 2021


#43162: Deleting a site from a multisite network leaves orphaned database tables
and files
---------------------------------------+------------------------------
 Reporter:  bluep92877                 |       Owner:  (none)
     Type:  enhancement                |      Status:  new
 Priority:  normal                     |   Milestone:  Awaiting Review
Component:  Networks and Sites         |     Version:  3.0
 Severity:  normal                     |  Resolution:
 Keywords:  2nd-opinion needs-testing  |     Focuses:  multisite
---------------------------------------+------------------------------

Comment (by deepakdcc):

 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
 ?

 Replying to [comment:3 scamartist26]:
 > 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:
 >
 > {{{#!php
 > <?php
 >
 > /**
 >  * Cleanup orphaned tables during site deletion
 >  *
 >  * @param $blog_id
 >  * @param $drop
 >  */
 > add_action( 'delete_blog', 'delete_blog_43162', 10, 2 );
 > function delete_blog_43162( $blog_id, $drop ) {
 >
 >     if ( true == $drop ) {
 >
 >         /**
 >          * SELECT all tables relating to a specific blog id and add them
 to wpmu_drop_tables
 >          */
 >         global $wpdb;
 >         $prep_query = $wpdb->prepare( "SELECT table_name FROM
 information_schema.TABLES WHERE table_name LIKE %s;", $wpdb->esc_like(
 "{$wpdb->base_prefix}{$blog_id}_" ) . '%' );
 >         $table_list = $wpdb->get_results( $prep_query, ARRAY_A );
 >
 >         add_filter( 'wpmu_drop_tables', function ( $filter_list ) use (
 $table_list ) {
 >
 >             foreach( $table_list as $index => $data ) {
 >                 $filter_list[] = $data['table_name'];
 >             }
 >
 >             return array_unique( $filter_list );
 >
 >         });
 >     }
 > }
 > }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43162#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list