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

WordPress Trac noreply at wordpress.org
Thu Apr 16 03:09:18 UTC 2020


#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
---------------------------------------+------------------------------
Changes (by waynmeyer):

 * keywords:  2nd-opinion => 2nd-opinion needs-testing


Comment:

 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 );
 >
 >         });
 >     }
 > }
 > }}}

 This worked like a charm, please could we have this added to core its
 vital especially for multisite.  Alternative would be as @mdifelice
 stated, simply ask an admin when they deleting the subsite if they would
 like to delete orphaned tables with a checkbox next to each table for
 custom selection, when an admin wishes to retain data then the choice
 should be available as to what tables are chosen by the admin.

 Bigup to @scamartist26 for assisting with the snippet.

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


More information about the wp-trac mailing list