Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Created January 10, 2023 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafauysal/0d47ae10ef04a64bef920452dd3cc7bb to your computer and use it in GitHub Desktop.
Save mustafauysal/0d47ae10ef04a64bef920452dd3cc7bb to your computer and use it in GitHub Desktop.
Drop all tables belonging to the site during the deletion of the site on multisite.
<?php
/**
* Drop all tables belongs to site.
*
* @param array $tables The tables to drop.
* @param int $blog_id The site ID.
*
* @return array
*/
add_filter( 'wpmu_drop_tables', function ( $tables, $blog_id ) {
global $wpdb;
$site_tables = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->get_blog_prefix( $blog_id ) ) . '%' ), ARRAY_A );
if ( ! empty( $site_tables ) ) {
foreach ( $site_tables as $table_item ) {
$table_item = array_values( $table_item );
$tables[] = $table_item[0];
}
}
return $tables;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment