WordPress plugins activation issue #

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.

WordPress plugin activation issue

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.

So it’s gonna look like that:

<p>function myplugin_activate(){</p>
<p>// Here your plugin activation code</p>
<p>$contents = ob_get_contents();</p>

For getting $contents, I let choose: set a breakpoint and debug with your favorite tool, a little exit or even error_log.

There is a bunch of links that google can give you about output buffering if you want to know more about that.

Have fun with it !

Tags: , ,

Amplify Nature – Biodiversity Profile

Amplify Nature – Biodiversity Profile# 29/09/13 # 1

Chamallow – Press Relations Agency

Chamallow – Press Relations Agency# 01/09/13 # 2

Archireport – Digital Construction Sites Assistant

Archireport – Digital Construction Sites Assistant# 08/04/13 # 3 – High Tech & Video games – High Tech & Video games# 22/01/13 # 4

Yadlavoix – Singing school

Yadlavoix – Singing school# 05/12/12 # 5

Wankin Noodles (band)

Wankin Noodles (band)# 19/11/12 # 6

Suivre mes derniers projets en RSS.