wp-smushit
Last commit date
assets
9 years ago
extras
9 years ago
languages
9 years ago
lib
9 years ago
license.txt
17 years ago
readme.txt
9 years ago
uninstall.php
9 years ago
wp-smush.php
9 years ago
uninstall.php
132 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Remove plugin settings data |
| 4 | * |
| 5 | * @since 1.7 |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | //if uninstall not called from WordPress exit |
| 10 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 11 | exit(); |
| 12 | } |
| 13 | global $wpdb; |
| 14 | |
| 15 | $smushit_keys = array( |
| 16 | 'auto', |
| 17 | 'original', |
| 18 | 'lossy', |
| 19 | 'backup', |
| 20 | 'resize', |
| 21 | 'png_to_jpg', |
| 22 | 'resize-sizes', |
| 23 | 'nextgen', |
| 24 | 'keep_exif', |
| 25 | 'resmush-list', |
| 26 | 'resize_sizes', |
| 27 | 'transparent_png', |
| 28 | 'image_sizes', |
| 29 | 'skip-redirect', |
| 30 | 'nextgen-resmush-list', |
| 31 | 'super_smushed', |
| 32 | 'super_smushed_nextgen', |
| 33 | 'settings_updated', |
| 34 | 'skip-redirect', |
| 35 | 'hide_smush_welcome', |
| 36 | 'hide_upgrade_notice', |
| 37 | 'hide_update_info', |
| 38 | 'install-type', |
| 39 | 'lossy-updated', |
| 40 | 'version' |
| 41 | ); |
| 42 | |
| 43 | //Cache Keys |
| 44 | $cache_keys = array( |
| 45 | 'smush_global_stats', |
| 46 | ); |
| 47 | |
| 48 | $cache_smush_group = array( |
| 49 | 'exceeding_items', |
| 50 | 'wp-smush-resize_savings', |
| 51 | 'pngjpg_savings' |
| 52 | ); |
| 53 | $cache_nextgen_group = array( |
| 54 | 'wp_smush_images', |
| 55 | 'wp_smush_images_smushed', |
| 56 | 'wp_smush_images_unsmushed', |
| 57 | 'wp_smush_stats_nextgen', |
| 58 | |
| 59 | ); |
| 60 | |
| 61 | if ( ! is_multisite() ) { |
| 62 | //Delete Options |
| 63 | foreach ( $smushit_keys as $key ) { |
| 64 | $key = 'wp-smush-' . $key; |
| 65 | delete_option( $key ); |
| 66 | delete_site_option( $key ); |
| 67 | } |
| 68 | //Delete Cache data |
| 69 | foreach ( $cache_keys as $key ) { |
| 70 | wp_cache_delete( $key ); |
| 71 | } |
| 72 | |
| 73 | foreach ( $cache_smush_group as $s_key ) { |
| 74 | wp_cache_delete( $s_key, 'smush' ); |
| 75 | } |
| 76 | |
| 77 | foreach ( $cache_nextgen_group as $n_key ) { |
| 78 | wp_cache_delete( $n_key, 'nextgen' ); |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | //Delete Post meta |
| 84 | $meta_type = 'post'; |
| 85 | $meta_key = 'wp-smpro-smush-data'; |
| 86 | $meta_value = ''; |
| 87 | $delete_all = true; |
| 88 | |
| 89 | if ( is_multisite() ) { |
| 90 | $offset = 0; |
| 91 | $limit = 100; |
| 92 | while ( $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} LIMIT $offset, $limit", ARRAY_A ) ) { |
| 93 | if ( $blogs ) { |
| 94 | foreach ( $blogs as $blog ) { |
| 95 | switch_to_blog( $blog['blog_id'] ); |
| 96 | delete_metadata( $meta_type, null, $meta_key, $meta_value, $delete_all ); |
| 97 | delete_metadata( $meta_type, null, 'wp-smush-lossy', '', $delete_all ); |
| 98 | delete_metadata( $meta_type, null, 'wp-smush-resize_savings', '', $delete_all ); |
| 99 | delete_metadata( $meta_type, null, 'wp-smush-original_file', '', $delete_all ); |
| 100 | delete_metadata( $meta_type, null, 'wp-smush-pngjpg_savings', '', $delete_all ); |
| 101 | foreach ( $smushit_keys as $key ) { |
| 102 | $key = 'wp-smush-' . $key; |
| 103 | delete_option( $key ); |
| 104 | delete_site_option( $key ); |
| 105 | } |
| 106 | //Delete Cache data |
| 107 | foreach ( $cache_keys as $key ) { |
| 108 | wp_cache_delete( $key ); |
| 109 | } |
| 110 | |
| 111 | foreach ( $cache_smush_group as $s_key ) { |
| 112 | wp_cache_delete( $s_key, 'smush' ); |
| 113 | } |
| 114 | |
| 115 | foreach ( $cache_nextgen_group as $n_key ) { |
| 116 | wp_cache_delete( $n_key, 'nextgen' ); |
| 117 | } |
| 118 | } |
| 119 | restore_current_blog(); |
| 120 | } |
| 121 | $offset += $limit; |
| 122 | } |
| 123 | } else { |
| 124 | delete_metadata( $meta_type, null, $meta_key, $meta_value, $delete_all ); |
| 125 | delete_metadata( $meta_type, null, 'wp-smush-lossy', '', $delete_all ); |
| 126 | delete_metadata( $meta_type, null, 'wp-smush-resize_savings', '', $delete_all ); |
| 127 | delete_metadata( $meta_type, null, 'wp-smush-original_file', '', $delete_all ); |
| 128 | delete_metadata( $meta_type, null, 'wp-smush-pngjpg_savings', '', $delete_all ); |
| 129 | } |
| 130 | //@todo: Add procedure to delete backup files |
| 131 | //@todo: Update NextGen Metadata to remove Smush stats on plugin deletion |
| 132 | ?> |