| 1 |
<?php |
| 2 |
/** |
| 3 |
* Fired when the plugin is uninstalled. |
| 4 |
* |
| 5 |
* Uninstallation steps: |
| 6 |
* + Check if plugin is called correcly |
| 7 |
* + Check if user has the appropriate rights |
| 8 |
* + Drop plugin tables (unless settings indicate not to) |
| 9 |
* + Delete plugin options from $wpdb->options (unless settings indicate not to) |
| 10 |
* |
| 11 |
* For multisite installation steps 3 and 4 are performed for every blog. |
| 12 |
* |
| 13 |
* @package plugin |
| 14 |
* @author Peter Schulz |
| 15 |
* @since 1.0.0 |
| 16 |
*/ |
| 17 |
|
| 18 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 19 |
exit(); |
| 20 |
} |
| 21 |
|
| 22 |
if ( ! current_user_can( 'activate_plugins' ) ) { |
| 23 |
exit(); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Uninstall blog |
| 28 |
* |
| 29 |
* This functions is called when the plugin is uninstalled. The following actions are performed: |
| 30 |
* + Drop plugin tables (unless settings indicate not to) |
| 31 |
* + Delete plugin options from $wpdb->options (unless settings indicate not to) |
| 32 |
* |
| 33 |
* Actions are processed on the current blog and are repeated for every blog on a multisite installation. Must be |
| 34 |
* called from the dashboard (WP_UNINSTALL_PLUGIN defined). User must have the proper privileges (activate_plugins). |
| 35 |
* |
| 36 |
* @author Peter Schulz |
| 37 |
* @since 1.0.0 |
| 38 |
*/ |
| 39 |
function wpda_uninstall_blog() { |
| 40 |
|
| 41 |
global $wpdb; |
| 42 |
|
| 43 |
$drop_tables = get_option( 'wpda_uninstall_tables' ); |
| 44 |
if ( ! $drop_tables || 'on' === $drop_tables ) { |
| 45 |
// Drop repository. |
| 46 |
$wpdb->query( |
| 47 |
" |
| 48 |
DROP TABLE IF EXISTS |
| 49 |
{$wpdb->prefix}wpda_logging |
| 50 |
" |
| 51 |
); // WPCS: unprepared SQL OK; db call ok; no-cache ok. |
| 52 |
$wpdb->query( |
| 53 |
" |
| 54 |
DROP TABLE IF EXISTS |
| 55 |
{$wpdb->prefix}wpda_menu_items |
| 56 |
" |
| 57 |
); // WPCS: unprepared SQL OK; db call ok; no-cache ok. |
| 58 |
$wpdb->query( |
| 59 |
" |
| 60 |
DROP TABLE IF EXISTS |
| 61 |
{$wpdb->prefix}wpda_table_design |
| 62 |
" |
| 63 |
); // WPCS: unprepared SQL OK; db call ok; no-cache ok. |
| 64 |
$wpdb->query( |
| 65 |
" |
| 66 |
DROP TABLE IF EXISTS |
| 67 |
{$wpdb->prefix}wpdp_project |
| 68 |
" |
| 69 |
); // WPCS: unprepared SQL OK; db call ok; no-cache ok. |
| 70 |
$wpdb->query( |
| 71 |
" |
| 72 |
DROP TABLE IF EXISTS |
| 73 |
{$wpdb->prefix}wpdp_page |
| 74 |
" |
| 75 |
); // WPCS: unprepared SQL OK; db call ok; no-cache ok. |
| 76 |
$wpdb->query( |
| 77 |
" |
| 78 |
DROP TABLE IF EXISTS |
| 79 |
{$wpdb->prefix}wpdp_table |
| 80 |
" |
| 81 |
); // WPCS: unprepared SQL OK; db call ok; no-cache ok. |
| 82 |
} |
| 83 |
|
| 84 |
$delete_options = get_option( 'wpda_uninstall_options' ); |
| 85 |
if ( ! $delete_options || 'on' === $delete_options ) { |
| 86 |
// Delete all options from wp_options. |
| 87 |
$wpdb->query( |
| 88 |
" |
| 89 |
DELETE FROM {$wpdb->options} |
| 90 |
WHERE option_name LIKE 'wpda_%' |
| 91 |
" |
| 92 |
); // db call ok; no-cache ok. |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
if ( is_multisite() ) { |
| 98 |
|
| 99 |
global $wpdb; |
| 100 |
|
| 101 |
// Uninstall plugin for alll blogs one by one (will fail silently for blogs having no plugin tables/options). |
| 102 |
$blogids = $wpdb->get_col( "select blog_id from $wpdb->blogs" ); // db call ok; no-cache ok. |
| 103 |
foreach ( $blogids as $blog_id ) { |
| 104 |
|
| 105 |
// Uninstall blog. |
| 106 |
switch_to_blog( $blog_id ); |
| 107 |
wpda_uninstall_blog(); |
| 108 |
restore_current_blog(); |
| 109 |
|
| 110 |
} |
| 111 |
} else { |
| 112 |
|
| 113 |
// Uninstall on single site installation. |
| 114 |
wpda_uninstall_blog(); |
| 115 |
|
| 116 |
} |
| 117 |
|