PluginProbe
UpStream: a Project Management Plugin for WordPress / trunk
UpStream: a Project Management Plugin for WordPress vtrunk
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 trunk, at uninstall.php

84 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 * @package UpStream
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
10 exit;
11 }
12
13 // Load UpStream file.
14 require_once 'upstream.php';
15
16 global $wpdb, $wp_roles;
17
18 $options = (array) get_option( 'upstream_general' );
19 $remove = ! empty( $options['remove_data'] ) && ! empty( $options['remove_data'][0] ) ? 'yes' === (string) $options['remove_data'][0] : false;
20
21 if ( $remove ) {
22 /** Delete All the Custom Post Types */
23 $upstream_taxonomies = array( 'project_category' );
24 $upstream_post_types = array( 'project', 'client' );
25
26 foreach ( $upstream_post_types as $wp_post_type ) {
27 $upstream_taxonomies = array_merge( $upstream_taxonomies, get_object_taxonomies( $wp_post_type ) );
28 $items = get_posts(
29 array(
30 'post_type' => $wp_post_type,
31 'post_status' => 'any',
32 'numberposts' => -1,
33 'fields' => 'ids',
34 )
35 );
36
37 if ( $items ) {
38 foreach ( $items as $item ) {
39 wp_delete_post( $item, true );
40 }
41 }
42 }
43
44 /** Delete All the Terms & Taxonomies */
45 foreach ( array_unique( array_filter( $upstream_taxonomies ) ) as $wp_tax ) {
46 $terms = $wpdb->get_results(
47 $wpdb->prepare(
48 "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",
49 $wp_tax
50 )
51 );
52
53 // Delete Terms.
54 if ( $terms ) {
55 foreach ( $terms as $wp_term ) {
56 $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $wp_term->term_taxonomy_id ) );
57 $wpdb->delete( $wpdb->terms, array( 'term_id' => $wp_term->term_id ) );
58 }
59 }
60
61 // Delete Taxonomies.
62 $wpdb->delete( $wpdb->term_taxonomy, array( 'taxonomy' => $wp_tax ), array( '%s' ) );
63 }
64
65 /** Delete all the Plugin Options */
66 delete_option( 'upstream_extensions' );
67 delete_option( 'upstream_bugs' );
68 delete_option( 'upstream_tasks' );
69 delete_option( 'upstream_milestones' );
70 delete_option( 'upstream_projects' );
71 delete_option( 'upstream_general' );
72 delete_option( 'upstream_version' );
73
74 /** Delete Capabilities */
75 $roles = new UpStream_Roles();
76 $roles->remove_caps();
77
78 /** Delete the Roles */
79 $upstream_roles = array( 'upstream_manager', 'upstream_user', 'upstream_client_user' );
80 foreach ( $upstream_roles as $wp_role ) {
81 remove_role( $wp_role );
82 }
83 }
84