Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#31515 new defect (bug)

Cannot enable plugins with protected function redeclarations (PHP Fatal Error)

Reported by: brokentone's profile brokentone Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.3
Component: Plugins Keywords:
Focuses: Cc:

Description

I'm working on a codebase where the theme or plugins concurrently declare the same function inside a function_exists() however the original plugin defines the function without a function_exists check. In this situation, all the declarations can live together at runtime, but attempting to activate (or reactivate) the original plugin causes an error.

Since the plugin initialization sandbox occurs after wp is loaded, the other plugins (with their checks) will have filled the function, any additional function declarations will fail. However this is merely an artifact of the initialization system -- as this plugin is being artificially run much later than it will be regularly running.

A usecase -- perhaps you are trying to wean yourself off the Advanced Custom Fields plugin so you've implemented the get_field function in the theme's functions file in a function_exists check. After disabling the ACF plugin, you decided to reenable it to adjust a field. Game over, Fatal Error.

Change History (3)

This ticket was mentioned in Slack in #core by jorbin. View the logs.


9 years ago

#2 @antpb
9 years ago

This seems to be caused by the order that the plugins are tested on activation. The order in testing is different from the order that the plugins are loaded on the page.

#3 @dd32
9 years ago

I have a feeling the correct method here is to conditionally define the functions, ie. put them within a function_exists() check themselves.

Changing the plugin loading order for activation or the error sandbox isn't realistically possible at present IMHO.

Note: See TracTickets for help on using tickets.