Make WordPress Core

Opened 6 years ago

Closed 4 months ago

Last modified 3 months ago

#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's profile 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

https://photos.app.goo.gl/BHeCDSF4uB2Eh4HNA

Attachments (1)

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

Download all attachments as: .zip

Change History (5)

#1 @mukesh27
6 years ago

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

#2 @dontgo2sleep
6 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.

#3 @kkmuffme
4 months ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #26735.

#4 @desrosj
3 months ago

  • Milestone Awaiting Review deleted
  • Version changed from 4.9.8 to 2.7
Note: See TracTickets for help on using tickets.