64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Reservair uninstall routine.
|
|
*
|
|
* Runs only when the user deletes the plugin from the WordPress admin. It removes
|
|
* exclusively this plugin's own data — tables and options that use the `rsv_`
|
|
* prefix — and never touches anything created by WordPress core or other plugins.
|
|
*
|
|
* @package reservair
|
|
*/
|
|
|
|
// Bail unless WordPress is genuinely performing an uninstall.
|
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|
exit;
|
|
}
|
|
|
|
// Uninstall runs in isolation (the main plugin file is not loaded), so pull in
|
|
// the autoloader before referencing any of the plugin's classes.
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
global $wpdb;
|
|
|
|
// Drop the plugin's tables. Children are dropped before parents so that foreign
|
|
// key constraints never block removal; the checks are disabled as a safety net.
|
|
// $rsv_tables = [
|
|
// 'rsv_timetable_reservation_confirmation',
|
|
// 'rsv_timetable_reservation',
|
|
// 'rsv_timetable_capacity',
|
|
// 'rsv_reservation',
|
|
// 'rsv_form_submit',
|
|
// 'rsv_timetable',
|
|
// 'rsv_form_definition',
|
|
// ];
|
|
|
|
// $wpdb->query( 'SET FOREIGN_KEY_CHECKS = 0' );
|
|
|
|
// foreach ( $rsv_tables as $rsv_table ) {
|
|
// $table_name = $wpdb->prefix . $rsv_table; // Static, prefixed identifier — safe to interpolate.
|
|
// $wpdb->query( "DROP TABLE IF EXISTS `{$table_name}`" );
|
|
// }
|
|
|
|
// $wpdb->query( 'SET FOREIGN_KEY_CHECKS = 1' );
|
|
|
|
// Remove the plugin's options.
|
|
$rsv_options = [
|
|
'rsv_google_access_token',
|
|
'rsv_google_refresh_token',
|
|
'rsv_google_sync_token',
|
|
'rsv_google_token_expires',
|
|
'rsv_google_calendar_id',
|
|
'rsv_google_client_id',
|
|
'rsv_google_client_secret',
|
|
'rsv_google_webhook_channel_id',
|
|
'rsv_google_webhook_expiration',
|
|
'rsv_google_webhook_resource_id',
|
|
];
|
|
|
|
foreach ( $rsv_options as $rsv_option ) {
|
|
delete_option( $rsv_option );
|
|
}
|
|
|
|
// Remove the custom capability from every role.
|
|
RsvCapabilities::revoke();
|