PluginProbe
UpStream: a Project Management Plugin for WordPress / 1.39.2
UpStream: a Project Management Plugin for WordPress v1.39.2
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / uninstall.php

uninstall.php in UpStream: a Project Management Plugin for WordPress 1.39.2, at uninstall.php

78 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall UpStream
4 */
5
6 // Exit if accessed directly.
7 if ( ! defined('WP_UNINSTALL_PLUGIN')) {
8 exit;
9 }
10
11 // Load UpStream file.
12 include_once('upstream.php');
13
14 global $wpdb, $wp_roles;
15
16 $options = (array)get_option('upstream_general');
17 $remove = ! empty($options['remove_data']) && ! empty($options['remove_data'][0]) ? (string)$options['remove_data'][0] === 'yes' : false;
18
19 if ($remove) {
20
21 /** Delete All the Custom Post Types */
22 $upstream_taxonomies = ['project_category'];
23 $upstream_post_types = ['project', 'client'];
24 foreach ($upstream_post_types as $post_type) {
25 $upstream_taxonomies = array_merge($upstream_taxonomies, get_object_taxonomies($post_type));
26 $items = get_posts([
27 'post_type' => $post_type,
28 'post_status' => 'any',
29 'numberposts' => -1,
30 'fields' => 'ids',
31 ]);
32
33 if ($items) {
34 foreach ($items as $item) {
35 wp_delete_post($item, true);
36 }
37 }
38 }
39
40 /** Delete All the Terms & Taxonomies */
41 foreach (array_unique(array_filter($upstream_taxonomies)) as $taxonomy) {
42 $terms = $wpdb->get_results($wpdb->prepare(
43 "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('%s') ORDER BY t.name ASC",
44 $taxonomy
45 ));
46
47 // Delete Terms.
48 if ($terms) {
49 foreach ($terms as $term) {
50 $wpdb->delete($wpdb->term_taxonomy, ['term_taxonomy_id' => $term->term_taxonomy_id]);
51 $wpdb->delete($wpdb->terms, ['term_id' => $term->term_id]);
52 }
53 }
54
55 // Delete Taxonomies.
56 $wpdb->delete($wpdb->term_taxonomy, ['taxonomy' => $taxonomy], ['%s']);
57 }
58
59 /** Delete all the Plugin Options */
60 delete_option('upstream_extensions');
61 delete_option('upstream_bugs');
62 delete_option('upstream_tasks');
63 delete_option('upstream_milestones');
64 delete_option('upstream_projects');
65 delete_option('upstream_general');
66 delete_option('upstream_version');
67
68 /** Delete Capabilities */
69 $roles = new UpStream_Roles;
70 $roles->remove_caps();
71
72 /** Delete the Roles */
73 $upstream_roles = ['upstream_manager', 'upstream_user', 'upstream_client_user'];
74 foreach ($upstream_roles as $role) {
75 remove_role($role);
76 }
77 }
78