wordpress-popular-posts
Last commit date
assets
3 weeks ago
i18n
3 weeks ago
src
3 weeks ago
vendor
2 years ago
LICENSE
5 years ago
index.php
5 years ago
readme.txt
3 weeks ago
uninstall.php
8 months ago
wordpress-popular-posts.php
3 weeks ago
uninstall.php
86 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-2022 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 | $blogs_table = "{$wpdb->blogs}"; |
| 25 | $original_blog_id = get_current_blog_id(); |
| 26 | $blogs_ids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM %i", $blogs_table)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching |
| 27 | |
| 28 | foreach( $blogs_ids as $b_id ) { |
| 29 | switch_to_blog($b_id); |
| 30 | // delete tables and options |
| 31 | wordpress_popular_posts_uninstall(); |
| 32 | // delete thumbnails cache and its directory |
| 33 | wordpress_popular_posts_delete_thumb_cache(); |
| 34 | } |
| 35 | |
| 36 | // Switch back to current blog |
| 37 | switch_to_blog($original_blog_id); |
| 38 | } else { |
| 39 | // delete tables and options |
| 40 | wordpress_popular_posts_uninstall(); |
| 41 | // delete thumbnails cache and its directory |
| 42 | wordpress_popular_posts_delete_thumb_cache(); |
| 43 | } |
| 44 | |
| 45 | function wordpress_popular_posts_delete_thumb_cache() { |
| 46 | $wp_upload_dir = wp_get_upload_dir(); |
| 47 | |
| 48 | if ( is_dir($wp_upload_dir['basedir'] . '/wordpress-popular-posts') ) { |
| 49 | $files = glob($wp_upload_dir['basedir'] . '/wordpress-popular-posts/*'); // get all file names |
| 50 | |
| 51 | if ( is_array($files) && ! empty($files) ) { |
| 52 | foreach( $files as $file ){ // iterate files |
| 53 | if ( is_file($file) ) { |
| 54 | @unlink($file); // delete file |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Finally, delete WPP's upload directory |
| 60 | @rmdir($wp_upload_dir['basedir'] . '/wordpress-popular-posts'); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | function wordpress_popular_posts_uninstall() { |
| 65 | global $wpdb; |
| 66 | |
| 67 | // Delete plugin's options |
| 68 | delete_option('wpp_ver'); |
| 69 | delete_option('wpp_update'); |
| 70 | delete_option('wpp_settings_config'); |
| 71 | delete_option('wpp_rand'); |
| 72 | delete_option('wpp_transients'); |
| 73 | delete_option('wpp_performance_nag'); |
| 74 | |
| 75 | // Delete WPP's DB tables |
| 76 | $prefix = $wpdb->prefix . 'popularposts'; |
| 77 | //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 78 | $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS %i;", "{$prefix}data")); |
| 79 | $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS %i;", "{$prefix}datacache")); |
| 80 | $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS %i;", "{$prefix}datacache_backup")); |
| 81 | $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS %i;", "{$prefix}log")); |
| 82 | $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS %i;", "{$prefix}summary")); |
| 83 | $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS %i;", "{$prefix}transients")); |
| 84 | //phpcs:enable |
| 85 | } |
| 86 |