PluginProbe
Code Snippets / 3.0.0
Code Snippets v3.0.0
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / trunk / uninstall.php

uninstall.php in Code Snippets 3.0.0, at trunk/uninstall.php

88 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cleans up data created by this plugin
4 *
5 * @package Code_Snippets
6 * @since 2.0.0
7 */
8
9 namespace Code_Snippets;
10
11 /* Ensure this plugin is actually being uninstalled */
12 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
13 return;
14 }
15
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;
23
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 }
88