|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Fired when the plugin is uninstalled. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Plugin_Name |
|
6
|
|
|
* @author Your Name <[email protected]> |
|
7
|
|
|
* @license GPL-2.0+ |
|
8
|
|
|
* @link http://example.com |
|
9
|
|
|
* @copyright 2013 Your Name or Company Name |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// If uninstall not called from WordPress, then exit |
|
13
|
|
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/* Delete channels and post types */ |
|
18
|
|
|
rn_delete_custom_terms( 'rn-channel' ); |
|
19
|
|
|
rn_delete_custom_terms( 'rn-pt' ); |
|
20
|
|
|
rn_delete_notifications(); |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Detete all terms of a taxonomy |
|
24
|
|
|
* |
|
25
|
|
|
* @link http://wordpress.stackexchange.com/questions/119229/how-to-delete-custom-taxonomy-terms-in-plugins-uninstall-php |
|
26
|
|
|
*/ |
|
27
|
|
|
function rn_delete_custom_terms( $taxonomy ) { |
|
28
|
|
|
|
|
29
|
|
|
global $wpdb; |
|
30
|
|
|
|
|
31
|
|
|
$query = 'SELECT t.name, t.term_id |
|
32
|
|
|
FROM ' . $wpdb->terms . ' AS t |
|
33
|
|
|
INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt |
|
34
|
|
|
ON t.term_id = tt.term_id |
|
35
|
|
|
WHERE tt.taxonomy = "' . $taxonomy . '"'; |
|
36
|
|
|
|
|
37
|
|
|
$terms = $wpdb->get_results($query); |
|
38
|
|
|
|
|
39
|
|
|
foreach( $terms as $term ) { |
|
40
|
|
|
wp_delete_term( $term->term_id, $taxonomy ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Delete all the notifications saved in DB |
|
47
|
|
|
*/ |
|
48
|
|
|
function rn_delete_notifications() { |
|
49
|
|
|
|
|
50
|
|
|
global $wpdb; |
|
51
|
|
|
|
|
52
|
|
|
$args = array( |
|
53
|
|
|
'posts_per_page' => -1, |
|
54
|
|
|
'post_type' => 'notification', |
|
55
|
|
|
'post_status' => array( 'any', 'auto-draft' ), |
|
56
|
|
|
'update_post_term_cache' => false, |
|
57
|
|
|
'update_post_meta_cache' => false, |
|
58
|
|
|
'cache_results' => false |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$posts = new WP_Query( $args ); |
|
62
|
|
|
|
|
63
|
|
|
if( isset( $posts->posts ) && is_array( $posts->posts ) ) { |
|
64
|
|
|
|
|
65
|
|
|
foreach( $posts->posts as $post ) |
|
66
|
|
|
wp_delete_post( $post->ID, true ); |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |