backwpup
Last commit date
assets
2 days ago
components
6 days ago
config
6 days ago
inc
6 days ago
languages
2 days ago
pages
6 days ago
parts
6 days ago
src
6 days ago
vendor
2 days ago
views
6 days ago
.htaccess
9 years ago
LICENSE
6 years ago
backwpup.php
2 days ago
changelog.txt
2 days ago
cloud-auth-endpoint.php
2 months ago
readme.txt
2 days ago
uninstall.php
6 days ago
uninstall.php
112 lines
| 1 | <?php |
| 2 | /** |
| 3 | * BackWPup uninstall cleanup. |
| 4 | */ |
| 5 | |
| 6 | // If uninstall not called from WordPress, exit. |
| 7 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 8 | exit(); |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * WordPress database access. |
| 13 | * |
| 14 | * @var wpdb $wpdb |
| 15 | */ |
| 16 | global $wpdb; |
| 17 | |
| 18 | // Only uninstall if no BackWPup Version active. |
| 19 | if ( ! class_exists( \BackWPup::class ) ) { |
| 20 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Base.php'; |
| 21 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Column.php'; |
| 22 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Schema.php'; |
| 23 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Query.php'; |
| 24 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Row.php'; |
| 25 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Table.php'; |
| 26 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Queries/Meta.php'; |
| 27 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Queries/Date.php'; |
| 28 | require_once __DIR__ . '/vendor/berlindb/core/src/Database/Queries/Compare.php'; |
| 29 | require_once __DIR__ . '/src/Common/Database/TableInterface.php'; |
| 30 | require_once __DIR__ . '/src/Common/Database/Tables/AbstractTable.php'; |
| 31 | require_once __DIR__ . '/src/Backup/Database/Tables/Backup.php'; |
| 32 | |
| 33 | $tables = [ |
| 34 | new \WPMedia\BackWPup\Backup\Database\Tables\Backup(), |
| 35 | ]; |
| 36 | backwpup_remove_tables( $tables ); |
| 37 | |
| 38 | // Delete plugin options. |
| 39 | if ( is_multisite() ) { |
| 40 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall cleanup. |
| 41 | $wpdb->query( 'DELETE FROM ' . $wpdb->sitemeta . " WHERE meta_key LIKE '%backwpup_%' " ); |
| 42 | } else { |
| 43 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall cleanup. |
| 44 | $wpdb->query( 'DELETE FROM ' . $wpdb->options . " WHERE option_name LIKE '%backwpup_%' " ); |
| 45 | } |
| 46 | |
| 47 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 48 | $wpdb->query( 'DELETE FROM ' . $wpdb->usermeta . " WHERE meta_key LIKE '%backwpup_%' " ); |
| 49 | |
| 50 | // Delete Backwpup user roles. |
| 51 | // Special handling for multisite when network-activated. |
| 52 | if ( is_multisite() ) { |
| 53 | $sites = get_sites( |
| 54 | [ |
| 55 | 'fields' => 'ids', |
| 56 | ] |
| 57 | ); |
| 58 | $current_site_id = get_current_blog_id(); |
| 59 | |
| 60 | foreach ( $sites as $site ) { |
| 61 | switch_to_blog( $site ); |
| 62 | backwpup_remove_roles(); |
| 63 | backwpup_remove_tables( $tables ); |
| 64 | } |
| 65 | |
| 66 | switch_to_blog( $current_site_id ); |
| 67 | } else { |
| 68 | backwpup_remove_roles(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Removes BackWPup roles and capabilities. |
| 74 | */ |
| 75 | function backwpup_remove_roles() { |
| 76 | remove_role( 'backwpup_admin' ); |
| 77 | remove_role( 'backwpup_helper' ); |
| 78 | remove_role( 'backwpup_check' ); |
| 79 | |
| 80 | // Remove capabilities from the administrator role. |
| 81 | $role = get_role( 'administrator' ); |
| 82 | if ( is_object( $role ) && method_exists( $role, 'remove_cap' ) ) { |
| 83 | $role->remove_cap( 'backwpup' ); |
| 84 | $role->remove_cap( 'backwpup_jobs' ); |
| 85 | $role->remove_cap( 'backwpup_jobs_edit' ); |
| 86 | $role->remove_cap( 'backwpup_jobs_start' ); |
| 87 | $role->remove_cap( 'backwpup_backups' ); |
| 88 | $role->remove_cap( 'backwpup_backups_download' ); |
| 89 | $role->remove_cap( 'backwpup_backups_delete' ); |
| 90 | $role->remove_cap( 'backwpup_logs' ); |
| 91 | $role->remove_cap( 'backwpup_logs_delete' ); |
| 92 | $role->remove_cap( 'backwpup_settings' ); |
| 93 | $role->remove_cap( 'backwpup_restore' ); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Remove available database tables. |
| 99 | * |
| 100 | * @param array $tables Database tables objects. |
| 101 | * |
| 102 | * @return void |
| 103 | */ |
| 104 | function backwpup_remove_tables( $tables ) { |
| 105 | foreach ( $tables as $table ) { |
| 106 | if ( ! $table->exists() ) { |
| 107 | continue; |
| 108 | } |
| 109 | $table->uninstall(); |
| 110 | } |
| 111 | } |
| 112 |