wordpress-popular-posts
Last commit date
admin
8 years ago
includes
8 years ago
languages
8 years ago
public
8 years ago
index.php
8 years ago
readme.txt
8 years ago
uninstall.php
8 years ago
wordpress-popular-posts.php
8 years ago
uninstall.php
93 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Fired when the plugin is uninstalled. |
| 4 | * |
| 5 | * @package WordpressPopularPosts |
| 6 | * @author Hector Cabrera <hcabrerab@gmail.com> |
| 7 | * @license GPL-2.0+ |
| 8 | * @link http://cabrerahector.com |
| 9 | * @copyright 2013 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_site_option( 'wpp_ver' ); |
| 31 | delete_site_option( 'wpp_settings_config' ); |
| 32 | delete_site_option( 'wpp_rand' ); |
| 33 | delete_site_option( 'wpp_transients' ); |
| 34 | |
| 35 | // delete tables |
| 36 | uninstall(); |
| 37 | |
| 38 | // delete thumbnails cache and its directory |
| 39 | delete_thumb_cache(); |
| 40 | |
| 41 | } |
| 42 | |
| 43 | // Switch back to current blog |
| 44 | switch_to_blog( $original_blog_id ); |
| 45 | |
| 46 | } else { |
| 47 | |
| 48 | // Delete plugin's options |
| 49 | delete_option( 'wpp_ver' ); |
| 50 | delete_option( 'wpp_settings_config' ); |
| 51 | delete_option( 'wpp_rand' ); |
| 52 | delete_option( 'wpp_transients' ); |
| 53 | |
| 54 | // delete tables |
| 55 | uninstall(); |
| 56 | |
| 57 | // delete thumbnails cache and its directory |
| 58 | delete_thumb_cache(); |
| 59 | |
| 60 | } |
| 61 | |
| 62 | function delete_thumb_cache() { |
| 63 | $wp_upload_dir = wp_upload_dir(); |
| 64 | |
| 65 | if ( is_dir( $wp_upload_dir['basedir'] . "/wordpress-popular-posts" ) ) { |
| 66 | $files = glob( $wp_upload_dir['basedir'] . "/wordpress-popular-posts/*" ); // get all file names |
| 67 | |
| 68 | if ( is_array($files) && !empty($files) ) { |
| 69 | foreach($files as $file){ // iterate files |
| 70 | if ( is_file($file) ) |
| 71 | @unlink($file); // delete file |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Finally, delete wpp's upload directory |
| 76 | @rmdir( $wp_upload_dir['basedir'] . "/wordpress-popular-posts" ); |
| 77 | |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | function uninstall(){ |
| 82 | |
| 83 | global $wpdb; |
| 84 | |
| 85 | // Delete db tables |
| 86 | $prefix = $wpdb->prefix . "popularposts"; |
| 87 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}data;" ); |
| 88 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}datacache;" ); |
| 89 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}datacache_backup;" ); |
| 90 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}log;" ); |
| 91 | $wpdb->query( "DROP TABLE IF EXISTS {$prefix}summary" ); |
| 92 | |
| 93 | } |