PluginProbe
Code Snippets / 3.6.3
Code Snippets v3.6.3
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 / php / uninstall.php

uninstall.php in Code Snippets 3.6.3, at php/uninstall.php

86 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions for cleaning data when the plugin is uninstalled.
4 *
5 * @package Code_Snippets
6 *
7 * phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
8 */
9
10 namespace Code_Snippets\Uninstall;
11
12 /**
13 * Determine whether the option for allowing a complete uninstallation is enabled.
14 *
15 * @return boolean
16 */
17 function complete_uninstall_enabled(): bool {
18 $unified = false;
19
20 if ( is_multisite() ) {
21 $menu_perms = get_site_option( 'menu_items', array() );
22 $unified = empty( $menu_perms['snippets_settings'] );
23 }
24
25 $settings = $unified ? get_site_option( 'code_snippets_settings' ) : get_option( 'code_snippets_settings' );
26
27 return isset( $settings['general']['complete_uninstall'] ) && $settings['general']['complete_uninstall'];
28 }
29
30 /**
31 * Clean up data created by this plugin for a single site
32 *
33 * phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange
34 */
35 function uninstall_current_site() {
36 global $wpdb;
37
38 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}snippets" );
39
40 delete_option( 'code_snippets_version' );
41 delete_option( 'recently_activated_snippets' );
42 delete_option( 'code_snippets_settings' );
43 }
44
45 /**
46 * Clean up data created by this plugin on multisite.
47 *
48 * phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange
49 */
50 function uninstall_multisite() {
51 global $wpdb;
52
53 // Loop through sites.
54 $blog_ids = get_sites( [ 'fields' => 'ids' ] );
55
56 foreach ( $blog_ids as $site_id ) {
57 switch_to_blog( $site_id );
58 uninstall_current_site();
59 }
60
61 restore_current_blog();
62
63 // Remove network snippets table.
64 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ms_snippets" );
65
66 // Remove saved options.
67 delete_site_option( 'code_snippets_version' );
68 delete_site_option( 'recently_activated_snippets' );
69 }
70
71 /**
72 * Uninstall the Code Snippets plugin.
73 *
74 * @return void
75 */
76 function uninstall_plugin() {
77 if ( complete_uninstall_enabled() ) {
78
79 if ( is_multisite() ) {
80 uninstall_multisite();
81 } else {
82 uninstall_current_site();
83 }
84 }
85 }
86