| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall script for EmailOctopus. |
| 4 |
*/ |
| 5 |
|
| 6 |
// Exit if accessed directly |
| 7 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) |
| 8 |
{ |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
global $wpdb; |
| 13 |
|
| 14 |
// Delete options |
| 15 |
$plugin_options = $wpdb->get_results( |
| 16 |
"SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'emailoctopus_%' OR option_name LIKE 'widget_emailoctopus_%'" |
| 17 |
); |
| 18 |
foreach( $plugin_options as $option ) { |
| 19 |
delete_option( $option->option_name ); |
| 20 |
} |
| 21 |
|
| 22 |
// Delete custom tables |
| 23 |
$tables = [ |
| 24 |
$wpdb->prefix . 'emailoctopus_forms', |
| 25 |
$wpdb->prefix . 'emailoctopus_forms_meta', |
| 26 |
$wpdb->prefix . 'emailoctopus_custom_fields', |
| 27 |
]; |
| 28 |
foreach ( $tables as $table ) |
| 29 |
{ |
| 30 |
$wpdb->query("DROP TABLE IF EXISTS $table"); |
| 31 |
} |
| 32 |
|
| 33 |
// Delete cache (should match logic in `Utils::clear_transients()`) |
| 34 |
$transient_options = $wpdb->get_results( |
| 35 |
"SELECT option_name FROM $wpdb->options WHERE option_name LIKE '_transient_emailoctopus_%'" |
| 36 |
); |
| 37 |
foreach( $transient_options as $option ) { |
| 38 |
// Remove `_transient_` from the beginning of the string to |
| 39 |
// determine the transient name |
| 40 |
$transient_name = preg_replace('/^_transient_/', '', $option->option_name); |
| 41 |
delete_transient( $transient_name ); |
| 42 |
} |
| 43 |
|