-
Notifications
You must be signed in to change notification settings - Fork 17
/
uninstall.php
53 lines (43 loc) · 1.38 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
<?php
/**
* Uninstall
*
* Runs when WP Simple Pay is deleted if "Save Settings" is unchecked in
* "Settings > General > Advanced"
*
* @package SimplePay
* @copyright Copyright (c) 2021, Sandhills Development, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since unknown
*/
// Exit if not uninstalling from WordPress.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Do nothing if settings should be saved.
$settings = get_option( 'simpay_settings' );
$save_settings = isset( $settings[ 'save_settings' ] )
? $settings['save_settings']
: 'yes';
if ( 'yes' === $save_settings ) {
return;
}
global $wpdb;
// Delete pages.
$success_page = isset( $settings['success_page'] )
? $settings['success_page']
: '';
$failure_page = isset( $settings['failure_page'] )
? $settings['failure_page']
: '';
$cancelled_page = isset( $settings['cancelled_page'] )
? $settings['cancelled_page']
: '';
wp_delete_post( $success_page, true );
wp_delete_post( $failure_page, true );
wp_delete_post( $cancelled_page, true );
// Delete options.
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'simpay\_%'" );
// Delete Payment Forms.
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'simple-pay'" );
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );