70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Uninstall script for Newsletter - SMTP (by ROBOTSTXT).
|
|
*
|
|
* Removes plugin data and database tables on uninstall.
|
|
*
|
|
* @package ROBOTSTXT_SMTP_Newsletter
|
|
*/
|
|
|
|
// Exit if not called by WordPress uninstaller.
|
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|
exit;
|
|
}
|
|
|
|
// Check if should delete data.
|
|
$should_delete = false;
|
|
|
|
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
|
|
// Check network-level setting if available.
|
|
$network_options = get_site_option( 'robotstxt_smtp_network_options', array() );
|
|
$should_delete = ! empty( $network_options['delete_data_on_uninstall'] );
|
|
} else {
|
|
// Check site-level setting.
|
|
$options = get_option( 'robotstxt_smtp_options', array() );
|
|
$should_delete = ! empty( $options['delete_data_on_uninstall'] );
|
|
}
|
|
|
|
if ( ! $should_delete ) {
|
|
// User wants to preserve data.
|
|
return;
|
|
}
|
|
|
|
// Drop tables for all sites if multisite.
|
|
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
|
|
$sites = get_sites( array( 'fields' => 'ids' ) );
|
|
|
|
foreach ( $sites as $site_id ) {
|
|
switch_to_blog( $site_id );
|
|
robotstxt_smtp_newsletter_drop_tables();
|
|
restore_current_blog();
|
|
}
|
|
} else {
|
|
robotstxt_smtp_newsletter_drop_tables();
|
|
}
|
|
|
|
// Delete plugin options.
|
|
delete_option( 'robotstxt_smtp_newsletter_options' );
|
|
|
|
/**
|
|
* Drop queue and statistics tables.
|
|
*
|
|
* @return void
|
|
*/
|
|
function robotstxt_smtp_newsletter_drop_tables() {
|
|
global $wpdb;
|
|
|
|
$queue_table = $wpdb->prefix . 'robotstxt_smtp_newsletter_queue';
|
|
$stats_table = $wpdb->prefix . 'robotstxt_smtp_newsletter_stats';
|
|
|
|
// Drop both tables.
|
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$queue_table}" );
|
|
|
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$stats_table}" );
|
|
|
|
// Delete version options.
|
|
delete_option( 'robotstxt_smtp_newsletter_queue_db_version' );
|
|
delete_option( 'robotstxt_smtp_newsletter_stats_db_version' );
|
|
}
|