Repository navigation
Expand file tree
/
Copy pathuninstall.php
More file actions
53 lines (45 loc) · 1.67 KB
/
Copy pathuninstall.php
File metadata and controls
53 lines (45 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Remove analytics tables when the plugin is deleted.
*
* @package RSFV
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
/**
* Remove analytics data from the current site.
*
* @return void
*/
function rsfv_uninstall_site() {
global $wpdb;
$videos = $wpdb->prefix . 'rsfv_videos';
$stats = $wpdb->prefix . 'rsfv_stats_daily';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Uninstall drops this plugin's analytics tables. Names are prefixed constants.
$wpdb->query( "DROP TABLE IF EXISTS {$videos}" );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Uninstall drops this plugin's analytics tables. Names are prefixed constants.
$wpdb->query( "DROP TABLE IF EXISTS {$stats}" );
delete_option( 'rsfv_analytics_backfill' );
wp_clear_scheduled_hook( 'rsfv_analytics_prune' );
$options = get_option( 'rsfv_options' );
if ( is_array( $options ) ) {
unset( $options['analytics_enabled'], $options['analytics_ignore_editors'], $options['analytics_retention'] );
update_option( 'rsfv_options', $options );
}
}
// Deleting a plugin removes it from the whole network, so every site's data goes with it.
if ( is_multisite() ) {
foreach ( get_sites(
array(
'fields' => 'ids',
'number' => 0,
)
) as $rsfv_site_id ) {
switch_to_blog( (int) $rsfv_site_id );
rsfv_uninstall_site();
restore_current_blog();
}
} else {
rsfv_uninstall_site();
}