Capturing WordPress Plugin Activation Errors

If you’re developing a plugin and there are any PHP errors/warnings you’ll get a message like this when you activate it:

The plugin generated [x] characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

You don’t actually see what the errors are, though, even if PHP’s display_errors directive is enabled. If you don’t have PHP error logging enabled, you can use Zakir Hossain’s method of capturing and outputting the error. It needs to be placed before you instantiate your class.

I’m surprised there isn’t a more elegant way to handle this, though. You’d think WordPress would show the error if WP_DEBUG is true or something, but I haven’t been able to find any other method for getting it.

Leave a Reply

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