wp-smushit
Last commit date
_src
2 days ago
app
2 days ago
core
2 days ago
languages
2 days ago
vendor_prefixed
2 days ago
readme.txt
2 days ago
uninstall.php
2 days ago
wp-smush.php
2 days ago
uninstall.php
259 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Remove plugin settings data. |
| 4 | * |
| 5 | * @since 1.7 |
| 6 | * @package Smush |
| 7 | */ |
| 8 | |
| 9 | use Smush\Core\LCP\LCP_Helper; |
| 10 | use Smush\Core\Settings; |
| 11 | |
| 12 | // If uninstall not called from WordPress exit. |
| 13 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 14 | exit(); |
| 15 | } |
| 16 | |
| 17 | if ( ! class_exists( '\\Smush\\Core\\Settings' ) ) { |
| 18 | /* @noinspection PhpIncludeInspection */ |
| 19 | include_once plugin_dir_path( __FILE__ ) . '/core/class-settings.php'; |
| 20 | } |
| 21 | $keep_data = Settings::get_instance()->get( 'keep_data' ); |
| 22 | |
| 23 | // Check if someone want to keep the stats and settings. |
| 24 | if ( ( defined( 'WP_SMUSH_PRESERVE_STATS' ) && WP_SMUSH_PRESERVE_STATS ) || true === $keep_data ) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | global $wpdb; |
| 29 | |
| 30 | $smushit_keys = array( |
| 31 | 'wp-smush-resmush-list', |
| 32 | 'wp-smush-nextgen-resmush-list', |
| 33 | 'wp-smush-resize_sizes', |
| 34 | 'wp-smush-transparent_png', |
| 35 | 'wp-smush-image_sizes', |
| 36 | 'wp-smush-super_smushed', |
| 37 | 'wp-smush-super_smushed_nextgen', |
| 38 | 'wp-smush-settings_updated', |
| 39 | 'wp-smush-hide_update_info', |
| 40 | 'wp-smush-hide_upgrade_notice', |
| 41 | 'wp-smush-hide_s3support_alert', |
| 42 | 'wp-smush-install-type', |
| 43 | 'wp-smush-version', |
| 44 | 'wp-smush-scan', |
| 45 | 'wp-smush-settings', |
| 46 | 'wp-smush-cdn-advanced-settings', |
| 47 | 'wp-smush-cdn_status', |
| 48 | 'wp-smush-lazy_load', |
| 49 | 'wp-smush-preload', |
| 50 | 'wp-smush-last_run_sync', |
| 51 | 'wp-smush-networkwide', |
| 52 | 'wp-smush-cron_update_running', |
| 53 | 'wp-smush-dismissed-notices', |
| 54 | 'wp-smush-show_upgrade_modal', |
| 55 | 'wp-smush-preset_configs', |
| 56 | 'wp-smush-webp_hide_wizard', |
| 57 | 'wp-smush-hide-tutorials', |
| 58 | 'wp-smush-hide_tutorials_from_bulk_smush', // Possible leftover from 3.8.4. |
| 59 | 'wp-smush-png2jpg-rewrite-rules-flushed', |
| 60 | 'wp-smush-optimization-global-stats', |
| 61 | 'wp-smush-resize-global-stats', |
| 62 | 'wp-smush-png2jpg-global-stats', |
| 63 | 'wp_smush_skip_image_sizes_recheck', |
| 64 | 'wp_smush_image_sizes_state', |
| 65 | 'wp_smush_global_stats', |
| 66 | 'wp-smush-optimize-list', |
| 67 | 'wp-smush-reoptimize-list', |
| 68 | 'wp-smush-error-items-list', |
| 69 | 'wp-smush-plugin-activated', |
| 70 | 'wp_smush_run_optimize_on_scan_completed', |
| 71 | 'wp-smush-nextgen-reoptimize-list', |
| 72 | 'wp-smush-nextgen-super-smushed-list', |
| 73 | 'wp-smush-webp-global-stats', |
| 74 | 'wp-smush-avif-global-stats', |
| 75 | 'wp_smush_scan_slice_size', |
| 76 | 'wp_smush_media_library_last_process', |
| 77 | 'wp_smush_public_expected_nonces', |
| 78 | 'wp_smush_expected_public_nonces', |
| 79 | 'wp_smush_expected_nonces', |
| 80 | 'wp_smush_background_pre_flight', |
| 81 | 'wp_smush_background_scan_process_status', |
| 82 | 'wp_smush_bulk_smush_background_process_status', |
| 83 | 'wp_smush_event_times', |
| 84 | 'wp-smush-show-new-feature-hotspot', |
| 85 | 'wp-smush-rating-status', |
| 86 | 'wp-smush-api_message', |
| 87 | 'wp_smush_notifications', |
| 88 | 'wp-smush-directory_first_visit_dismissed', |
| 89 | 'wp-smush-ignored-items-list', |
| 90 | 'wp-smush-animated-items-list', |
| 91 | 'wp_smush_event_data', |
| 92 | 'wp_smush_show_connected_modal', |
| 93 | 'wp_smush_error_counts', |
| 94 | 'wp_smush_pre_3_22_site', |
| 95 | 'wp_smush_pre_3_12_6_site', |
| 96 | 'wp_smush_last_scan_completed', |
| 97 | 'wp_smush_next_gen_previously_active_format_key', |
| 98 | 'smush_deactivated', |
| 99 | 'wp-smush-review_prompt_next_show', |
| 100 | 'wp-smush-dir-settings', |
| 101 | ); |
| 102 | |
| 103 | $db_keys = array( |
| 104 | 'skip-smush-setup', |
| 105 | 'smush_global_stats', |
| 106 | 'wp_smush_stats_nextgen', |
| 107 | ); |
| 108 | |
| 109 | // Cache Keys. |
| 110 | $cache_smush_group = array( |
| 111 | 'exceeding_items', |
| 112 | 'wp-smush-resize_count', |
| 113 | 'wp-smush-resize_savings', |
| 114 | 'wp-smush-pngjpg_savings', |
| 115 | 'wp-smush-smushed_ids', |
| 116 | 'media_attachments', |
| 117 | 'skipped_images', |
| 118 | 'images_with_backups', |
| 119 | 'wp-smush-dir_total_stats', |
| 120 | ); |
| 121 | |
| 122 | $cache_nextgen_group = array( |
| 123 | 'wp_smush_images', |
| 124 | 'wp_smush_images_smushed', |
| 125 | 'wp_smush_images_unsmushed', |
| 126 | 'wp_smush_stats_nextgen', |
| 127 | ); |
| 128 | |
| 129 | if ( ! class_exists( '\Smush\Core\LCP\LCP_Helper' ) ) { |
| 130 | /* @noinspection PhpIncludeInspection */ |
| 131 | $lcp_helper_file_path = plugin_dir_path( __FILE__ ) . '/core/lcp/class-lcp-helper.php'; |
| 132 | if ( file_exists( $lcp_helper_file_path ) ) { |
| 133 | include_once $lcp_helper_file_path; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if ( ! is_multisite() ) { |
| 138 | // Delete Options. |
| 139 | foreach ( $smushit_keys as $key ) { |
| 140 | delete_option( $key ); |
| 141 | } |
| 142 | |
| 143 | foreach ( $db_keys as $key ) { |
| 144 | delete_option( $key ); |
| 145 | } |
| 146 | |
| 147 | // Delete Cache data. |
| 148 | foreach ( $cache_smush_group as $s_key ) { |
| 149 | wp_cache_delete( $s_key, 'wp-smush' ); |
| 150 | } |
| 151 | |
| 152 | foreach ( $cache_nextgen_group as $n_key ) { |
| 153 | wp_cache_delete( $n_key, 'nextgen' ); |
| 154 | } |
| 155 | |
| 156 | wp_cache_delete( 'get_image_sizes', 'smush_image_sizes' ); |
| 157 | |
| 158 | delete_transient( 'wp-smush-conflict_check' ); |
| 159 | |
| 160 | if ( class_exists( '\Smush\Core\LCP\LCP_Helper' ) ) { |
| 161 | LCP_Helper::delete_all_lcp_data(); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Delete Directory Smush stats. |
| 166 | delete_option( 'dir_smush_stats' ); |
| 167 | delete_option( 'wp_smush_scan' ); |
| 168 | delete_option( 'wp_smush_api_auth' ); |
| 169 | delete_site_option( 'wp_smush_api_auth' ); |
| 170 | |
| 171 | // Delete Post meta. |
| 172 | $meta_type = 'post'; |
| 173 | $meta_key = 'wp-smpro-smush-data'; |
| 174 | $meta_value = ''; |
| 175 | $delete_all = true; |
| 176 | |
| 177 | if ( is_multisite() ) { |
| 178 | $blog_pattern_keys = array( |
| 179 | 'wp_smush_background_scan_process_', |
| 180 | 'wp_smush_bulk_smush_background_process_' |
| 181 | ); |
| 182 | |
| 183 | $offset = 0; |
| 184 | $limit = 100; |
| 185 | while ( $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} LIMIT $offset, $limit", ARRAY_A ) ) { |
| 186 | if ( $blogs ) { |
| 187 | foreach ( $blogs as $blog ) { |
| 188 | switch_to_blog( $blog['blog_id'] ); |
| 189 | delete_metadata( $meta_type, null, $meta_key, $meta_value, $delete_all ); |
| 190 | delete_metadata( $meta_type, null, 'wp-smush-lossy', '', $delete_all ); |
| 191 | delete_metadata( $meta_type, null, 'wp-smush-resize_savings', '', $delete_all ); |
| 192 | delete_metadata( $meta_type, null, 'wp-smush-original_file', '', $delete_all ); |
| 193 | delete_metadata( $meta_type, null, 'wp-smush-pngjpg_savings', '', $delete_all ); |
| 194 | delete_metadata( $meta_type, null, 'wp-smush-animated', '', $delete_all ); |
| 195 | delete_metadata( $meta_type, null, 'wp-smush-transparent', '', $delete_all ); |
| 196 | delete_metadata( $meta_type, null, 'wp-smush-ignore-bulk', '', $delete_all ); |
| 197 | |
| 198 | foreach ( $blog_pattern_keys as $pattern ) { |
| 199 | delete_site_option($pattern . $blog['blog_id'] . '_status'); |
| 200 | } |
| 201 | |
| 202 | foreach ( $smushit_keys as $key ) { |
| 203 | delete_option( $key ); |
| 204 | delete_site_option( $key ); |
| 205 | } |
| 206 | |
| 207 | foreach ( $db_keys as $key ) { |
| 208 | delete_option( $key ); |
| 209 | delete_site_option( $key ); |
| 210 | } |
| 211 | |
| 212 | // Delete Cache data. |
| 213 | foreach ( $cache_smush_group as $s_key ) { |
| 214 | wp_cache_delete( $s_key, 'wp-smush' ); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | wp_cache_delete( 'get_image_sizes', 'smush_image_sizes' ); |
| 219 | if ( class_exists( '\Smush\Core\LCP\LCP_Helper' ) ) { |
| 220 | LCP_Helper::delete_all_lcp_data(); |
| 221 | } |
| 222 | } |
| 223 | restore_current_blog(); |
| 224 | } |
| 225 | $offset += $limit; |
| 226 | } |
| 227 | } else { |
| 228 | delete_metadata( $meta_type, null, $meta_key, $meta_value, $delete_all ); |
| 229 | delete_metadata( $meta_type, null, 'wp-smush-lossy', '', $delete_all ); |
| 230 | delete_metadata( $meta_type, null, 'wp-smush-resize_savings', '', $delete_all ); |
| 231 | delete_metadata( $meta_type, null, 'wp-smush-original_file', '', $delete_all ); |
| 232 | delete_metadata( $meta_type, null, 'wp-smush-pngjpg_savings', '', $delete_all ); |
| 233 | delete_metadata( $meta_type, null, 'wp-smush-animated', '', $delete_all ); |
| 234 | delete_metadata( $meta_type, null, 'wp-smush-transparent', '', $delete_all ); |
| 235 | delete_metadata( $meta_type, null, 'wp-smush-ignore-bulk', '', $delete_all ); |
| 236 | } |
| 237 | // Delete Directory smush table. |
| 238 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->base_prefix}smush_dir_images" ); |
| 239 | |
| 240 | // Delete directory scan data. |
| 241 | delete_option( 'wp-smush-scan-step' ); |
| 242 | |
| 243 | // Delete all WebP images. |
| 244 | global $wp_filesystem; |
| 245 | if ( is_null( $wp_filesystem ) ) { |
| 246 | WP_Filesystem(); |
| 247 | } |
| 248 | |
| 249 | $upload_dir = wp_get_upload_dir(); |
| 250 | $webp_dir = dirname( $upload_dir['basedir'] ) . '/smush-webp'; |
| 251 | $wp_filesystem->delete( $webp_dir, true ); |
| 252 | |
| 253 | // Delete WebP test image. |
| 254 | $webp_img = $upload_dir['basedir'] . '/smush-webp-test.png'; |
| 255 | $wp_filesystem->delete( $webp_img ); |
| 256 | |
| 257 | // TODO: Add procedure to delete backup files |
| 258 | // TODO: Update NextGen Metadata to remove Smush stats on plugin deletion. |
| 259 |