PluginProbe
Code Snippets / 3.2.1
Code Snippets v3.2.1
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.2.1, at php/uninstall.php

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