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