Drop MailPoet tables when a site is deleted in a multisite install
This commit makes sure MailPoet tables are dropped when a site is deleted in a multisite install. It uses the filter `wpmu_drop_tables` to add the list of MailPoet tables to the list of tables that WP drops whenever a site is deleted in a multisite install. $wpdb is used instead of Doctrine entity manager as the latter is not affected by calls to switch_to_blog() which is used in this case to switch from the main site to the site being deleted. This will only work if MailPoet is network active. If it is not, MailPoet code is not executed inside the WP network admin panel, and thus our filter is not added to wpmu_drop_tables, and MP tables are not deleted. [MAILPOET-3265]
This commit is contained in:
@ -168,6 +168,12 @@ class Initializer {
|
||||
new DeferredAdminNotices,
|
||||
'printAndClean',
|
||||
]);
|
||||
|
||||
WPFunctions::get()->addFilter('wpmu_drop_tables', [
|
||||
$this,
|
||||
'multisiteDropTables',
|
||||
]);
|
||||
|
||||
$this->hooks->initEarlyHooks();
|
||||
}
|
||||
|
||||
@ -345,6 +351,13 @@ class Initializer {
|
||||
$automaticEmails->getAutomaticEmails();
|
||||
}
|
||||
|
||||
public function multisiteDropTables($tables) {
|
||||
global $wpdb;
|
||||
$tablePrefix = $wpdb->prefix . Env::$pluginPrefix;
|
||||
$mailpoetTables = $wpdb->get_col("SHOW TABLES LIKE '$tablePrefix%'");
|
||||
return array_merge($tables, $mailpoetTables);
|
||||
}
|
||||
|
||||
private function setupWoocommerceTransactionalEmails() {
|
||||
$wcEnabled = $this->wcHelper->isWooCommerceActive();
|
||||
$optInEnabled = $this->settings->get('woocommerce.use_mailpoet_editor', false);
|
||||
|
Reference in New Issue
Block a user