WordPress.org

Make WordPress Core

Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#51556 closed defect (bug) (invalid)

Cannot activate a plugin which overrides pluggable function

Reported by: superpoincare Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords:
Focuses: administration Cc:

Description

Trying to activate a plugin with a function with the same name as in wp-includes/pluggable.php gives a fatal error and doesn't activate it.

This probably happens because during the activation process, the pluggable.php file loads earlier. In a normal loading process, the plugin would load earlier and not give this error.

The same plugin would however activate without any errors if I remove the lines and activate the plugin. The plugin would also run if the lines are added after the activation, either by FTP or using the code editor.

Change History (4)

#1 @garrett-eclipse
14 months ago

  • Keywords close added

Hello @superpoincare with your function are you wrapping it in a function_exists? When overriding pluggable functions it's recommended to do so to avoid the fatal you're running into.

For safety, it is best to always wrap your functions with if ( !function_exists() ), otherwise you will produce fatal errors on plugin activation.

Reference: https://codex.wordpress.org/Pluggable_Functions

I hope that helps overcome the issue, marking as close as this is expected behaviour but leaving open for now incase I misunderstood.

#2 @superpoincare
14 months ago

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

Yes, it works that way, I forgot to mention.

Didn't know it was the expected behaviour.

Closing myself.

#3 @garrett-eclipse
14 months ago

Awesome, thanks for following up @superpoincare

#4 @garrett-eclipse
14 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Version 5.5.1 deleted
Note: See TracTickets for help on using tickets.