wordpress-popular-posts
Last commit date
assets
5 years ago
i18n
5 years ago
src
5 years ago
vendor
5 years ago
LICENSE
5 years ago
index.php
5 years ago
readme.txt
5 years ago
uninstall.php
5 years ago
wordpress-popular-posts.php
5 years ago
uninstall.php
81 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-2020 Hector Cabrera |
| 10 | */ |
| 11 | |
| 12 | // If uninstall is not called from WordPress, exit |
| 13 | if ( ! defined('WP_UNINSTALL_PLUGIN') ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | // Run uninstall for each blog in the network |
| 18 | if ( |
| 19 | function_exists('is_multisite') |
| 20 | && is_multisite() |
| 21 | ) { |
| 22 | global $wpdb; |
| 23 | |
| 24 | $original_blog_id = get_current_blog_id(); |
| 25 | $blogs_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); |
| 26 | |
| 27 | foreach( $blogs_ids as $blog_id ) { |
| 28 | switch_to_blog($blog_id); |
| 29 | // delete tables and options |
| 30 | uninstall(); |
| 31 | // delete thumbnails cache and its directory |
| 32 | delete_thumb_cache(); |
| 33 | } |
| 34 | |
| 35 | // Switch back to current blog |
| 36 | switch_to_blog($original_blog_id); |
| 37 | } else { |
| 38 | // delete tables and options |
| 39 | uninstall(); |
| 40 | // delete thumbnails cache and its directory |
| 41 | delete_thumb_cache(); |
| 42 | } |
| 43 | |
| 44 | function delete_thumb_cache() { |
| 45 | $wp_upload_dir = wp_get_upload_dir(); |
| 46 | |
| 47 | if ( is_dir($wp_upload_dir['basedir'] . "/wordpress-popular-posts") ) { |
| 48 | $files = glob($wp_upload_dir['basedir'] . "/wordpress-popular-posts/*"); // get all file names |
| 49 | |
| 50 | if ( is_array($files) && ! empty($files) ) { |
| 51 | foreach( $files as $file ){ // iterate files |
| 52 | if ( is_file($file) ) |
| 53 | @unlink($file); // delete file |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Finally, delete WPP's upload directory |
| 58 | @rmdir($wp_upload_dir['basedir'] . "/wordpress-popular-posts"); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | function uninstall() { |
| 63 | global $wpdb; |
| 64 | |
| 65 | // Delete plugin's options |
| 66 | delete_option('wpp_ver'); |
| 67 | delete_option('wpp_update'); |
| 68 | delete_option('wpp_settings_config'); |
| 69 | delete_option('wpp_rand'); |
| 70 | delete_option('wpp_transients'); |
| 71 | delete_option('wpp_performance_nag'); |
| 72 | |
| 73 | // Delete WPP's DB tables |
| 74 | $prefix = $wpdb->prefix . "popularposts"; |
| 75 | $wpdb->query("DROP TABLE IF EXISTS {$prefix}data;"); |
| 76 | $wpdb->query("DROP TABLE IF EXISTS {$prefix}datacache;"); |
| 77 | $wpdb->query("DROP TABLE IF EXISTS {$prefix}datacache_backup;"); |
| 78 | $wpdb->query("DROP TABLE IF EXISTS {$prefix}log;"); |
| 79 | $wpdb->query("DROP TABLE IF EXISTS {$prefix}summary;"); |
| 80 | } |
| 81 |