Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#44884 new defect (bug)

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's profile pmbaldha Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.8
Component: Plugins Keywords: needs-testing has-patch
Focuses: administration Cc:


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:
define('WP_DEBUG', true);
  • Install these plugins: Contact Form 7, Gutenberg, Jetpack by, WooCommerce and Yoast SEO
  • Please make new file as wp-content/mu-plugins/test.php and pate below code in it:
add_action('admin_init', function() {

    if (isset($_GET['t']) && 1 == $_GET['t']) {
        $uninstallable_plugins = array(




  • Open browser and open the address "" and you will see error

Attachments (1)

0001-Added-check-for-constant-existence.patch (847 bytes) - added by dontgo2sleep 5 years ago.

Download all attachments as: .zip

Change History (3)

#1 @mukesh27
5 years ago

  • Focuses administration added
  • Keywords needs-patch needs-testing added

#2 @dontgo2sleep
5 years ago

  • Keywords has-patch added; needs-patch removed

There are two possible mechanisms for plugin uninstallation:

  • Calling the pligin's uninstal hook (if defined)
  • Include and execute uninstall.php files located in the base plugin folder.

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.

Note: See TracTickets for help on using tickets.