| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Cleans up data created by this plugin |
| 5 |
* @package Code_Snippets |
| 6 |
* @since 2.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
/* Ensure this plugin is actually being uninstalled */ |
| 10 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 11 |
exit(); |
| 12 |
} |
| 13 |
|
| 14 |
/* Fetch the Complete Uninstall option from the database settings */ |
| 15 |
$unified = false; |
| 16 |
if ( is_multisite() ) { |
| 17 |
$menu_perms = get_site_option( 'menu_items', array() ); |
| 18 |
$unified = empty( $menu_perms['snippets_settings'] ); |
| 19 |
} |
| 20 |
|
| 21 |
$settings = $unified ? get_site_option( 'code_snippets_settings' ) : get_option( 'code_snippets_settings' ); |
| 22 |
|
| 23 |
/* Short circuit the uninstall cleanup process if the option is not enabled */ |
| 24 |
if ( ! isset( $settings['general']['complete_uninstall'] ) || ! $settings['general']['complete_uninstall'] ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Clean up data created by this plugin for a single site |
| 30 |
* @since 2.0 |
| 31 |
*/ |
| 32 |
function code_snippets_uninstall_site() { |
| 33 |
global $wpdb; |
| 34 |
|
| 35 |
/* Remove snippets database table */ |
| 36 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}snippets" ); |
| 37 |
|
| 38 |
/* Remove saved options */ |
| 39 |
delete_option( 'code_snippets_version' ); |
| 40 |
delete_option( 'recently_activated_snippets' ); |
| 41 |
delete_option( 'code_snippets_settings' ); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
global $wpdb; |
| 46 |
|
| 47 |
/* Multisite uninstall */ |
| 48 |
|
| 49 |
if ( is_multisite() ) { |
| 50 |
|
| 51 |
/* Loop through sites */ |
| 52 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ); |
| 53 |
|
| 54 |
if ( $blog_ids ) { |
| 55 |
|
| 56 |
foreach ( $blog_ids as $blog_id ) { |
| 57 |
switch_to_blog( $blog_id ); |
| 58 |
code_snippets_uninstall_site(); |
| 59 |
} |
| 60 |
|
| 61 |
restore_current_blog(); |
| 62 |
} |
| 63 |
|
| 64 |
/* Remove multisite snippets database table */ |
| 65 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ms_snippets" ); |
| 66 |
|
| 67 |
/* Remove saved options */ |
| 68 |
delete_site_option( 'code_snippets_version' ); |
| 69 |
delete_site_option( 'recently_activated_snippets' ); |
| 70 |
} else { |
| 71 |
code_snippets_uninstall_site(); |
| 72 |
} |
| 73 |
|