#44884 closed defect (bug) (duplicate)
Notice something like "Notice: Constant WP_UNINSTALL_PLUGIN already defined in testsite\wp-admin\includes\plugin.php on line 1016" appears when try to delete multiple plugins by "delete_plugins()" function
Reported by: | pmbaldha | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.7 |
Component: | Plugins | Keywords: | needs-testing has-patch |
Focuses: | administration | Cc: |
Description
When i try to uninstall multiple plugins, I am getting warning like "Notice: Constant WP_UNINSTALL_PLUGIN already defined in testsite\wp-admin\includes\plugin.php on line 1016".
To demonstrate this issue i have developed testcode.
Issue reproduce steps:
- Please ensure that debug mode is on in your WordPress setup by ensuring below constant is on root/wp-config.php file:
<?php define('WP_DEBUG', true);
- Install these plugins: Contact Form 7, Gutenberg, Jetpack by WordPress.com, WooCommerce and Yoast SEO
- Please make new file as wp-content/mu-plugins/test.php and pate below code in it:
<?php add_action('admin_init', function() { if (isset($_GET['t']) && 1 == $_GET['t']) { $uninstallable_plugins = array( 'contact-form-7/wp-contact-form-7.php', 'gutenberg/gutenberg.php', 'jetpack/jetpack.php', 'woocommerce/woocommerce.php', 'wordpress-seo/wp-seo.php', ); var_dump(delete_plugins($uninstallable_plugins)); die; } });
- Open browser and open the address "yoursite.com/wp-admin/?t=1" and you will see error
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
There are two possible mechanisms for plugin uninstallation:
The problem is that when using the uninstall.php file the developers are expected to do check for the 'WP_UNINSTALL_PLUGIN' constant, before executing any uninstallation logic.
When calling function uninstall_plugin multiple times in order to batch deinstall plugins, it will try to set WP_UNINSTALL_PLUGIN multiple times with different values (the plugin base name) and that's why PHP complains with notice.
Since the plugins are supposed to check for the constant existence, not for it's value, it seems to be safe to just set it to more generic value (such as boolean TRUE instead of plugin name of currently uninstalled plugin) and check if it is already defined.
Patch attached.