-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
75 lines (66 loc) · 1.7 KB
/
Copy pathuninstall.php
File metadata and controls
75 lines (66 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Uninstall routine — runs only when the plugin is deleted from wp-admin.
*
* Removes every artefact the plugin created (posts, attachments, terms, the demo
* page and its options) so deleting the plugin leaves the site exactly as it was.
*
* @package WMPB
*/
// If uninstall is not called from WordPress, bail.
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
const WMPB_POST_TYPE = 'wmpb_post';
const WMPB_TAX_CATEGORY = 'wmpb_category';
const WMPB_TAX_TAG = 'wmpb_tag';
/*
* 1. Delete every demo post together with its attached featured images.
*/
$wmpb_posts = get_posts(
array(
'post_type' => WMPB_POST_TYPE,
'post_status' => 'any',
'numberposts' => -1,
'fields' => 'ids',
'suppress_filters' => true,
)
);
foreach ( $wmpb_posts as $wmpb_post_id ) {
// Remove child attachments first.
$attachments = get_children(
array(
'post_parent' => $wmpb_post_id,
'post_type' => 'attachment',
'fields' => 'ids',
)
);
foreach ( $attachments as $attachment_id ) {
wp_delete_attachment( $attachment_id, true );
}
wp_delete_post( $wmpb_post_id, true );
}
/*
* 2. Delete the taxonomy terms.
*/
foreach ( array( WMPB_TAX_CATEGORY, WMPB_TAX_TAG ) as $wmpb_taxonomy ) {
$terms = get_terms(
array(
'taxonomy' => $wmpb_taxonomy,
'hide_empty' => false,
'fields' => 'ids',
)
);
if ( is_array( $terms ) ) {
foreach ( $terms as $term_id ) {
wp_delete_term( $term_id, $wmpb_taxonomy );
}
}
}
/*
* 3. Delete the demo page and the plugin's options.
*/
$demo_page_id = (int) get_option( 'wmpb_demo_page_id' );
if ( $demo_page_id ) {
wp_delete_post( $demo_page_id, true );
}
delete_option( 'wmpb_demo_page_id' );
delete_option( 'wmpb_seeded' );