<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CreativityJuice &#187; debugging</title>
	<atom:link href="http://www.creativityjuice.com/tag/debugger/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.creativityjuice.com</link>
	<description>Donnez du jus à votre communication web !</description>
	<lastBuildDate>Tue, 08 Oct 2013 07:27:52 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.7.41</generator>
	<item>
		<title>WordPress plugins activation issue</title>
		<link>http://www.creativityjuice.com/en/blog/probleme-dactivation-de-plugins-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=probleme-dactivation-de-plugins-wordpress</link>
		<comments>http://www.creativityjuice.com/en/blog/probleme-dactivation-de-plugins-wordpress/#comments</comments>
		<pubDate>Thu, 08 Nov 2012 10:23:31 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[plugins development]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.creativityjuice.com/?p=618</guid>
		<description><![CDATA[How to debug warnings from the activation of your WordPress plugins using output buffering]]></description>
				<content:encoded><![CDATA[<p>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.<span id="more-618"></span> It&#8217;s a bit ugly and we should not distribute that plugin like that.</p>
<p><a href="http://www.creativityjuice.com/wp-content/uploads/2012/11/WordPress_plugin_activation_issue.jpg"><img class="alignnone size-full wp-image-643 colorbox-618" title="WordPress plugin activation issue" src="http://www.creativityjuice.com/wp-content/uploads/2012/11/WordPress_plugin_activation_issue.jpg" alt="WordPress plugin activation issue" width="1432" height="401" /></a></p>
<h2>Where does it come from ?</h2>
<p>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 <a title="xDebug" href="http://xdebug.org/" target="_blank">xDebug</a>.</p>
<h2>How to deal with that ?</h2>
<p>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&#8217;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.</p>
<h2>How to access to these characters ?</h2>
<p>Well, we are gonna play with output buffering. What&#8217;s that ? It&#8217;s exactly how it sounds, it buffers the characters that were meant to be display on the output. We will use two php functions <a title="ob_start" href="http://www.php.net/manual/en/function.ob-start.php" target="_blank">ob_start</a> and <a title="ob_get_contents" href="http://www.php.net/manual/en/function.ob-get-contents.php" target="_blank">ob_get_contents</a>. The first one starts to buffer the data, while the second one just gets what&#8217;s inside this buffer.</p>
<p>So it&#8217;s gonna look like that:</p>
<p>
<pre class="brush: php; title: ; notranslate">&lt;/p&gt;
&lt;p&gt;register_activation_hook(__FILE__,'myplugin_activate');&lt;/p&gt;
&lt;p&gt;function myplugin_activate(){&lt;/p&gt;
&lt;p&gt;ob_start();&lt;/p&gt;
&lt;p&gt;// Here your plugin activation code&lt;/p&gt;
&lt;p&gt;$contents = ob_get_contents();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;</pre>
</p>
<p>For getting <em>$contents</em>, I let choose: set a breakpoint and debug with your favorite tool, a little <a title="PHP exit" href="http://de3.php.net/manual/en/function.exit.php" target="_blank">exit</a> or even <a title="PHP error log" href="http://de3.php.net/manual/en/function.error-log.php" target="_blank">error_log</a>.</p>
<p>There is a bunch of links that google can give you about output buffering if you want to know more about that.</p>
<p>Have fun with it !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.creativityjuice.com/en/blog/probleme-dactivation-de-plugins-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
