latepoint
Last commit date
blocks
4 months ago
languages
8 months ago
lib
3 months ago
public
3 months ago
latepoint.php
3 months ago
readme.txt
3 months ago
uninstall.php
4 months ago
uninstall.php
119 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Fired when the plugin is uninstalled. |
| 4 | * |
| 5 | * Removes all LatePoint database tables and plugin settings when |
| 6 | * the "Remove all data on uninstall" option is enabled in Settings > General. |
| 7 | * |
| 8 | * @package LatePoint |
| 9 | */ |
| 10 | |
| 11 | // Exit if uninstall is not called from WordPress. |
| 12 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | global $wpdb; |
| 17 | |
| 18 | $prefix = $wpdb->prefix; |
| 19 | |
| 20 | // Read the setting directly from the custom settings table, since the plugin |
| 21 | // classes are not loaded during uninstall. |
| 22 | $settings_table = $prefix . 'latepoint_settings'; |
| 23 | |
| 24 | // Check whether the settings table still exists before querying it. |
| 25 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to run a direct query here since the plugin's DB classes are not available during uninstall. |
| 26 | $table_exists = $wpdb->get_var( |
| 27 | $wpdb->prepare( 'SHOW TABLES LIKE %s', $settings_table ) |
| 28 | ); |
| 29 | |
| 30 | if ( $table_exists ) { |
| 31 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to run a direct query here since the plugin's DB classes are not available during uninstall. |
| 32 | $remove_data = $wpdb->get_var( |
| 33 | $wpdb->prepare( |
| 34 | "SELECT value FROM %i WHERE name = %s LIMIT 1", |
| 35 | $settings_table, |
| 36 | 'remove_data_on_plugin_delete' |
| 37 | ) |
| 38 | ); |
| 39 | } else { |
| 40 | $remove_data = null; |
| 41 | } |
| 42 | |
| 43 | // Only proceed with full data removal if the toggle is explicitly enabled ("on"). |
| 44 | if ( 'on' !== $remove_data ) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | // ------------------------------------------------------------------------- |
| 49 | // Drop all LatePoint tables. |
| 50 | // The list mirrors OsDatabaseHelper::get_all_latepoint_tables() plus the |
| 51 | // two tables that are defined as constants but were missing from that method. |
| 52 | // ------------------------------------------------------------------------- |
| 53 | $tables = [ |
| 54 | $prefix . 'latepoint_bundles', |
| 55 | $prefix . 'latepoint_bundles_services', |
| 56 | $prefix . 'latepoint_bookings', |
| 57 | $prefix . 'latepoint_sessions', |
| 58 | $prefix . 'latepoint_services', |
| 59 | $prefix . 'latepoint_settings', |
| 60 | $prefix . 'latepoint_service_categories', |
| 61 | $prefix . 'latepoint_work_periods', |
| 62 | $prefix . 'latepoint_custom_prices', |
| 63 | $prefix . 'latepoint_agents_services', |
| 64 | $prefix . 'latepoint_activities', |
| 65 | $prefix . 'latepoint_transactions', |
| 66 | $prefix . 'latepoint_transaction_refunds', |
| 67 | $prefix . 'latepoint_transaction_intents', |
| 68 | $prefix . 'latepoint_agents', |
| 69 | $prefix . 'latepoint_customers', |
| 70 | $prefix . 'latepoint_customer_meta', |
| 71 | $prefix . 'latepoint_service_meta', |
| 72 | $prefix . 'latepoint_booking_meta', |
| 73 | $prefix . 'latepoint_agent_meta', |
| 74 | $prefix . 'latepoint_bundle_meta', |
| 75 | $prefix . 'latepoint_steps', |
| 76 | $prefix . 'latepoint_step_settings', |
| 77 | $prefix . 'latepoint_locations', |
| 78 | $prefix . 'latepoint_location_categories', |
| 79 | $prefix . 'latepoint_processes', |
| 80 | $prefix . 'latepoint_process_jobs', |
| 81 | $prefix . 'latepoint_carts', |
| 82 | $prefix . 'latepoint_cart_meta', |
| 83 | $prefix . 'latepoint_cart_items', |
| 84 | $prefix . 'latepoint_orders', |
| 85 | $prefix . 'latepoint_order_meta', |
| 86 | $prefix . 'latepoint_order_items', |
| 87 | $prefix . 'latepoint_order_intents', |
| 88 | $prefix . 'latepoint_order_intent_meta', |
| 89 | $prefix . 'latepoint_order_invoices', |
| 90 | $prefix . 'latepoint_payment_requests', |
| 91 | $prefix . 'latepoint_recurrences', |
| 92 | $prefix . 'latepoint_customer_otp_codes', |
| 93 | $prefix . 'latepoint_blocked_periods', |
| 94 | ]; |
| 95 | |
| 96 | foreach ( $tables as $table ) { |
| 97 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange -- We need to run a direct query here since the plugin's DB classes are not available during uninstall. |
| 98 | $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table ) ); |
| 99 | } |
| 100 | |
| 101 | // ------------------------------------------------------------------------- |
| 102 | // Delete WordPress options created by LatePoint. |
| 103 | // ------------------------------------------------------------------------- |
| 104 | $options_to_delete = [ |
| 105 | 'latepoint_db_version', |
| 106 | 'latepoint_wizard_visited', |
| 107 | 'latepoint_redirect_to_wizard', |
| 108 | ]; |
| 109 | |
| 110 | foreach ( $options_to_delete as $option ) { |
| 111 | delete_option( $option ); |
| 112 | } |
| 113 | |
| 114 | // Remove any transients prefixed with latepoint_. |
| 115 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to run a direct query here since the plugin's DB classes are not available during uninstall. |
| 116 | $wpdb->query( |
| 117 | "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_latepoint_%' OR option_name LIKE '_transient_timeout_latepoint_%'" |
| 118 | ); |
| 119 |