[wp-trac] [WordPress Trac] #44884: 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

WordPress Trac noreply at wordpress.org
Mon Sep 10 21:48:13 UTC 2018


#44884: 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
-------------------------------------+------------------------------
 Reporter:  pmbaldha                 |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Plugins                  |     Version:  4.9.8
 Severity:  normal                   |  Resolution:
 Keywords:  needs-testing has-patch  |     Focuses:  administration
-------------------------------------+------------------------------
Changes (by dontgo2sleep):

 * keywords:  needs-patch needs-testing => needs-testing has-patch


Comment:

 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44884#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list