| @@ -1,75 +1,21 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | 3 | * Cleans up data created by this plugin |
| 4 | + * | |
| 5 | 5 | * @package Code_Snippets |
| 6 | - * @since 2.0 | |
| 6 | + * @since 2.0.0 | |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -/* Ensure this plugin is actually being uninstalled */ | |
| 10 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | |
| 11 | - exit(); | |
| 12 | -} | |
| 9 | +namespace Code_Snippets; | |
| 13 | 10 | |
| 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 | -} | |
| 11 | +use Code_Snippets\Core\Uninstaller; | |
| 20 | 12 | |
| 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'] ) { | |
| 13 | +// Ensure this plugin is actually being uninstalled. | |
| 14 | +if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) || ( defined( 'CODE_SNIPPETS_PRO' ) && CODE_SNIPPETS_PRO ) ) { | |
| 25 | 15 | return; |
| 26 | 16 | } |
| 27 | 17 | |
| 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; | |
| 18 | +require_once __DIR__ . '/php/Core/Uninstaller.php'; | |
| 34 | 19 | |
| 35 | - /* Remove snippets database table */ | |
| 36 | - $wpdb->query( "DROP TABLE IF EXISTS $wpdb->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 | -$wpdb->snippets = $wpdb->prefix . 'snippets'; | |
| 48 | -$wpdb->ms_snippets = $wpdb->prefix . 'ms_snippets'; | |
| 49 | - | |
| 50 | -/* Multisite uninstall */ | |
| 51 | - | |
| 52 | -if ( is_multisite() ) { | |
| 53 | - | |
| 54 | - /* Loop through sites */ | |
| 55 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 56 | - | |
| 57 | - if ( $blog_ids ) { | |
| 58 | - | |
| 59 | - foreach ( $blog_ids as $blog_id ) { | |
| 60 | - switch_to_blog( $blog_id ); | |
| 61 | - code_snippets_uninstall_site(); | |
| 62 | - } | |
| 63 | - | |
| 64 | - restore_current_blog(); | |
| 65 | - } | |
| 66 | - | |
| 67 | - /* Remove multisite snippets database table */ | |
| 68 | - $wpdb->query( "DROP TABLE IF EXISTS $wpdb->ms_snippets" ); | |
| 69 | - | |
| 70 | - /* Remove saved options */ | |
| 71 | - delete_site_option( 'code_snippets_version' ); | |
| 72 | - delete_site_option( 'recently_activated_snippets' ); | |
| 73 | -} else { | |
| 74 | - code_snippets_uninstall_site(); | |
| 75 | -} | |
| 20 | +$uninstaller = new Uninstaller(); | |
| 21 | +$uninstaller->uninstall_plugin(); | |