insert-headers-and-footers
Last commit date
admin
1 year ago
build
1 year ago
includes
1 year ago
languages
1 year ago
ihaf.php
1 year ago
readme.txt
1 year ago
uninstall.php
2 years ago
uninstall.php
133 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Uninstall WPCode. |
| 4 | * |
| 5 | * Remove: |
| 6 | * - custom capabilities. |
| 7 | * |
| 8 | * @package WPCode |
| 9 | */ |
| 10 | |
| 11 | // Exit if accessed directly. |
| 12 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | // If the function already exists we shouldn't run the uninstall as another version of the plugin is active. |
| 17 | if ( function_exists( 'WPCode' ) ) { |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | require_once 'ihaf.php'; |
| 22 | |
| 23 | if ( class_exists( 'WPCode_Capabilities' ) ) { |
| 24 | // Remove custom capabilities on uninstall. |
| 25 | WPCode_Capabilities::uninstall(); |
| 26 | } |
| 27 | |
| 28 | if ( class_exists( 'WPCode_Notifications' ) ) { |
| 29 | WPCode_Notifications::delete_notifications_data(); |
| 30 | } |
| 31 | |
| 32 | if ( function_exists( 'wp_unschedule_hook' ) ) { |
| 33 | wp_unschedule_hook( 'wpcode_usage_tracking_cron' ); |
| 34 | } |
| 35 | |
| 36 | delete_option( 'wpcode_send_usage_last_run' ); |
| 37 | delete_option( 'wpcode_usage_tracking_config' ); |
| 38 | |
| 39 | // Let's see if the uninstall_data option is set. |
| 40 | $settings = get_option( 'wpcode_settings', array() ); |
| 41 | |
| 42 | if ( ! empty( $settings['uninstall_data'] ) ) { |
| 43 | // Delete the revisions table. |
| 44 | global $wpdb; |
| 45 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpcode_revisions" ); |
| 46 | |
| 47 | // Delete settings. |
| 48 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'wpcode\_%'" ); |
| 49 | // Delete ihaf data. |
| 50 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'ihaf\_%'" ); |
| 51 | // Delete plugin user meta. |
| 52 | $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'wpcode\_%'" ); |
| 53 | // Delete post meta. |
| 54 | $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'wpcode\_%'" ); |
| 55 | $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '_wpcode\_%'" ); |
| 56 | |
| 57 | // Remove any transients we've left behind. |
| 58 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_wpcode\_%'" ); |
| 59 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_site\_transient\_wpcode\_%'" ); |
| 60 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_timeout\_wpcode\_%'" ); |
| 61 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_site\_transient\_timeout\_wpcode\_%'" ); |
| 62 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_wpcode\_transient\_%'" ); |
| 63 | |
| 64 | // Delete wpcode post types. |
| 65 | $wpcode_posts = get_posts( |
| 66 | array( |
| 67 | 'post_type' => array( 'wpcode', 'wpcode-blocks' ), |
| 68 | 'post_status' => array( 'publish', 'draft', 'trash' ), |
| 69 | 'numberposts' => - 1, |
| 70 | 'fields' => 'ids', |
| 71 | ) |
| 72 | ); |
| 73 | |
| 74 | if ( $wpcode_posts ) { |
| 75 | foreach ( $wpcode_posts as $wpcode_post ) { |
| 76 | wp_delete_post( $wpcode_post, true ); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if ( function_exists( 'wpcode_register_taxonomies' ) ) { |
| 81 | wpcode_register_taxonomies(); |
| 82 | } |
| 83 | |
| 84 | // Delete all taxonomy terms. |
| 85 | $wpcode_taxonomies = array( |
| 86 | 'wpcode_type', |
| 87 | 'wpcode_location', |
| 88 | 'wpcode_tags', |
| 89 | ); |
| 90 | foreach ( $wpcode_taxonomies as $wpcode_taxonomy ) { |
| 91 | $terms = get_terms( |
| 92 | array( |
| 93 | 'taxonomy' => $wpcode_taxonomy, |
| 94 | 'hide_empty' => false, |
| 95 | 'fields' => 'ids', |
| 96 | ) |
| 97 | ); |
| 98 | if ( $terms ) { |
| 99 | foreach ( $terms as $wpcode_term ) { |
| 100 | wp_delete_term( $wpcode_term, $wpcode_taxonomy ); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | |
| 106 | global $wp_filesystem; |
| 107 | // Remove uploaded files. |
| 108 | $uploads_directory = wp_upload_dir(); |
| 109 | |
| 110 | if ( empty( $uploads_directory['error'] ) ) { |
| 111 | $wp_filesystem->rmdir( $uploads_directory['basedir'] . '/wpcode/', true ); |
| 112 | $wp_filesystem->rmdir( $uploads_directory['basedir'] . '/wpcode-logs/', true ); |
| 113 | } |
| 114 | |
| 115 | // Remove translation files. |
| 116 | $languages_directory = defined( 'WP_LANG_DIR' ) ? trailingslashit( WP_LANG_DIR ) : trailingslashit( WP_CONTENT_DIR ) . 'languages/'; |
| 117 | $translations = glob( wp_normalize_path( $languages_directory . 'plugins/wpcode-*' ) ); |
| 118 | |
| 119 | if ( ! empty( $translations ) ) { |
| 120 | foreach ( $translations as $file ) { |
| 121 | $wp_filesystem->delete( $file ); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | $translations = glob( wp_normalize_path( $languages_directory . 'plugins/insert-headers-and-footers-*' ) ); |
| 126 | |
| 127 | if ( ! empty( $translations ) ) { |
| 128 | foreach ( $translations as $file ) { |
| 129 | $wp_filesystem->delete( $file ); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 |