[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 Oct 25 16:54:02 UTC 2018


#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         |     Focuses:  multisite
--------------------------------+------------------------------

Comment (by 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:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list