Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-smush...
File: uninstall.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Remove plugin settings data.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 1.7
[4] Fix | Delete
* @package Smush
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
use Smush\Core\Settings;
[8] Fix | Delete
[9] Fix | Delete
// If uninstall not called from WordPress exit.
[10] Fix | Delete
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
[11] Fix | Delete
exit();
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
if ( ! class_exists( '\\Smush\\Core\\Settings' ) ) {
[15] Fix | Delete
if ( ! defined( 'WP_SMUSH_PREFIX' ) ) {
[16] Fix | Delete
define( 'WP_SMUSH_PREFIX', 'wp-smush-' );
[17] Fix | Delete
}
[18] Fix | Delete
/* @noinspection PhpIncludeInspection */
[19] Fix | Delete
include_once plugin_dir_path( __FILE__ ) . '/core/class-settings.php';
[20] Fix | Delete
}
[21] Fix | Delete
$keep_data = Settings::get_instance()->get( 'keep_data' );
[22] Fix | Delete
[23] Fix | Delete
// Check if someone want to keep the stats and settings.
[24] Fix | Delete
if ( ( defined( 'WP_SMUSH_PRESERVE_STATS' ) && WP_SMUSH_PRESERVE_STATS ) || true === $keep_data ) {
[25] Fix | Delete
return;
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
global $wpdb;
[29] Fix | Delete
[30] Fix | Delete
$smushit_keys = array(
[31] Fix | Delete
'resmush-list',
[32] Fix | Delete
'nextgen-resmush-list',
[33] Fix | Delete
'resize_sizes',
[34] Fix | Delete
'transparent_png',
[35] Fix | Delete
'image_sizes',
[36] Fix | Delete
'super_smushed',
[37] Fix | Delete
'super_smushed_nextgen',
[38] Fix | Delete
'settings_updated',
[39] Fix | Delete
'hide_smush_welcome',
[40] Fix | Delete
'hide_upgrade_notice',
[41] Fix | Delete
'hide_update_info',
[42] Fix | Delete
'install-type',
[43] Fix | Delete
'version',
[44] Fix | Delete
'scan',
[45] Fix | Delete
'settings',
[46] Fix | Delete
'cdn_status',
[47] Fix | Delete
'lazy_load',
[48] Fix | Delete
'last_run_sync',
[49] Fix | Delete
'networkwide',
[50] Fix | Delete
'cron_update_running',
[51] Fix | Delete
'hide-conflict-notice',
[52] Fix | Delete
'show_upgrade_modal',
[53] Fix | Delete
// This could have been set in 3.7.1. The UI that set this was removed in 3.7.2.
[54] Fix | Delete
'hide_tutorials_from_bulk_smush',
[55] Fix | Delete
);
[56] Fix | Delete
[57] Fix | Delete
$db_keys = array(
[58] Fix | Delete
'skip-smush-setup',
[59] Fix | Delete
'smush_global_stats',
[60] Fix | Delete
);
[61] Fix | Delete
[62] Fix | Delete
// Cache Keys.
[63] Fix | Delete
$cache_keys = array(
[64] Fix | Delete
'smush_global_stats',
[65] Fix | Delete
);
[66] Fix | Delete
[67] Fix | Delete
$cache_smush_group = array(
[68] Fix | Delete
'exceeding_items',
[69] Fix | Delete
'wp-smush-resize_savings',
[70] Fix | Delete
'pngjpg_savings',
[71] Fix | Delete
);
[72] Fix | Delete
[73] Fix | Delete
$cache_nextgen_group = array(
[74] Fix | Delete
'wp_smush_images',
[75] Fix | Delete
'wp_smush_images_smushed',
[76] Fix | Delete
'wp_smush_images_unsmushed',
[77] Fix | Delete
'wp_smush_stats_nextgen',
[78] Fix | Delete
);
[79] Fix | Delete
[80] Fix | Delete
if ( ! is_multisite() ) {
[81] Fix | Delete
// Delete Options.
[82] Fix | Delete
foreach ( $smushit_keys as $key ) {
[83] Fix | Delete
$key = 'wp-smush-' . $key;
[84] Fix | Delete
delete_option( $key );
[85] Fix | Delete
delete_site_option( $key );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
foreach ( $db_keys as $key ) {
[89] Fix | Delete
delete_option( $key );
[90] Fix | Delete
delete_site_option( $key );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
// Delete Cache data.
[94] Fix | Delete
foreach ( $cache_keys as $key ) {
[95] Fix | Delete
wp_cache_delete( $key );
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
foreach ( $cache_smush_group as $s_key ) {
[99] Fix | Delete
wp_cache_delete( $s_key, 'smush' );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
foreach ( $cache_nextgen_group as $n_key ) {
[103] Fix | Delete
wp_cache_delete( $n_key, 'nextgen' );
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
// Delete Directory Smush stats.
[108] Fix | Delete
delete_option( 'dir_smush_stats' );
[109] Fix | Delete
delete_option( 'wp_smush_scan' );
[110] Fix | Delete
delete_option( 'wp_smush_api_auth' );
[111] Fix | Delete
delete_site_option( 'wp_smush_api_auth' );
[112] Fix | Delete
[113] Fix | Delete
// Delete Post meta.
[114] Fix | Delete
$meta_type = 'post';
[115] Fix | Delete
$meta_key = 'wp-smpro-smush-data';
[116] Fix | Delete
$meta_value = '';
[117] Fix | Delete
$delete_all = true;
[118] Fix | Delete
[119] Fix | Delete
if ( is_multisite() ) {
[120] Fix | Delete
$offset = 0;
[121] Fix | Delete
$limit = 100;
[122] Fix | Delete
while ( $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} LIMIT $offset, $limit", ARRAY_A ) ) {
[123] Fix | Delete
if ( $blogs ) {
[124] Fix | Delete
foreach ( $blogs as $blog ) {
[125] Fix | Delete
switch_to_blog( $blog['blog_id'] );
[126] Fix | Delete
delete_metadata( $meta_type, null, $meta_key, $meta_value, $delete_all );
[127] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-lossy', '', $delete_all );
[128] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-resize_savings', '', $delete_all );
[129] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-original_file', '', $delete_all );
[130] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-pngjpg_savings', '', $delete_all );
[131] Fix | Delete
[132] Fix | Delete
foreach ( $smushit_keys as $key ) {
[133] Fix | Delete
$key = 'wp-smush-' . $key;
[134] Fix | Delete
delete_option( $key );
[135] Fix | Delete
delete_site_option( $key );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
foreach ( $db_keys as $key ) {
[139] Fix | Delete
delete_option( $key );
[140] Fix | Delete
delete_site_option( $key );
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
// Delete Cache data.
[144] Fix | Delete
foreach ( $cache_keys as $key ) {
[145] Fix | Delete
wp_cache_delete( $key );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
foreach ( $cache_smush_group as $s_key ) {
[149] Fix | Delete
wp_cache_delete( $s_key, 'smush' );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
foreach ( $cache_nextgen_group as $n_key ) {
[153] Fix | Delete
wp_cache_delete( $n_key, 'nextgen' );
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
restore_current_blog();
[157] Fix | Delete
}
[158] Fix | Delete
$offset += $limit;
[159] Fix | Delete
}
[160] Fix | Delete
} else {
[161] Fix | Delete
delete_metadata( $meta_type, null, $meta_key, $meta_value, $delete_all );
[162] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-lossy', '', $delete_all );
[163] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-resize_savings', '', $delete_all );
[164] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-original_file', '', $delete_all );
[165] Fix | Delete
delete_metadata( $meta_type, null, 'wp-smush-pngjpg_savings', '', $delete_all );
[166] Fix | Delete
}
[167] Fix | Delete
// Delete Directory smush table.
[168] Fix | Delete
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}smush_dir_images" );
[169] Fix | Delete
[170] Fix | Delete
// Delete directory scan data.
[171] Fix | Delete
delete_option( 'wp-smush-scan-step' );
[172] Fix | Delete
[173] Fix | Delete
// Delete all WebP images.
[174] Fix | Delete
global $wp_filesystem;
[175] Fix | Delete
if ( is_null( $wp_filesystem ) ) {
[176] Fix | Delete
WP_Filesystem();
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
$upload_dir = wp_get_upload_dir();
[180] Fix | Delete
$webp_dir = dirname( $upload_dir['basedir'] ) . '/smush-webp';
[181] Fix | Delete
$wp_filesystem->delete( $webp_dir, true );
[182] Fix | Delete
[183] Fix | Delete
// Delete WebP test image.
[184] Fix | Delete
$webp_img = $upload_dir['basedir'] . '/smush-webp-test.png';
[185] Fix | Delete
$wp_filesystem->delete( $webp_img );
[186] Fix | Delete
[187] Fix | Delete
// TODO: Add procedure to delete backup files
[188] Fix | Delete
// TODO: Update NextGen Metadata to remove Smush stats on plugin deletion.
[189] Fix | Delete
[190] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function