wp-smushit
Last commit date
_src
6 years ago
app
6 years ago
core
6 years ago
languages
6 years ago
readme.txt
6 years ago
uninstall.php
6 years ago
wp-smush.php
6 years ago
uninstall.php
173 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Remove plugin settings data. |
| 4 | * |
| 5 | * @since 1.7 |
| 6 | * @package Smush |
| 7 | */ |
| 8 | |
| 9 | use Smush\Core\Settings; |
| 10 | |
| 11 | // If uninstall not called from WordPress exit. |
| 12 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 13 | exit(); |
| 14 | } |
| 15 | |
| 16 | if ( ! class_exists( '\\Smush\\Core\\Settings' ) ) { |
| 17 | if ( ! defined( 'WP_SMUSH_PREFIX' ) ) { |
| 18 | define( 'WP_SMUSH_PREFIX', 'wp-smush-' ); |
| 19 | } |
| 20 | /* @noinspection PhpIncludeInspection */ |
| 21 | include_once plugin_dir_path( __FILE__ ) . '/core/class-settings.php'; |
| 22 | } |
| 23 | $keep_data = Settings::get_instance()->get( 'keep_data' ); |
| 24 | |
| 25 | // Check if someone want to keep the stats and settings. |
| 26 | if ( ( defined( 'WP_SMUSH_PRESERVE_STATS' ) && WP_SMUSH_PRESERVE_STATS ) || true === $keep_data ) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | global $wpdb; |
| 31 | |
| 32 | $smushit_keys = array( |
| 33 | 'resmush-list', |
| 34 | 'nextgen-resmush-list', |
| 35 | 'resize_sizes', |
| 36 | 'transparent_png', |
| 37 | 'image_sizes', |
| 38 | 'super_smushed', |
| 39 | 'super_smushed_nextgen', |
| 40 | 'settings_updated', |
| 41 | 'hide_smush_welcome', |
| 42 | 'hide_upgrade_notice', |
| 43 | 'hide_update_info', |
| 44 | 'install-type', |
| 45 | 'version', |
| 46 | 'scan', |
| 47 | 'settings', |
| 48 | 'cdn_status', |
| 49 | 'lazy_load', |
| 50 | 'last_run_sync', |
| 51 | 'networkwide', |
| 52 | ); |
| 53 | |
| 54 | $db_keys = array( |
| 55 | 'skip-smush-setup', |
| 56 | 'smush_global_stats', |
| 57 | 'smush-directory-path-hash-updated', |
| 58 | ); |
| 59 | |
| 60 | // Cache Keys. |
| 61 | $cache_keys = array( |
| 62 | 'smush_global_stats', |
| 63 | ); |
| 64 | |
| 65 | $cache_smush_group = array( |
| 66 | 'exceeding_items', |
| 67 | 'wp-smush-resize_savings', |
| 68 | 'pngjpg_savings', |
| 69 | ); |
| 70 | |
| 71 | $cache_nextgen_group = array( |
| 72 | 'wp_smush_images', |
| 73 | 'wp_smush_images_smushed', |
| 74 | 'wp_smush_images_unsmushed', |
| 75 | 'wp_smush_stats_nextgen', |
| 76 | ); |
| 77 | |
| 78 | if ( ! is_multisite() ) { |
| 79 | // Delete Options. |
| 80 | foreach ( $smushit_keys as $key ) { |
| 81 | $key = 'wp-smush-' . $key; |
| 82 | delete_option( $key ); |
| 83 | delete_site_option( $key ); |
| 84 | } |
| 85 | |
| 86 | foreach ( $db_keys as $key ) { |
| 87 | delete_option( $key ); |
| 88 | delete_site_option( $key ); |
| 89 | } |
| 90 | |
| 91 | // Delete Cache data. |
| 92 | foreach ( $cache_keys as $key ) { |
| 93 | wp_cache_delete( $key ); |
| 94 | } |
| 95 | |
| 96 | foreach ( $cache_smush_group as $s_key ) { |
| 97 | wp_cache_delete( $s_key, 'smush' ); |
| 98 | } |
| 99 | |
| 100 | foreach ( $cache_nextgen_group as $n_key ) { |
| 101 | wp_cache_delete( $n_key, 'nextgen' ); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // Delete Directory Smush stats. |
| 106 | delete_option( 'dir_smush_stats' ); |
| 107 | delete_option( 'wp_smush_scan' ); |
| 108 | delete_option( 'wp_smush_api_auth' ); |
| 109 | delete_site_option( 'wp_smush_api_auth' ); |
| 110 | |
| 111 | // Delete Post meta. |
| 112 | $meta_type = 'post'; |
| 113 | $meta_key = 'wp-smpro-smush-data'; |
| 114 | $meta_value = ''; |
| 115 | $delete_all = true; |
| 116 | |
| 117 | if ( is_multisite() ) { |
| 118 | $offset = 0; |
| 119 | $limit = 100; |
| 120 | while ( $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} LIMIT $offset, $limit", ARRAY_A ) ) { |
| 121 | if ( $blogs ) { |
| 122 | foreach ( $blogs as $blog ) { |
| 123 | switch_to_blog( $blog['blog_id'] ); |
| 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 | foreach ( $smushit_keys as $key ) { |
| 131 | $key = 'wp-smush-' . $key; |
| 132 | delete_option( $key ); |
| 133 | delete_site_option( $key ); |
| 134 | } |
| 135 | |
| 136 | foreach ( $db_keys as $key ) { |
| 137 | delete_option( $key ); |
| 138 | delete_site_option( $key ); |
| 139 | } |
| 140 | |
| 141 | // Delete Cache data. |
| 142 | foreach ( $cache_keys as $key ) { |
| 143 | wp_cache_delete( $key ); |
| 144 | } |
| 145 | |
| 146 | foreach ( $cache_smush_group as $s_key ) { |
| 147 | wp_cache_delete( $s_key, 'smush' ); |
| 148 | } |
| 149 | |
| 150 | foreach ( $cache_nextgen_group as $n_key ) { |
| 151 | wp_cache_delete( $n_key, 'nextgen' ); |
| 152 | } |
| 153 | } |
| 154 | restore_current_blog(); |
| 155 | } |
| 156 | $offset += $limit; |
| 157 | } |
| 158 | } else { |
| 159 | delete_metadata( $meta_type, null, $meta_key, $meta_value, $delete_all ); |
| 160 | delete_metadata( $meta_type, null, 'wp-smush-lossy', '', $delete_all ); |
| 161 | delete_metadata( $meta_type, null, 'wp-smush-resize_savings', '', $delete_all ); |
| 162 | delete_metadata( $meta_type, null, 'wp-smush-original_file', '', $delete_all ); |
| 163 | delete_metadata( $meta_type, null, 'wp-smush-pngjpg_savings', '', $delete_all ); |
| 164 | } |
| 165 | // Delete Directory smush table. |
| 166 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}smush_dir_images" ); |
| 167 | |
| 168 | // Delete directory scan data. |
| 169 | delete_option( 'wp-smush-scan-step' ); |
| 170 | |
| 171 | // TODO: Add procedure to delete backup files |
| 172 | // TODO: Update NextGen Metadata to remove Smush stats on plugin deletion. |
| 173 |