# code-snippets/3.0.0/uninstall.php

Code Snippets, version 3.0.0. 88 lines.

- Page: https://pluginprobe.com/plugins/code-snippets/3.0.0/code/uninstall.php
- Raw: https://pluginprobe.com/plugins/code-snippets/3.0.0/raw/uninstall.php
- Modified: 2022-05-14T04:42:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-snippets/3.0.0/code/uninstall.php#L10-L20`.

```php
<?php
/**
 * Cleans up data created by this plugin
 *
 * @package Code_Snippets
 * @since   2.0.0
 */

namespace Code_Snippets;

/* Ensure this plugin is actually being uninstalled */
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
	return;
}

/**
 * Determine whether the option for allowing a complete uninstallation is enabled.
 *
 * @return boolean
 */
function complete_uninstall_enabled() {
	$unified = false;

	if ( is_multisite() ) {
		$menu_perms = get_site_option( 'menu_items', array() );
		$unified = empty( $menu_perms['snippets_settings'] );
	}

	$settings = $unified ? get_site_option( 'code_snippets_settings' ) : get_option( 'code_snippets_settings' );

	return isset( $settings['general']['complete_uninstall'] ) && $settings['general']['complete_uninstall'];
}

/**
 * Clean up data created by this plugin for a single site
 *
 * @phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange
 * @phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
 */
function uninstall_current_site() {
	global $wpdb;

	$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}snippets" );

	delete_option( 'code_snippets_version' );
	delete_option( 'recently_activated_snippets' );
	delete_option( 'code_snippets_settings' );
}

/**
 * Clean up data created by this plugin on multisite.
 *
 * @phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange
 * @phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
 */
function uninstall_multisite() {
	global $wpdb;

	/* Loop through sites */
	$blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );

	if ( $blog_ids ) {

		foreach ( $blog_ids as $site_id ) {
			switch_to_blog( $site_id );
			uninstall_current_site();
		}

		restore_current_blog();
	}

	/* Remove multisite snippets database table */
	$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ms_snippets" );

	/* Remove saved options */
	delete_site_option( 'code_snippets_version' );
	delete_site_option( 'recently_activated_snippets' );
}

if ( complete_uninstall_enabled() ) {

	if ( is_multisite() ) {
		uninstall_multisite();
	} else {
		uninstall_current_site();
	}
}

```
