Created
January 10, 2023 19:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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