| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* UninstallCleanup: cleans all data during uninstallation |
| 5 |
* |
| 6 |
* @package WPFunnels |
| 7 |
* @since 3.0.13 |
| 8 |
*/ |
| 9 |
class UninstallCleanup { |
| 10 |
|
| 11 |
public static function init() { |
| 12 |
$general_settings = get_option( '_wpfunnels_general_settings', []); |
| 13 |
|
| 14 |
if(isset($general_settings['uninstall_cleanup']) && $general_settings['uninstall_cleanup'] == 'on') { |
| 15 |
self::deleteAllFunnels(); |
| 16 |
self::deleteAllSteps(); |
| 17 |
self::deleteAllDBTables(); |
| 18 |
self::deleteAllOptionsValue(); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* deleteAllFunnels: deletes all funnel data during uninstallation. |
| 24 |
* |
| 25 |
* @since 3.0.13 |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public static function deleteAllFunnels() { |
| 29 |
|
| 30 |
$funnel_ids = get_posts( |
| 31 |
array( |
| 32 |
'fields' => 'ids', |
| 33 |
'numberposts' => - 1, |
| 34 |
'post_type' => 'wpfunnels', |
| 35 |
) |
| 36 |
); |
| 37 |
|
| 38 |
if(!empty($funnel_ids)) { |
| 39 |
foreach ( $funnel_ids as $funnel_id ) { |
| 40 |
wp_delete_post( $funnel_id ); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* deleteAllSteps: deletes all funnel steps |
| 47 |
* |
| 48 |
* @since 3.0.13 |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public static function deleteAllSteps() { |
| 52 |
$funnel_step_ids = get_posts( |
| 53 |
array( |
| 54 |
'fields' => 'ids', |
| 55 |
'numberposts' => - 1, |
| 56 |
'post_type' => 'wpfunnel_steps', |
| 57 |
) |
| 58 |
); |
| 59 |
|
| 60 |
if(!empty($funnel_step_ids)) { |
| 61 |
foreach ( $funnel_step_ids as $funnel_step_id ) { |
| 62 |
wp_delete_post( $funnel_step_id ); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* deleteAllDBTables: deletes all plugin custom tables |
| 69 |
* |
| 70 |
* @since 3.0.13 |
| 71 |
* @return void |
| 72 |
*/ |
| 73 |
public static function deleteAllDBTables() { |
| 74 |
|
| 75 |
global $wpdb; |
| 76 |
|
| 77 |
$sql = 'DROP TABLE IF EXISTS %1s'; |
| 78 |
|
| 79 |
$wpfnl_tables = array( |
| 80 |
$wpdb->prefix . 'wpfnl_analytics_meta', |
| 81 |
$wpdb->prefix . 'wpfnl_analytics', |
| 82 |
// AI copilot conversations and their messages. |
| 83 |
$wpdb->prefix . 'wpfnl_ai_messages', |
| 84 |
$wpdb->prefix . 'wpfnl_ai_conversations', |
| 85 |
); |
| 86 |
$wpfnl_tables = implode( ', ', $wpfnl_tables ); |
| 87 |
|
| 88 |
$wpdb->query( $wpdb->prepare( $sql, $wpfnl_tables ) ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* deleteAllOptionsValue: deletes plugins generic options data |
| 93 |
* |
| 94 |
* @since 3.0.13 |
| 95 |
* @return void |
| 96 |
*/ |
| 97 |
public static function deleteAllOptionsValue() { |
| 98 |
|
| 99 |
global $wpdb; |
| 100 |
|
| 101 |
$option_ids_sql = "SELECT `option_id` FROM {$wpdb->options} WHERE `option_name` LIKE '%wpfunnels%' OR `option_name` LIKE '%wpfnl%'"; |
| 102 |
$funnels_option_ids = $wpdb->get_results( $option_ids_sql, ARRAY_A ); |
| 103 |
|
| 104 |
$funnels_option_ids = array_column( $funnels_option_ids, 'option_id' ); |
| 105 |
$funnels_option_ids = implode( ', ', $funnels_option_ids ); |
| 106 |
$option_sql = "DELETE FROM {$wpdb->options} WHERE `option_id` IN ({$funnels_option_ids})"; |
| 107 |
|
| 108 |
$wpdb->query( $option_sql ); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
UninstallCleanup::init(); |
| 113 |
|