Reason for Fatal error: Cannot redeclare function when activating plugin in WordPress

When activating a plugin in WordPress you may see a fatal error message that suggests that a function cannot be redeclared even though the plugin code does not redeclare it.

The real problem however is due to a bug in the plugin code that triggers a PHP error. But, WordPress for whatever reason masks this error message by reloading the plugin, hence generating the error message.

This is also the reason for the message that a plugin produced x bytes of unexpected output where WP hides the content of a PHP error message.

To debug plugins, it’s recommended to add the following to your wp-config file: define(‘WP_DEBUG’, true);

This will turn on verbose error reporting. Then you can see which deprecated functions are being used by the plugins and hopefully the cause of any fatal error.

Leave a Reply

Your email address will not be published. Required fields are marked *