wordpress-popular-posts
Last commit date
assets
6 years ago
i18n
6 years ago
src
6 years ago
vendor
6 years ago
index.php
6 years ago
readme.txt
6 years ago
uninstall.php
6 years ago
wordpress-popular-posts.php
6 years ago
uninstall.php
95 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Fired when the plugin is uninstalled. |
| 4 | * |
| 5 | * @package WordpressPopularPosts |
| 6 | * @author Hector Cabrera <me@cabrerahector.com> |
| 7 | * @license GPL-2.0+ |
| 8 | * @link https://cabrerahector.com |
| 9 | * @copyright 2008-2018 Hector Cabrera |
| 10 | */ |
| 11 | |
| 12 | // If uninstall, not called from WordPress, then exit |
| 13 | if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | // Run uninstall for each blog in the network |
| 18 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 19 | |
| 20 | global $wpdb; |
| 21 | |
| 22 | $original_blog_id = get_current_blog_id(); |
| 23 | $blogs_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ); |
| 24 | |
| 25 | foreach( $blogs_ids as $blog_id ) { |
| 26 | |
| 27 | switch_to_blog( $blog_id ); |
| 28 | |
| 29 | // Delete plugin's options |
| 30 | delete_option( 'wpp_ver' ); |
| 31 | delete_option( 'wpp_update' ); |
| 32 | delete_option( 'wpp_settings_config' ); |
| 33 | delete_option( 'wpp_rand' ); |
| 34 | delete_option( 'wpp_transients' ); |
| 35 | |
| 36 | // delete tables |
| 37 | uninstall(); |
| 38 | |
| 39 | // delete thumbnails cache and its directory |
| 40 | delete_thumb_cache(); |
| 41 | |
| 42 | } |
| 43 | |
| 44 | // Switch back to current blog |
| 45 | switch_to_blog( $original_blog_id ); |
| 46 | |
| 47 | } else { |
| 48 | |
| 49 | // Delete plugin's options |
| 50 | delete_option( 'wpp_ver' ); |
| 51 | delete_option( 'wpp_update' ); |
| 52 | delete_option( 'wpp_settings_config' ); |
| 53 | delete_option( 'wpp_rand' ); |
| 54 | delete_option( 'wpp_transients' ); |
| 55 | |
| 56 | // delete tables |
| 57 | uninstall(); |
| 58 | |
| 59 | // delete thumbnails cache and its directory |
| 60 | delete_thumb_cache(); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | function delete_thumb_cache() { |
| 65 | $wp_upload_dir = wp_get_upload_dir(); |
| 66 | |
| 67 | if ( is_dir( $wp_upload_dir['basedir'] . "/wordpress-popular-posts" ) ) { |
| 68 | $files = glob( $wp_upload_dir['basedir'] . "/wordpress-popular-posts/*" ); // get all file names |
| 69 | |
| 70 | if ( is_array($files) && !empty($files) ) { |
| 71 | foreach($files as $file){ // iterate files |
| 72 | if ( is_file($file) ) |
| 73 | @unlink($file); // delete file |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Finally, delete wpp's upload directory |
| 78 | @rmdir( $wp_upload_dir['basedir'] . "/wordpress-popular-posts" ); |
| 79 | |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | function uninstall(){ |
| 84 | |
| 85 | global $wpdb; |
| 86 | |
| 87 | // Delete db tables |
| 88 | $prefix = $wpdb->prefix . "popularposts"; |
| 89 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}data;" ); |
| 90 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}datacache;" ); |
| 91 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}datacache_backup;" ); |
| 92 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}log;" ); |
| 93 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}summary" ); |
| 94 | |
| 95 | } |