| @@ -7,81 +7,15 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | namespace Code_Snippets; |
| 10 | 10 | |
| 11 | -/* Ensure this plugin is actually being uninstalled */ | |
| 12 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | |
| 11 | +use Code_Snippets\Core\Uninstaller; | |
| 12 | + | |
| 13 | +// Ensure this plugin is actually being uninstalled. | |
| 14 | +if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) || ( defined( 'CODE_SNIPPETS_PRO' ) && CODE_SNIPPETS_PRO ) ) { | |
| 13 | 15 | return; |
| 14 | 16 | } |
| 15 | 17 | |
| 16 | -/** | |
| 17 | - * Determine whether the option for allowing a complete uninstallation is enabled. | |
| 18 | - * | |
| 19 | - * @return boolean | |
| 20 | - */ | |
| 21 | -function complete_uninstall_enabled() { | |
| 22 | - $unified = false; | |
| 18 | +require_once __DIR__ . '/php/Core/Uninstaller.php'; | |
| 23 | 19 | |
| 24 | - if ( is_multisite() ) { | |
| 25 | - $menu_perms = get_site_option( 'menu_items', array() ); | |
| 26 | - $unified = empty( $menu_perms['snippets_settings'] ); | |
| 27 | - } | |
| 28 | - | |
| 29 | - $settings = $unified ? get_site_option( 'code_snippets_settings' ) : get_option( 'code_snippets_settings' ); | |
| 30 | - | |
| 31 | - return isset( $settings['general']['complete_uninstall'] ) && $settings['general']['complete_uninstall']; | |
| 32 | -} | |
| 33 | - | |
| 34 | -/** | |
| 35 | - * Clean up data created by this plugin for a single site | |
| 36 | - * | |
| 37 | - * @phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange | |
| 38 | - * @phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 39 | - */ | |
| 40 | -function uninstall_current_site() { | |
| 41 | - global $wpdb; | |
| 42 | - | |
| 43 | - $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}snippets" ); | |
| 44 | - | |
| 45 | - delete_option( 'code_snippets_version' ); | |
| 46 | - delete_option( 'recently_activated_snippets' ); | |
| 47 | - delete_option( 'code_snippets_settings' ); | |
| 48 | -} | |
| 49 | - | |
| 50 | -/** | |
| 51 | - * Clean up data created by this plugin on multisite. | |
| 52 | - * | |
| 53 | - * @phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange | |
| 54 | - * @phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 55 | - */ | |
| 56 | -function uninstall_multisite() { | |
| 57 | - global $wpdb; | |
| 58 | - | |
| 59 | - /* Loop through sites */ | |
| 60 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ); | |
| 61 | - | |
| 62 | - if ( $blog_ids ) { | |
| 63 | - | |
| 64 | - foreach ( $blog_ids as $site_id ) { | |
| 65 | - switch_to_blog( $site_id ); | |
| 66 | - uninstall_current_site(); | |
| 67 | - } | |
| 68 | - | |
| 69 | - restore_current_blog(); | |
| 70 | - } | |
| 71 | - | |
| 72 | - /* Remove multisite snippets database table */ | |
| 73 | - $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ms_snippets" ); | |
| 74 | - | |
| 75 | - /* Remove saved options */ | |
| 76 | - delete_site_option( 'code_snippets_version' ); | |
| 77 | - delete_site_option( 'recently_activated_snippets' ); | |
| 78 | -} | |
| 79 | - | |
| 80 | -if ( complete_uninstall_enabled() ) { | |
| 81 | - | |
| 82 | - if ( is_multisite() ) { | |
| 83 | - uninstall_multisite(); | |
| 84 | - } else { | |
| 85 | - uninstall_current_site(); | |
| 86 | - } | |
| 87 | -} | |
| 20 | +$uninstaller = new Uninstaller(); | |
| 21 | +$uninstaller->uninstall_plugin(); | |