-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathuninstall.php
63 lines (51 loc) · 2.08 KB
/
uninstall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Event Tickets uninstall script.
*
* @since 5.18.0
*/
declare( strict_types=1 );
// Ensure the uninstall script is not called directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Ensure that uninstallation happens deliberately, via an option or a constant.
$option_value = get_option( 'event_tickets_uninstall', false );
$constant_value = defined( 'EVENT_TICKETS_UNINSTALL' ) && EVENT_TICKETS_UNINSTALL;
if ( ! $option_value && ! $constant_value ) {
return;
}
/*
* Run the uninstallation process.
*
* Ideally, this sould make use of objects directly. Due to the way the plugin
* is structured, we are using the global $wpdb object directly for simplicity.
*
* @todo Refactor to use objects directly.
* @todo Run other uninstallation tasks unrelated to Order Modifiers.
*/
/*
* Disable PHPCS warnings for this part of the file.
*
* phpcs:disable WordPress.DB.DirectDatabaseQuery
*/
/** @global wpdb $wpdb */
global $wpdb;
// Remove the option for this uninstall process, so it must manually be set again.
delete_option( 'event_tickets_uninstall' );
// Remove the options that indicate what version of the DB tables are installed.
delete_option( 'stellar_schema_version_tec-order-modifiers' );
delete_option( 'stellar_schema_version_tec-order-modifiers-meta' );
delete_option( 'stellar_schema_version_tec-order-modifiers-relationships' );
// Remove the options that indicate the previous version of the DB tables.
delete_option( 'stellar_schema_previous_version_tec-order-modifiers' );
delete_option( 'stellar_schema_previous_version_tec-order-modifiers-meta' );
delete_option( 'stellar_schema_previous_version_tec-order-modifiers-relationships' );
// Disable foreign key checks.
$wpdb->query( 'SET FOREIGN_KEY_CHECKS = 0' );
// Drop our custom tables.
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}tec_order_modifiers" );
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}tec_order_modifiers_meta" );
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}tec_order_modifier_relationships" );
// Re-enable foreign key checks.
$wpdb->query( 'SET FOREIGN_KEY_CHECKS = 1' );