WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 13 months 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 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.8
Component: Plugins Keywords: needs-testing has-patch
Focuses: administration Cc:
PR Number:

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 13 months ago.

Download all attachments as: .zip

Change History (3)

#1 @mukesh27
14 months ago

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

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