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

WordPress Trac noreply at wordpress.org
Tue Jan 31 08:42:45 UTC 2023


#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 carl-alberto):

 to add on as a temporary solution, this will also delete the corresponding
 subsite's `uploads` folder

 {{{#!php
 <?php
 add_action( 'wp_delete_site', 'wpmu_delete_blog_uploads_folder' );

 /**
  * Deletes the corresponding uploads folder of a subsite.
  *
  * @return boolean Return true if successful.
  */
 function wpmu_delete_blog_uploads_folder() {

                 require_once ABSPATH . 'wp-admin/includes/class-wp-
 filesystem-base.php';
                 require_once ABSPATH . 'wp-admin/includes/class-wp-
 filesystem-direct.php';

                 $upload_dir = wp_upload_dir(); // This function already
 calls the subsite's upload folder path automatically.

                 $fileSystemDirect = new WP_Filesystem_Direct( false );

                 return $fileSystemDirect->rmdir( $upload_dir['basedir'],
 true );

 }
 }}}




 it seems @johnjamesjacoby is right that there is a ready function
 `wpmu_delete_blog` which also calls the `wp_delete_site` which also calls
 `wp_uninitialize_site` and supposedly deletes the corresponding uploads
 folder. Those functions might need to be revisited as it seems to be
 logical to delete those along when a subsite is deleted, otherwise a busy
 multisite can easily be bloated with unnecessary files or possibly have
 something like a checkbox for confirmation like what @mdifelice proposed,
 something like:

 [[Image(www.screencast.com/users/craxtech/folders/Capture/media/55df8c6c-b108-4f08
 -bbfe-b326d6e3a229/embed)]]

 https://www.screencast.com/t/tO4WHqjZnYO

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


More information about the wp-trac mailing list