give
Last commit date
assets
1 year ago
blocks
2 years ago
build
1 year ago
includes
1 year ago
languages
1 year ago
sample-data
6 years ago
src
1 year ago
templates
1 year ago
vendor
1 year ago
.dependabot.yml
2 years ago
LICENSE
2 years ago
changelog.txt
2 years ago
give.php
1 year ago
license.txt
6 years ago
readme.txt
1 year ago
uninstall.php
2 years ago
wordpress-scripts-webpack.config.js
1 year ago
wpml-config.xml
6 years ago
uninstall.php
145 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Uninstall Give |
| 5 | * |
| 6 | * @package Give |
| 7 | * @since 1.0 |
| 8 | * @copyright Copyright (c) 2016, GiveWP |
| 9 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 10 | * @subpackage Uninstall |
| 11 | */ |
| 12 | |
| 13 | // Exit if accessed directly. |
| 14 | if (!defined('WP_UNINSTALL_PLUGIN')) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | // Load Give file. |
| 19 | include_once('give.php'); |
| 20 | |
| 21 | /** |
| 22 | * Initialize the main Give class, which includes loading the code necessary to process the uninstall. |
| 23 | * This is included manually because the plugins_loaded hook does not run on uninstall. |
| 24 | * |
| 25 | * @since 2.7.4 |
| 26 | */ |
| 27 | give()->init(); |
| 28 | |
| 29 | // Prevent checking for plugin updates |
| 30 | remove_filter('pre_set_site_transient_update_plugins', 'give_check_addon_updates', 999); |
| 31 | |
| 32 | global $wpdb, $wp_roles; |
| 33 | |
| 34 | |
| 35 | if (give_is_setting_enabled(give_get_option('uninstall_on_delete'))) { |
| 36 | |
| 37 | // Delete All the Custom Post Types. |
| 38 | $give_taxonomies = ['form_category', 'form_tag']; |
| 39 | $give_post_types = ['give_forms', 'give_payment']; |
| 40 | foreach ($give_post_types as $post_type) { |
| 41 | |
| 42 | foreach (get_object_taxonomies($post_type) as $taxonomy) { |
| 43 | $give_taxonomies[] = $taxonomy; |
| 44 | } |
| 45 | |
| 46 | $items = get_posts( |
| 47 | [ |
| 48 | 'post_type' => $post_type, |
| 49 | 'post_status' => 'any', |
| 50 | 'numberposts' => -1, |
| 51 | 'fields' => 'ids', |
| 52 | ] |
| 53 | ); |
| 54 | |
| 55 | if ($items) { |
| 56 | foreach ($items as $item) { |
| 57 | wp_delete_post($item, true); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Delete All the Terms & Taxonomies. |
| 63 | foreach (array_unique(array_filter($give_taxonomies)) as $taxonomy) { |
| 64 | |
| 65 | $terms = $wpdb->get_results( |
| 66 | $wpdb->prepare( |
| 67 | " |
| 68 | SELECT t.*, tt.* |
| 69 | FROM $wpdb->terms AS t |
| 70 | INNER JOIN $wpdb->term_taxonomy AS tt |
| 71 | ON t.term_id = tt.term_id |
| 72 | WHERE tt.taxonomy IN ('%s') |
| 73 | ORDER BY t.name ASC |
| 74 | ", |
| 75 | $taxonomy |
| 76 | ) |
| 77 | ); |
| 78 | |
| 79 | // Delete Terms. |
| 80 | if ($terms) { |
| 81 | foreach ($terms as $term) { |
| 82 | $wpdb->delete($wpdb->term_taxonomy, ['term_taxonomy_id' => $term->term_taxonomy_id]); |
| 83 | $wpdb->delete($wpdb->terms, ['term_id' => $term->term_id]); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Delete Taxonomies. |
| 88 | $wpdb->delete($wpdb->term_taxonomy, ['taxonomy' => $taxonomy], ['%s']); |
| 89 | } |
| 90 | |
| 91 | // Delete the Plugin Pages. |
| 92 | $give_created_pages = ['success_page', 'failure_page', 'history_page']; |
| 93 | foreach ($give_created_pages as $p) { |
| 94 | $page = give_get_option($p, false); |
| 95 | if ($page) { |
| 96 | wp_delete_post($page, true); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Delete Capabilities. |
| 101 | give()->roles->remove_caps(); |
| 102 | |
| 103 | // Delete the Roles. |
| 104 | $give_roles = ['give_manager', 'give_accountant', 'give_worker', 'give_donor']; |
| 105 | foreach ($give_roles as $role) { |
| 106 | remove_role($role); |
| 107 | } |
| 108 | |
| 109 | // Remove all give database tables. |
| 110 | $give_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}give_%'"); |
| 111 | $wpdb->query('DROP TABLE ' . implode(',', $give_tables)); |
| 112 | |
| 113 | // Cleanup Cron Events. |
| 114 | wp_clear_scheduled_hook('give_daily_scheduled_events'); |
| 115 | wp_clear_scheduled_hook('give_weekly_scheduled_events'); |
| 116 | wp_clear_scheduled_hook('give_daily_cron'); |
| 117 | wp_clear_scheduled_hook('give_weekly_cron'); |
| 118 | |
| 119 | // Get all options. |
| 120 | $give_option_names = $wpdb->get_col( |
| 121 | $wpdb->prepare( |
| 122 | " |
| 123 | SELECT option_name |
| 124 | FROM {$wpdb->options} |
| 125 | WHERE option_name LIKE '%s' |
| 126 | ", |
| 127 | '%give%' |
| 128 | ) |
| 129 | ); |
| 130 | |
| 131 | if (!empty($give_option_names)) { |
| 132 | // Convert option name to transient or option name. |
| 133 | $new_give_option_names = []; |
| 134 | |
| 135 | // Delete all the Plugin Options. |
| 136 | foreach ($give_option_names as $option) { |
| 137 | if (false !== strpos($option, 'give_cache')) { |
| 138 | Give_Cache::delete($option); |
| 139 | } else { |
| 140 | delete_option($option); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 |