Created
December 28, 2025 20:26
-
-
Save stingray82/32d5733e43c681b6cb5fa8a2fb38500f to your computer and use it in GitHub Desktop.
Devkit - Alternative delete_plugins() - This allows additional protected plugins using a filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function delete_plugins() { | |
| require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| // Plugin basenames you NEVER want to delete | |
| $protected = array( | |
| DPDEV_BASE, // devkit itself | |
| ); | |
| // Let other code add more protected plugins | |
| $protected = apply_filters('devkit_deleteplugin_exceptions', $protected); | |
| // 1) Deactivate active plugins except protected ones | |
| $active_plugins = get_option('active_plugins', array()); | |
| // Remove all protected plugins from deactivation list | |
| $active_plugins = array_values(array_diff($active_plugins, $protected)); | |
| if (!empty($active_plugins)) { | |
| deactivate_plugins($active_plugins, true); | |
| } | |
| // 2) Get all plugins, remove protected ones, delete the rest | |
| $plugins = get_plugins(); | |
| foreach ($protected as $p) { | |
| unset($plugins[$p]); | |
| } | |
| if (!empty($plugins)) { | |
| delete_plugins(array_keys($plugins)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter('devkit_deleteplugin_exceptions', function($protected) { | |
| $protected[] = 'ninja-updater/ninja-updater.php'; | |
| return $protected; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment