| 1 |
<?php |
| 2 |
/** |
| 3 |
* If uninstall.php is not called by WordPress, die. |
| 4 |
*/ |
| 5 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 6 |
die; |
| 7 |
} |
| 8 |
// @formatter:off |
| 9 |
|
| 10 |
/** |
| 11 |
* Uninstall function to clean up plugin data. |
| 12 |
*/ |
| 13 |
function winp_uninstall() { |
| 14 |
global $wpdb; |
| 15 |
|
| 16 |
$post_type = 'wbcr-snippets'; |
| 17 |
$taxonomy = 'wbcr-snippet-tags'; |
| 18 |
|
| 19 |
$snippets = get_posts( |
| 20 |
[ |
| 21 |
'post_type' => $post_type, |
| 22 |
'post_status' => [ 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ], |
| 23 |
'numberposts' => - 1, |
| 24 |
] |
| 25 |
); |
| 26 |
|
| 27 |
if ( ! empty( $snippets ) ) { |
| 28 |
foreach ( (array) $snippets as $snippet ) { |
| 29 |
wp_delete_post( $snippet->ID, true ); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
$query = 'SELECT t.name, t.term_id |
| 34 |
FROM ' . $wpdb->terms . ' AS t |
| 35 |
INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt |
| 36 |
ON t.term_id = tt.term_id |
| 37 |
WHERE tt.taxonomy = "' . $taxonomy . '"'; |
| 38 |
|
| 39 |
$terms = $wpdb->get_results( $query ); |
| 40 |
if ( ! empty( $terms ) ) { |
| 41 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
| 42 |
register_taxonomy( $taxonomy, $post_type, [] ); |
| 43 |
} |
| 44 |
foreach ( $terms as $term ) { |
| 45 |
wp_delete_term( $term->term_id, $taxonomy ); |
| 46 |
} |
| 47 |
|
| 48 |
unregister_taxonomy( $taxonomy ); |
| 49 |
} |
| 50 |
|
| 51 |
// Remove plugin options. |
| 52 |
$wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE 'wbcr_inp_%';" ); |
| 53 |
} |
| 54 |
|
| 55 |
if ( is_multisite() ) { |
| 56 |
global $wpdb, $wp_version; |
| 57 |
|
| 58 |
$wpdb->query( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key LIKE 'wbcr_inp_%';" ); |
| 59 |
|
| 60 |
$blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 61 |
|
| 62 |
if ( ! empty( $blogs ) ) { |
| 63 |
foreach ( $blogs as $blog_id ) { |
| 64 |
switch_to_blog( $blog_id ); |
| 65 |
|
| 66 |
winp_uninstall(); |
| 67 |
|
| 68 |
restore_current_blog(); |
| 69 |
} |
| 70 |
} |
| 71 |
} elseif ( get_option( 'wbcr_inp_complete_uninstall', true ) ) { |
| 72 |
winp_uninstall(); |
| 73 |
} |
| 74 |
// @formatter:on |
| 75 |
|