PluginProbe
Request a Quote – Quote Forms for Any WordPress Site / trunk
Request a Quote – Quote Forms for Any WordPress Site vtrunk
trunk 1.0.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.5 1.9.6 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.0 2.2.0 2.3.0 2.3.1 2.3.10 2.3.11 2.3.2 2.3.3 2.3.4 All 39 releases
request-a-quote / uninstall.php

uninstall.php in Request a Quote – Quote Forms for Any WordPress Site trunk, at uninstall.php

111 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall Request a quote
4 *
5 * Uninstalling deletes notifications and terms initializations
6 *
7 * @package REQUEST_A_QUOTE
8 * @since WPAS 4.0
9 */
10 if (!defined('WP_UNINSTALL_PLUGIN')) exit;
11 if (!current_user_can('activate_plugins')) return;
12 $tools = get_option('request_a_quote_tools');
13 if (!empty($tools['remove_data'])) {
14 global $wpdb;
15 //delete all relationships
16 $rel_list = get_option('request_a_quote_rel_list');
17 if (!empty($rel_list)) {
18 foreach ($rel_list as $krel => $vrel) {
19 $rel_type = str_replace("rel_", "", $krel);
20 $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}p2p WHERE p2p_type = %s", $rel_type));
21 if (!empty($vrel['attrs'])) {
22 foreach (array_keys($vrel['attrs']) as $rel_attr) {
23 $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}p2pmeta WHERE meta_key = %s", $rel_attr));
24 }
25 }
26 }
27 }
28 $app_post_types = Array(
29 'emd_quote'
30 );
31 foreach ($app_post_types as $post_type) {
32 //delete all taxonomies
33 $tax_list = get_option('request_a_quote_tax_list');
34 if (!empty($tax_list[$post_type])) {
35 foreach (array_keys($tax_list[$post_type]) as $tkey) {
36 if ($tax_list[$post_type][$tkey]['type'] != 'builtin') {
37 $wpdb->delete($wpdb->term_taxonomy, array(
38 'taxonomy' => $tkey
39 ));
40 }
41 }
42 }
43 //delete posts and attrs
44 $postslist = get_posts(array(
45 'post_type' => $post_type,
46 'numberposts' => - 1,
47 'post_status' => 'any'
48 ));
49 if (!empty($postslist)) {
50 $entity_fields = get_option('request_a_quote_attr_list');
51 foreach ($postslist as $mypost) {
52 if (!empty($entity_fields[$post_type])) {
53 //Delete fields
54 foreach (array_keys($entity_fields[$post_type]) as $myfield) {
55 if (in_array($entity_fields[$post_type][$myfield]['display_type'], Array(
56 'file',
57 'image',
58 'plupload_image',
59 'thickbox_image'
60 ))) {
61 $pmeta = get_post_meta($mypost->ID, $myfield);
62 if (!empty($pmeta)) {
63 foreach ($pmeta as $file_id) {
64 wp_delete_attachment($file_id);
65 }
66 }
67 }
68 delete_post_meta($mypost->ID, $myfield);
69 }
70 //delete post
71 wp_delete_post($mypost->ID);
72 }
73 }
74 }
75 }
76 // Delete orphan relationships
77 $wpdb->query($wpdb->prepare("DELETE tr FROM {$wpdb->term_relationships} tr LEFT JOIN {$wpdb->posts} posts ON posts.ID = tr.object_id WHERE posts.ID IS NULL;"));
78 // Delete orphan terms
79 $wpdb->query($wpdb->prepare("DELETE t FROM {$wpdb->terms} t LEFT JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.term_id IS NULL;"));
80 // Delete orphan term meta
81 if (!empty($wpdb->termmeta)) {
82 $wpdb->query($wpdb->prepare("DELETE tm FROM {$wpdb->termmeta} tm LEFT JOIN {$wpdb->term_taxonomy} tt ON tm.term_id = tt.term_id WHERE tt.term_id IS NULL;"));
83 }
84 $pages_list = get_option('request_a_quote_setup_pages_list', Array());
85 if (!empty($pages_list)) {
86 foreach ($pages_list as $page_id) {
87 wp_trash_post($page_id);
88 }
89 }
90 // Clear any cached data that has been removed
91 wp_cache_flush();
92 }
93 if (!empty($tools['remove_settings'])) {
94 global $wpdb;
95 $pages_list = get_option('request_a_quote_setup_pages_list', Array());
96 if (!empty($pages_list)) {
97 foreach ($pages_list as $page_id) {
98 wp_trash_post($page_id);
99 }
100 }
101 //delete all settings
102 $options_name = 'request_a_quote_%';
103 $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE %s", $options_name));
104 }
105 $emd_activated_plugins = get_option('emd_activated_plugins');
106 if (!empty($emd_activated_plugins)) {
107 $emd_activated_plugins = array_diff($emd_activated_plugins, Array(
108 'request-a-quote'
109 ));
110 update_option('emd_activated_plugins', $emd_activated_plugins);
111 }