WordPress plugins activation issue# 08/11/12 #

Excerpt: How to debug warnings from the activation of your WordPress plugins using output buffering

If you have tried to develop some plugins for WordPress, you might have faced some warnings while activating it. This is due to some characters sent to the standard output before the header. It’s a bit ugly and we should not distribute that plugin like that.

Where does it come from ?

Most of the time, it is just a matter of warnings sent during the activation of the plugin. For instance, when you set WordPress in debug mode (WP_DEBUG to true) or when you use xDebug.

How to deal with that ?

We set WordPress WP_DEBUG to false, we disable xDebug, and we play with error_reporting flags in our php.ini in order to hide warnings. Ok, I’m joking ! It might maybe be a good idea to fix our warnings. But how to display those warnings, because blind debugging is a pain.

How to access to these characters ?

Well, we are gonna play with output buffering. What’s that ? It’s exactly how it sounds, it buffers the characters that were meant to be display on the output. We will use two php functions ob_start and ob_get_contents. The first one starts to buffer the data, while the second one just gets what’s inside this buffer.