| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Fired when the plugin is uninstalled. |
| 5 |
* |
| 6 |
* @link https://swarmify.com/ |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package Swarmify |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
delete_option( 'swarmify_status' ); |
| 17 |
delete_option( 'swarmify_cdn_key' ); |
| 18 |
delete_option( 'swarmify_toggle_youtube' ); |
| 19 |
delete_option( 'swarmify_toggle_youtube_cc' ); |
| 20 |
delete_option( 'swarmify_toggle_layout' ); |
| 21 |
delete_option( 'swarmify_toggle_bgvideo' ); |
| 22 |
delete_option( 'swarmify_theme_button' ); |
| 23 |
delete_option( 'swarmify_toggle_uploadacceleration' ); |
| 24 |
delete_option( 'swarmify_theme_primarycolor' ); |
| 25 |
delete_option( 'swarmify_watermark' ); |
| 26 |
delete_option( 'swarmify_ads_vasturl' ); |
| 27 |
delete_option( 'swarmify_toggle_schema' ); |
| 28 |
delete_option( 'swarmify_default_autoplay' ); |
| 29 |
delete_option( 'swarmify_default_muted' ); |
| 30 |
delete_option( 'swarmify_default_loop' ); |
| 31 |
delete_option( 'swarmify_default_controls' ); |
| 32 |
delete_option( 'swarmify_default_playsinline' ); |
| 33 |
delete_option( 'swarmify_default_responsive' ); |
| 34 |
delete_option( 'swarmify_default_preload' ); // older installs may still carry this row |
| 35 |
delete_option( 'swarmify_toggle_conditional_loading' ); |
| 36 |
delete_option( 'swarmify_toggle_beta_player' ); |
| 37 |
delete_option( 'swarmify_plugin_version' ); |
| 38 |
delete_option( 'smartvideo_version' ); |
| 39 |
delete_option( 'smartvideo_show_player_notice' ); |
| 40 |
delete_option( 'swarmify_toggle_legacy_player' ); |
| 41 |
delete_option( 'swarmify_toggle_facade' ); |
| 42 |
delete_option( 'swarmify_theme_secondarycolor' ); |
| 43 |
delete_option( 'swarmify_theme_glasstint' ); |
| 44 |
delete_option( 'swarmify_theme_cornerradius' ); |
| 45 |
delete_option( 'swarmify_theme_button_radius' ); |
| 46 |
delete_option( 'swarmify_toggle_keyboard' ); |
| 47 |
delete_option( 'swarmify_keyboard_seekstep' ); |
| 48 |
delete_option( 'swarmify_toggle_kb_mute' ); |
| 49 |
delete_option( 'swarmify_toggle_kb_fullscreen' ); |
| 50 |
delete_option( 'swarmify_toggle_kb_numbers' ); |
| 51 |
delete_option( 'swarmify_toggle_kb_captions' ); |
| 52 |
delete_option( 'swarmify_watermark_opacity' ); |
| 53 |
delete_option( 'swarmify_watermark_position' ); |
| 54 |
delete_option( 'swarmify_toggle_ga' ); |
| 55 |
delete_option( 'swarmify_ga_interval' ); |
| 56 |
delete_option( 'swarmify_toggle_lazyload' ); |
| 57 |
delete_transient( 'smartvideo_account_tier' ); |
| 58 |
delete_metadata( 'user', 0, 'smartvideo_player_notice_dismissed', '', true ); |
| 59 |
|
| 60 |
// The activation-redirect transient is stored per user, so match by prefix |
| 61 |
// rather than by name. |
| 62 |
global $wpdb; |
| 63 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_smartvideo_activation_redirect_' ) . '%', $wpdb->esc_like( '_transient_timeout_smartvideo_activation_redirect_' ) . '%' ) ); |
| 64 |
|
| 65 |
// Cached Vimeo thumbnails expire on their own, but there is one row per video. |
| 66 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_sv_vimeo_thumb_' ) . '%', $wpdb->esc_like( '_transient_timeout_sv_vimeo_thumb_' ) . '%' ) ); |
| 67 |
|
| 68 |
delete_post_meta_by_key( '_smartvideo_disabled' ); |
| 69 |
|
| 70 |
wp_clear_scheduled_hook( 'swarmify_cleanup_chunks' ); |
| 71 |
|
| 72 |
// Upload chunks land under wp-content, or in the uploads directory where |
| 73 |
// wp-content is read-only. Each blog has its own uploads directory. |
| 74 |
$sv_chunks_dirs = array( WP_CONTENT_DIR . '/.swarmify-chunks' ); |
| 75 |
|
| 76 |
$sv_add_uploads_chunks_dir = function () use ( &$sv_chunks_dirs ) { |
| 77 |
$uploads = wp_get_upload_dir(); |
| 78 |
if ( empty( $uploads['error'] ) && ! empty( $uploads['basedir'] ) ) { |
| 79 |
$sv_chunks_dirs[] = $uploads['basedir'] . '/.swarmify-chunks'; |
| 80 |
} |
| 81 |
}; |
| 82 |
$sv_add_uploads_chunks_dir(); |
| 83 |
|
| 84 |
// Options and meta are per-site, so repeat the whole cleanup on every site. |
| 85 |
if ( is_multisite() ) { |
| 86 |
$sites = get_sites( array( 'fields' => 'ids', 'number' => 0 ) ); |
| 87 |
foreach ( $sites as $site_id ) { |
| 88 |
switch_to_blog( $site_id ); |
| 89 |
$sv_add_uploads_chunks_dir(); |
| 90 |
|
| 91 |
delete_option( 'swarmify_status' ); |
| 92 |
delete_option( 'swarmify_cdn_key' ); |
| 93 |
delete_option( 'swarmify_toggle_youtube' ); |
| 94 |
delete_option( 'swarmify_toggle_youtube_cc' ); |
| 95 |
delete_option( 'swarmify_toggle_layout' ); |
| 96 |
delete_option( 'swarmify_toggle_bgvideo' ); |
| 97 |
delete_option( 'swarmify_theme_button' ); |
| 98 |
delete_option( 'swarmify_toggle_uploadacceleration' ); |
| 99 |
delete_option( 'swarmify_theme_primarycolor' ); |
| 100 |
delete_option( 'swarmify_watermark' ); |
| 101 |
delete_option( 'swarmify_ads_vasturl' ); |
| 102 |
delete_option( 'swarmify_toggle_schema' ); |
| 103 |
delete_option( 'swarmify_default_autoplay' ); |
| 104 |
delete_option( 'swarmify_default_muted' ); |
| 105 |
delete_option( 'swarmify_default_loop' ); |
| 106 |
delete_option( 'swarmify_default_controls' ); |
| 107 |
delete_option( 'swarmify_default_playsinline' ); |
| 108 |
delete_option( 'swarmify_default_responsive' ); |
| 109 |
delete_option( 'swarmify_toggle_conditional_loading' ); |
| 110 |
delete_option( 'swarmify_default_preload' ); // older installs may still carry this row |
| 111 |
delete_option( 'swarmify_toggle_beta_player' ); |
| 112 |
delete_option( 'swarmify_plugin_version' ); |
| 113 |
delete_option( 'smartvideo_version' ); |
| 114 |
delete_option( 'smartvideo_show_player_notice' ); |
| 115 |
delete_option( 'swarmify_toggle_legacy_player' ); |
| 116 |
delete_option( 'swarmify_toggle_facade' ); |
| 117 |
delete_option( 'swarmify_theme_secondarycolor' ); |
| 118 |
delete_option( 'swarmify_theme_glasstint' ); |
| 119 |
delete_option( 'swarmify_theme_cornerradius' ); |
| 120 |
delete_option( 'swarmify_theme_button_radius' ); |
| 121 |
delete_option( 'swarmify_toggle_keyboard' ); |
| 122 |
delete_option( 'swarmify_keyboard_seekstep' ); |
| 123 |
delete_option( 'swarmify_toggle_kb_mute' ); |
| 124 |
delete_option( 'swarmify_toggle_kb_fullscreen' ); |
| 125 |
delete_option( 'swarmify_toggle_kb_numbers' ); |
| 126 |
delete_option( 'swarmify_toggle_kb_captions' ); |
| 127 |
delete_option( 'swarmify_watermark_opacity' ); |
| 128 |
delete_option( 'swarmify_watermark_position' ); |
| 129 |
delete_option( 'swarmify_toggle_ga' ); |
| 130 |
delete_option( 'swarmify_ga_interval' ); |
| 131 |
delete_option( 'swarmify_toggle_lazyload' ); |
| 132 |
delete_transient( 'smartvideo_account_tier' ); |
| 133 |
|
| 134 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_smartvideo_activation_redirect_' ) . '%', $wpdb->esc_like( '_transient_timeout_smartvideo_activation_redirect_' ) . '%' ) ); |
| 135 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_sv_vimeo_thumb_' ) . '%', $wpdb->esc_like( '_transient_timeout_sv_vimeo_thumb_' ) . '%' ) ); |
| 136 |
delete_post_meta_by_key( '_smartvideo_disabled' ); |
| 137 |
wp_clear_scheduled_hook( 'swarmify_cleanup_chunks' ); |
| 138 |
|
| 139 |
restore_current_blog(); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
// Delete only plain files, so a directory someone else has put subdirectories |
| 144 |
// in survives the rmdir. |
| 145 |
foreach ( array_unique( $sv_chunks_dirs ) as $chunks_dir ) { |
| 146 |
if ( ! is_dir( $chunks_dir ) || is_link( $chunks_dir ) ) { |
| 147 |
continue; |
| 148 |
} |
| 149 |
$entries = @scandir( $chunks_dir ); |
| 150 |
if ( is_array( $entries ) ) { |
| 151 |
foreach ( $entries as $entry ) { |
| 152 |
if ( '.' === $entry || '..' === $entry ) { |
| 153 |
continue; |
| 154 |
} |
| 155 |
$path = $chunks_dir . '/' . $entry; |
| 156 |
if ( is_link( $path ) || is_file( $path ) ) { |
| 157 |
@unlink( $path ); |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
@rmdir( $chunks_dir ); |
| 162 |
} |
| 163 |
|