Hide PHP Warnings and Notices from Poorly Written Plugins

Update: Zack Tollman wrote a plugin called Ostrichize that does an even better job of this, so I’ve reverted my version out of my functionality plugin skeleton and will use his in the future. Pro tip: search for existing code before writing new code ;)

* * *

There are a lot of WordPress plugin and theme developers who don’t enable WP_DEBUG, so their code it littered with PHP notices and warnings. It’s a big pet peeve of mine that I’ve ranted about before.

There are some situations where you have to run one of those plugins, though. In those situations, it’s common for developers to disable WP_DEBUG themselves to avoid seeing the errors, but there’s a better way.

You can define an array of plugin/theme slugs that you want to ignore notices from, and then override PHP’s default error handler to check whether the error originated one of those plugins. If it did, the custom error handler ignores it, but if it didn’t then the handler treats it like a normal error.

I’ve added a function to do that to my functionality plugin skeleton if anyone wants to check out the code for it.

Leave a Reply

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