<?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>The Gippy Pages &#187; Web Design &amp; Development</title>
	<atom:link href="http://top-frog.com/category/web-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://top-frog.com</link>
	<description>Polluting the internet since 2004</description>
	<lastBuildDate>Fri, 27 Jan 2012 05:23:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WordPress TextMate Bundle: Better late than never edition (aka: 3.3)</title>
		<link>http://top-frog.com/2012/01/26/wordpress-textmate-bundle-better-late-than-never-edition-aka-3-3/</link>
		<comments>http://top-frog.com/2012/01/26/wordpress-textmate-bundle-better-late-than-never-edition-aka-3-3/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 05:23:59 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[3.3]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=2135</guid>
		<description><![CDATA[FINALLY! WordPress 3.3 support is up for the TextMate Bundle. This is pretty much an update to the function definitions to add in new functions that were added in WordPress 3.3. I&#8217;ve been out of the WordPress loop for a little while now and I&#8217;m not up to speed to what some of the new [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://top-frog.com/wp-content/uploads/2012/01/late.png" alt="late" title="Google tells me that this is the Japanese character meaning &#039;Late&#039;" width="151" height="151" class="alignright size-full wp-image-2139" />FINALLY! WordPress 3.3 support is up for the <a href="http://top-frog.com/projects/wordpress-textmate-bundle/">TextMate Bundle</a>. This is pretty much an update to the function definitions to add in new functions that were added in WordPress 3.3. </p>
<p>I&#8217;ve been out of the WordPress loop for a little while now and I&#8217;m not up to speed to what some of the new developer oriented hotness is that could be added to the bundle so if you&#8217;re looking for something in particular drop a comment here or open an <a href="https://github.com/Gipetto/wordpress.tmbundle/issues">issue on GitHub</a>.</p>
<p>If you&#8217;re so inclined go ahead and Fork it, update what you need and submit a pull request. Since I don&#8217;t work with WordPress on a regular basis there are going to be those of you out there that have a better grasp than I on what should be added, or even what should be removed, from the Bundle.</p>
<p>So, my apologies for the delay with the update. I&#8217;ll try not to let it happen again.</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2012/01/26/wordpress-textmate-bundle-better-late-than-never-edition-aka-3-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Bundle now works with The TextMate 2 Alpha</title>
		<link>http://top-frog.com/2012/01/06/wordpress-bundle-now-works-with-the-textmate-2-alpha/</link>
		<comments>http://top-frog.com/2012/01/06/wordpress-bundle-now-works-with-the-textmate-2-alpha/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 06:47:12 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[TextMate]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[alpha]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[textmate2]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=2104</guid>
		<description><![CDATA[The WordPress TextMate bundle now works just fine with the TextMate 2 Alpha. It was easier than I thought it would be. It boiled down to some environment variables changing a little bit. No biggie. So, there it is. TextMate 2 Alpha support. If you notice anything weird please open a Support Ticket on GitHub. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://top-frog.com/wp-content/uploads/2012/01/TextMate2.png" alt="TextMate 2 Icon" title="I love this icon!" width="128" height="128" class="alignright size-full wp-image-2106" />The WordPress TextMate bundle now works just fine with the TextMate 2 Alpha. It was easier than I thought it would be. It boiled down to some environment variables changing a little bit. No biggie.</p>
<p>So, there it is. TextMate 2 Alpha support. If you notice anything weird please open a <a href="https://github.com/Gipetto/wordpress.tmbundle/issues">Support Ticket on GitHub</a>. Please include the full text of the error that you receive as that&#8217;ll most likely be what I need to fix the problem.</p>
<p>WordPress 3.3 support is hot on its heels. Really!</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2012/01/06/wordpress-bundle-now-works-with-the-textmate-2-alpha/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TextMate 2 and the WordPress Bundle</title>
		<link>http://top-frog.com/2011/12/13/textmate-2-and-the-wordpress-bundle/</link>
		<comments>http://top-frog.com/2011/12/13/textmate-2-and-the-wordpress-bundle/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 05:17:27 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[alpha]]></category>
		<category><![CDATA[awesomesauce]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[textmate 2]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=2094</guid>
		<description><![CDATA[We&#8217;re all excited to see that TextMate 2 Alpha has been released. It was a long wait but by the looks of the Alpha it appears that the wait wasn&#8217;t wasted. There&#8217;s plenty to be happy about with the Alpha. I&#8217;ve been doing some cursory testing with the WordPress Bundle and so far it appears [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re all excited to see that <a href="http://blog.macromates.com/2011/textmate-2-0-alpha/">TextMate 2 Alpha has been released</a>. It was a long wait but by the looks of the Alpha it appears that the wait wasn&#8217;t wasted. There&#8217;s plenty to be happy about with the Alpha.</p>
<p>I&#8217;ve been doing some cursory testing with the WordPress Bundle and so far it appears that only a few minor modifications might be needed to be compatible. </p>
<p>Better yet, though I haven&#8217;t fully tested this yet, the changes should be backwards compatible with TextMate 1.5. For the time being it doesn&#8217;t appear as thought I&#8217;ll have to create a branch just for TextMate 2.</p>
<p>So, keeping in mind that TM2 is Alpha, I&#8217;m pleased with how things are panning out. I&#8217;m eager to get in to the guts the new bundles and figure out what more I can do to make the WordPress bundle even better (suggestions are welcome!).</p>
<p>Congratulations to Mr. Odgaard on his release. I hope he&#8217;s able to ignore the petty jerks who keep harassing him and finish up what already looks to be a kick-ass upgrade.</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2011/12/13/textmate-2-and-the-wordpress-bundle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A few PHP Dev Helper functions</title>
		<link>http://top-frog.com/2011/09/27/a-few-php-dev-helper-functions/</link>
		<comments>http://top-frog.com/2011/09/27/a-few-php-dev-helper-functions/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 06:51:47 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[commit]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[error_log]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[print_r]]></category>
		<category><![CDATA[var_dump]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=2059</guid>
		<description><![CDATA[I&#8217;ve come to be pretty reliant on a few little dev helper functions that I&#8217;ve written that help introspect data in a couple of different output methods. A lot of development, especially development with unfamiliar systems, involves looking at objects and their contents. These helpers are designed to help give consistently formatted output no matter [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve come to be pretty reliant on a few little dev helper functions that I&#8217;ve written that help introspect data in a couple of different output methods. A lot of development, especially development with unfamiliar systems, involves looking at objects and their contents. </p>
<p>These helpers are designed to help give consistently formatted output no matter where they&#8217;re used. They output specific styling inline to override the current site&#8217;s style sheets and output readable, monospace formatted code in most scenarios.</p>
<p><span id="more-2059"></span></p>
<p>The <code>pp()</code> &#038; <code>dp()</code> functions output to screen and the <code>ep()</code> function outputs to the error log.</p>
<p><div class="hl-wrapper"><div class="hl-main"><ol class="hl-main"><li>&nbsp;<span class="hl-inlinetags">&lt;?php</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">pp</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-var">$msg</span><span class="hl-code"> = </span><span class="hl-identifier">__v_build_message</span><span class="hl-brackets">(</span><span class="hl-identifier">func_get_args</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;pre style=&quot;white-space: pre-wrap; text-align: left; </span><span class="hl-quotes">'</span><span class="hl-code">.</span></li>
<li><span class="hl-code">&nbsp;        </span><span class="hl-quotes">'</span><span class="hl-string">font: normal normal 11px/1.4 menlo, monaco, monospaced; </span><span class="hl-quotes">'</span><span class="hl-code">.</span></li>
<li><span class="hl-code">&nbsp;        </span><span class="hl-quotes">'</span><span class="hl-string">background: white; color: black; padding: 5px;&quot;&gt;</span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$msg</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string">&lt;/pre&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">dp</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-var">$msg</span><span class="hl-code"> = </span><span class="hl-identifier">__v_build_message</span><span class="hl-brackets">(</span><span class="hl-identifier">func_get_args</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">var_dump</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;pre style=&quot;white-space: pre-wrap; text-align: left; </span><span class="hl-quotes">'</span><span class="hl-code">.</span></li>
<li><span class="hl-code">&nbsp;        </span><span class="hl-quotes">'</span><span class="hl-string">font: normal normal 11px/1.4 menlo, monaco, monospaced; </span><span class="hl-quotes">'</span><span class="hl-code">.</span></li>
<li><span class="hl-code">&nbsp;        </span><span class="hl-quotes">'</span><span class="hl-string">background: white; color: black; padding: 5px;&quot;&gt;</span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$msg</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string">&lt;/pre&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">ep</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-var">$msg</span><span class="hl-code"> = </span><span class="hl-identifier">__v_build_message</span><span class="hl-brackets">(</span><span class="hl-identifier">func_get_args</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-identifier">error_log</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">**: </span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$msg</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">__v_build_message</span><span class="hl-brackets">(</span><span class="hl-var">$vars</span><span class="hl-code">, </span><span class="hl-var">$func</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">print_r</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-var">$sep</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">, </span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-var">$msgs</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code">!</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$vars</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;        </span><span class="hl-reserved">foreach</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$vars</span><span class="hl-code"> </span><span class="hl-reserved">as</span><span class="hl-code"> </span><span class="hl-var">$var</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;            </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">is_bool</span><span class="hl-brackets">(</span><span class="hl-var">$var</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;                </span><span class="hl-var">$msgs</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-var">$var</span><span class="hl-code"> ? </span><span class="hl-quotes">'</span><span class="hl-string">true</span><span class="hl-quotes">'</span><span class="hl-code"> : </span><span class="hl-quotes">'</span><span class="hl-string">false</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;            </span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;            </span><span class="hl-reserved">elseif</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">is_scalar</span><span class="hl-brackets">(</span><span class="hl-var">$var</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;                </span><span class="hl-var">$msgs</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-var">$var</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;            </span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;            </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;                </span><span class="hl-reserved">switch</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$func</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;                    </span><span class="hl-reserved">case</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">print_r</span><span class="hl-quotes">'</span><span class="hl-code">:</span></li>
<li><span class="hl-code">&nbsp;                    </span><span class="hl-reserved">case</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">var_export</span><span class="hl-quotes">'</span><span class="hl-code">:</span></li>
<li><span class="hl-code">&nbsp;                        </span><span class="hl-var">$msgs</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-var">$func</span><span class="hl-brackets">(</span><span class="hl-var">$var</span><span class="hl-code">, </span><span class="hl-reserved">true</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;                        </span><span class="hl-reserved">break</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;                    </span><span class="hl-reserved">case</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">var_dump</span><span class="hl-quotes">'</span><span class="hl-code">:</span></li>
<li><span class="hl-code">&nbsp;                        </span><span class="hl-identifier">ob_start</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;                        </span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$var</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;                        </span><span class="hl-var">$msgs</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-identifier">ob_get_clean</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;                        </span><span class="hl-reserved">break</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;                </span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;            </span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;        </span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">implode</span><span class="hl-brackets">(</span><span class="hl-var">$sep</span><span class="hl-code">, </span><span class="hl-var">$msgs</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-inlinetags">?&gt;</span></li></ol></div></div></p>
<h2>Install</h2>
<p>Copy the code above, or copy from <a href="https://gist.github.com/1244452">the Gist File</a>. Paste the contents in to a file that is accessible to your web-server software. Next, edit your <code>php.ini</code> file and edit the line with the <code>auto_prepend_file</code> setting with the full path to your helper file. Now restart apache to reload the <code>php.ini</code>.</p>
<h2>Usage</h3>
<p>All methods will output simple scalar values in their normal format and will translate boolean values to their string values instead of their numerical values. Object and arrays are then run through either <code>print_r()</code> or <code>var_dump()</code> depending upon which method you use.</p>
<p>In general <code>pp()</code> will give you the most readable output as it uses <code>print_r()</code> to output. But one drawback of <code>print_r()</code> is that it doesn&#8217;t tell you what type the variable is. This can be a drawback if you&#8217;re working specifically against boolean or null types. In that case you can use the <code>dp()</code> method which uses <code>var_dump()</code> to output. <code>var_dump()</code>&#8216;s output is less easy to read, but it does output the variable types which is very handy.</p>
<p>The <code>ep()</code> method outputs to the PHP error log. Handy for inspecting data in ajax or api calls or when outputting data is either inconvenient or hard to access.</p>
<p>All functions can be overloaded to take as many arguments as required. Each parameter is parsed separately and output comma separated.</p>
<h2>Caveat</h2>
<p>There&#8217;s only one: make sure that you don&#8217;t commit code that contains these function calls &#8211; others likely won&#8217;t have the same helper methods and your production server most assuredly doesn&#8217;t. There&#8217;s nothing like committing these methods and not realizing it until someone asks you why &#8216;dp() is undefined&#8217;. I&#8217;m actually pretty close to putting pre-commit hooks in to my version control repositories that reject any commit that has these methods in it. Its very easy to forget to strip them out first.</p>
<p>So, there it is. Nothing special, but I find these lil&#8217; guys super handy. I hope you do too.</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2011/09/27/a-few-php-dev-helper-functions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New WP Salts command in the WordPress TextMate bundle</title>
		<link>http://top-frog.com/2011/09/14/new-wp-salts-command-in-the-wordpress-textmate-bundle/</link>
		<comments>http://top-frog.com/2011/09/14/new-wp-salts-command-in-the-wordpress-textmate-bundle/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 16:00:05 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[TextMate]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[salt]]></category>
		<category><![CDATA[secret]]></category>
		<category><![CDATA[secret-key]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=2048</guid>
		<description><![CDATA[I just merged a pull request from Simon Wheatley in to the WordPress TextMate Bundle that adds the command wpsalts to generate the Security Keys for the WP Config file. The command uses the WordPress.org secret-key Service. Very handy. Thanks Simon!]]></description>
			<content:encoded><![CDATA[<p><a href="http://top-frog.com/wp-content/uploads/2010/05/TextMate-icon.png"><img src="http://top-frog.com/wp-content/uploads/2010/05/TextMate-icon.png" alt="" title="TextMate-icon" width="128" height="128" class="alignright size-full wp-image-1376" /></a></p>
<p>I just merged a pull request from <a href="https://github.com/simonwheatley">Simon Wheatley</a> in to the <a href="/projects/wordpress-textmate-bundle/">WordPress TextMate Bundle</a> that adds the command <code>wpsalts</code> to generate the <a href="http://codex.wordpress.org/Editing_wp-config.php#Security_Keys">Security Keys</a> for the WP Config file. The command uses the <a href="https://api.wordpress.org/secret-key/1.1/salt">WordPress.org secret-key Service</a>.</p>
<p>Very handy. </p>
<p>Thanks Simon!</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2011/09/14/new-wp-salts-command-in-the-wordpress-textmate-bundle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress TextMate bundle updated for WordPress 3.2</title>
		<link>http://top-frog.com/2011/07/11/wordpress-textmate-bundle-updated-for-wordpress-3-2/</link>
		<comments>http://top-frog.com/2011/07/11/wordpress-textmate-bundle-updated-for-wordpress-3-2/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 06:56:20 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[PHP Scripting]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[doxygen]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scrape]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[tmbundle]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=2005</guid>
		<description><![CDATA[So, WordPress 3.2 has been out for a little while now and I&#8217;ve just gotten around to updating the bundle. My apologies, I&#8217;ve just been super swamped with a new job in a new city. But that&#8217;s some whining for another post. After much fiddling, the updated WordPress TextMate Bundle is here and it has [...]]]></description>
			<content:encoded><![CDATA[<p>So, WordPress 3.2 has been out for a little while now and I&#8217;ve just gotten around to updating the bundle. My apologies, I&#8217;ve just been super swamped with a new job in a new city. But that&#8217;s some whining for another post.</p>
<p>After much fiddling, the updated <a href="http://top-frog.com/projects/wordpress-textmate-bundle/">WordPress TextMate Bundle</a> is here and it has been updated with a much better function definition display. I&#8217;ve ditched the old function scraper that was an abomination of grep &#038; regex matches and replaced it with <a href="http://www.stack.nl/~dimitri/doxygen/">doxygen</a> and some ruby abomination to provide much more information about the function or method being inspected.</p>
<p><a class="thickbox" href="http://www.flickr.com/photos/tehgipster/5925516548/" title="Screen shot 2011-07-10 at 11.40.10 PM by tehgipster, on Flickr"><img src="http://farm7.static.flickr.com/6121/5925516548_a3b11afb9f.jpg" width="453" height="500" alt="New and Improved Function Definitions" rel="http://farm7.static.flickr.com/6121/5925516548_a3b11afb9f_b.jpg"></a></p>
<p>I&#8217;m pretty sure there&#8217;s a lingering issue with the parsing and display of special characters in the doxygen output (which I blame squarely on strange handling by doxygen) that I haven&#8217;t handled yet. There may be HTML Entities missing from the documentation here and there.</p>
<p>Also improved is that the function definition search is contextually sensitive. It&#8217;ll only look for methods when in object scope (ie: <code>$object->method();</code>) and only look for functions when in regular php scope (ie: <code>function();</code>). There&#8217;s also a prompt to select the method that you&#8217;re actually after when multiple matches are found.</p>
<p>So, as always there&#8217;s something that can be improved upon with the bundle, but its moving forward and getting better with each revision. I guess that&#8217;s something, right? RIGHT?</p>
<p>So, fire up <a href="http://onethingwell.org/post/1344303536/getbundles">GetBundles</a> or head on over to the <a href="https://github.com/Gipetto/wordpress.tmbundle">WordPress TextMate Bundle&#8217;s Github Page</a> to update your bundle!</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2011/07/11/wordpress-textmate-bundle-updated-for-wordpress-3-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Beware MAMP&#8217;s default Caching Settings</title>
		<link>http://top-frog.com/2011/03/14/beware-mamps-default-caching-settings/</link>
		<comments>http://top-frog.com/2011/03/14/beware-mamps-default-caching-settings/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 21:20:46 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[eaccelerator]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[MAMP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xchache]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=1954</guid>
		<description><![CDATA[MAMP is a wonderful thing. It allows for quick setup of a LAMP stack just about anywhere. This makes it great for testing. However, the folks who manage MAMP are focusing MAMP&#8217;s default settings towards production use, not development use. This means that XCache is turned on by default and that means that there is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mamp.info/">MAMP</a> is a wonderful thing. It allows for quick setup of a LAMP stack just about anywhere. This makes it great for testing. However, the folks who manage MAMP are focusing MAMP&#8217;s default settings towards production use, not development use. This means that <a href="http://xcache.lighttpd.net/">XCache</a> is turned on by default and that means that there is variable caching and file-path caching going on (MAMP also includes the <a href="http://php.net/apc">APC</a> &amp; <a href="http://eaccelerator.net/">EAccelerator</a> extensions, which do very similar things, as well).</p>
<p><span id="more-1954"></span></p>
<p>While enabling these caching settings is good for performance they&#8217;re not really good for development since both filesystem paths and interpreted code can be cached for periods of time. What made me notice was when a machine here in the office wasn&#8217;t honoring the new path to a renamed folder. The assets in this folder were all loaded via include statements using relative paths. Hard coded paths should not have been an issue, but for some reason the system kept looking for the files in their old location. </p>
<p>It took a while before I narrowed it down to the caching settings as a culprit. Once we turned off caching all together our changes were reflected immediately and all was right again with the world.</p>
<h3 id="what-you-need-to-do">What you need to do</h3>
<p>The modification is simple, its just a change to the MAMP preferences. </p>
<ol>
<li>Open MAMP</li>
<li>Click the &#8220;Preferences&#8221; button or select &#8220;Preferences&#8221; from the MAMP menu</li>
<li>Click on &#8220;PHP&#8221; in the tab-bar if its not already selected</li>
<li>Change the &#8220;Cache&#8221; dropdown to be &#8220;&ndash;&ndash;&#8221; so that no caching extension is used</li>
<li>Click &#8220;OK&#8221; to save the changes</li>
<li>Restart MAMP (click &#8220;Stop Servers&#8221; and then &#8220;Start Servers&#8221; once they&#8217;ve stopped)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2011/03/14/beware-mamps-default-caching-settings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress TextMate Bundle Updated</title>
		<link>http://top-frog.com/2010/12/27/wordpress-textmate-bundle-updated-wp-31-rc1/</link>
		<comments>http://top-frog.com/2010/12/27/wordpress-textmate-bundle-updated-wp-31-rc1/#comments</comments>
		<pubDate>Tue, 28 Dec 2010 04:20:20 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[PHP Scripting]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[3.1]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[candidate]]></category>
		<category><![CDATA[rc]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=1827</guid>
		<description><![CDATA[WordPress 3.1 RC is here, so I figure its time enough to issue an update my [recently neglected, sorry 'bout that, its been busy] WordPress TextMate Bundle. All function definitions have been updated to the 3.1 RC code base. There is a tag for the 3.0 branch as it sat this afternoon. No new features [...]]]></description>
			<content:encoded><![CDATA[<p><a class="floatright" href="http://top-frog.com/wp-content/uploads/2009/12/wp-logo-cropped.png"><img src="http://top-frog.com/wp-content/uploads/2009/12/wp-logo-cropped.png" alt="" title="wp-logo-cropped" width="166" height="124" class="alignright size-full wp-image-1177" /></a><a href="http://wordpress.org/news/2010/12/wordpress-3-1-release-candidate/">WordPress 3.1 RC is here</a>, so I figure its time enough to issue an update my [recently neglected, sorry 'bout that, its been busy] <a href="http://top-frog.com/projects/wordpress-textmate-bundle/">WordPress TextMate Bundle</a>. All function definitions have been updated to the 3.1 RC code base. There is a tag for the 3.0 branch as it sat this afternoon. </p>
<p>No new features have been added yet, but this will at least jump you to the right place in the code base when needing to inspect an internal function.  Suggestions for feature additions are always welcome, so lemme know how you use the bundle and how any improvements can help you use it better and I&#8217;ll see what I can do. As it always has been, the project&#8217;s source is freely available so you&#8217;re welcome to contribute as well if you wanna dive in to a little bit of Ruby code.</p>
<p>I know I&#8217;ll regret saying this, but one of my goals to hit during the 3.1 lifespan is a better code scrape of the WordPress core. I&#8217;ve been playing with a couple of different code scrapers/documentation engines to replace the janky regex that I&#8217;ve got going on, so hopefully I can find the time to put in to this as I think getting as much of the built in documentation to the surface as possible would be a boon to my sanity. Maybe once I&#8217;m caught up on my hackers list reading (I think I&#8217;m about 3 months behind) I might have a couple of ideas for adding to the bundle <img src='http://top-frog.com/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2010/12/27/wordpress-textmate-bundle-updated-wp-31-rc1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress export, import and double serialization.</title>
		<link>http://top-frog.com/2010/08/02/wordpress-export-import-and-double-serialization/</link>
		<comments>http://top-frog.com/2010/08/02/wordpress-export-import-and-double-serialization/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 05:32:47 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[maybe_serialize]]></category>
		<category><![CDATA[maybe_unserialize]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[postmeta]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wxr]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=1509</guid>
		<description><![CDATA[Ran in to a fun one in the WordPress core today. If your plugin stores post meta and you store that post meta as an array then you&#8217;re prone to a bug in the WordPress core that can break your data should someone export their data and reimport it on another WordPress install. Yeah, this [...]]]></description>
			<content:encoded><![CDATA[<p>Ran in to a fun one in the WordPress core today. If your plugin stores post meta and you store that post meta as an array then you&#8217;re prone to a bug in the WordPress core that can break your data should someone export their data and reimport it on another WordPress install. Yeah, this is a small minority of what actually goes on in WordPress but when you&#8217;re dealing with migrating data from one install to another, or are trying to supply complex sample data with a theme distribution, then things like this tend to get on your nerves. Quickly.</p>
<p>I&#8217;m gonna sound jaded through this writeup, but I&#8217;ll get over it. </p>
<p><span id="more-1509"></span></p>
<p>Say your plugin saves and retrieves data correctly, like this greatly oversimplified example:</p>
<p><div class="hl-wrapper"><div class="hl-main"><ol class="hl-main"><li>&nbsp;<span class="hl-inlinetags">&lt;?php</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">global</span><span class="hl-code"> </span><span class="hl-var">$post</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-var">$postmeta</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">one</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">two</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">bunnies</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">add_post_meta</span><span class="hl-brackets">(</span><span class="hl-var">$post</span><span class="hl-code">-&gt;</span><span class="hl-identifier">ID</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">my-meta-key</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-var">$postmeta</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> ...</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> and later</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> ...</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-var">$postmeta</span><span class="hl-code"> = </span><span class="hl-identifier">get_post_meta</span><span class="hl-brackets">(</span><span class="hl-var">$post</span><span class="hl-code">-&gt;</span><span class="hl-identifier">ID</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">my-meta-key</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-inlinetags">?&gt;</span></li></ol></div></div></p>
<p>You&#8217;re properly using the post-meta api and your array is serialized in the database, all safe and sound.</p>
<p>Now imagine your user migrates to a new host, exports a WXR and imports that WXR on their new host. Your data will break. Why? On import your serialized array is then double serialized as a string. The post-meta in the WXR is imported the same way as if the data had been saved programmatically which means it makes a trip through the function <code>maybe_serialize</code>. Unfortunately <code>maybe_serialize</code> has a bug that explicitly serializes already serialized data. So now your data is broken because your serialized array has just been serialized as a string. Don&#8217;t expect this behavior to change any time soon. The core WordPress team is too worried about breaking the functionality of plugins who have been saving data the wrong way to try and make this function work correctly. You have to safeguard yourself against its behavior.</p>
<p>Its not a lost cause, though, you can protect yourself by being a bit more verbose when pulling your post meta. When retrieving your post meta don&#8217;t assume that you know how its gonna come out. Yeah, it sounds funny, but its better safe than broken. Simply changing the above code by one line can help protect your data when it moves from server to server. Like so:</p>
<p><div class="hl-wrapper"><div class="hl-main"><ol class="hl-main"><li>&nbsp;<span class="hl-inlinetags">&lt;?php</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">global</span><span class="hl-code"> </span><span class="hl-var">$post</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-var">$postmeta</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">one</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">two</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">bunnies</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">add_post_meta</span><span class="hl-brackets">(</span><span class="hl-var">$post</span><span class="hl-code">-&gt;</span><span class="hl-identifier">ID</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">my-meta-key</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-var">$postmeta</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> ...</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> and later</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> ...</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-var">$postmeta</span><span class="hl-code"> = </span><span class="hl-identifier">maybe_unserialize</span><span class="hl-brackets">(</span><span class="hl-identifier">get_post_meta</span><span class="hl-brackets">(</span><span class="hl-var">$post</span><span class="hl-code">-&gt;</span><span class="hl-identifier">ID</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">my-meta-key</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-inlinetags">?&gt;</span></li></ol></div></div></p>
<p>By wrapping the <code>get_post_meta</code> function call in a <code>maybe_unserialize</code> call you force the data coming out of the database to be inspected one more time and then double-unserialize if necessary. Its extra work but it can save your butt.</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2010/08/02/wordpress-export-import-and-double-serialization/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A simple way to limit file downloads to only logged in users in WordPress</title>
		<link>http://top-frog.com/2010/07/01/a-simple-way-to-limit-file-downloads-to-only-logged-in-users-in-wordpress/</link>
		<comments>http://top-frog.com/2010/07/01/a-simple-way-to-limit-file-downloads-to-only-logged-in-users-in-wordpress/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 18:51:38 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[protect]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp_list_pages]]></category>

		<guid isPermaLink="false">http://top-frog.com/?p=1344</guid>
		<description><![CDATA[So, you&#8217;ve used WordPress to build your client&#8217;s site and to provide downloads for the site&#8217;s users. You&#8217;re hiding the links to download content based on the user&#8217;s logged in status. Great. But what happens when the logged in user copies the download URL and sends it to his friend? Well, unless you&#8217;re filtering the [...]]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;ve used WordPress to build your client&#8217;s site and to provide downloads for the site&#8217;s users. You&#8217;re hiding the links to download content based on the user&#8217;s logged in status. Great. But what happens when the logged in user copies the download URL and sends it to his friend? Well, unless you&#8217;re filtering the download links and checking them with WordPress first his friend gets to download the file.</p>
<p>I&#8217;m not a big fan of checking every file download with WordPress as it can take a lot of overhead if you&#8217;re running a busy site. So here is a pretty straight forward way to limit downloads from a WordPress site with a minimal amount of code. In this example I&#8217;ll illustrate how to prevent non-logged in users from downloading audio files in <code>mp3</code> and <code>m4a</code> format.</p>
<p><span id="more-1344"></span></p>
<h2>Basic Blocking</h2>
<p>First, lets use some ModRewrite rules to get Apache to show users a 403 forbidden page when trying to access the files. This isn&#8217;t pretty, it simply gets Apache to dump the user in to a default 403 page and the user is told that their access is forbidden. <b>The .htaccess changes:</b></p>
<p><div class="hl-wrapper"><div class="hl-main"><ol class="hl-main"><li>&nbsp;<span class="hl-comment"># These next two lines will already exist in your .htaccess file</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">RewriteEngine</span><span class="hl-code"> </span><span class="hl-reserved">On</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">RewriteBase</span><span class="hl-code"> /</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment"># Add these lines right after the preceding two</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">RewriteCond</span><span class="hl-code"> %{</span><span class="hl-identifier">REQUEST_FILENAME</span><span class="hl-code">} ^.*</span><span class="hl-brackets">(</span><span class="hl-identifier">mp3</span><span class="hl-code">|</span><span class="hl-identifier">m4a</span><span class="hl-brackets">)</span><span class="hl-code">$</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">RewriteCond</span><span class="hl-code"> %{</span><span class="hl-identifier">HTTP_COOKIE</span><span class="hl-code">} !^.*</span><span class="hl-identifier">wordpress_logged_in</span><span class="hl-code">.*$ [</span><span class="hl-identifier">NC</span><span class="hl-code">]</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">RewriteRule</span><span class="hl-code"> . - [</span><span class="hl-identifier">R</span><span class="hl-code">=</span><span class="hl-number">403</span><span class="hl-code">,</span><span class="hl-identifier">L</span><span class="hl-code">]</span></li></ol></div></div></p>
<p>On the first line of this code you&#8217;ll see <code>(mp3|m4a)</code>. This is the part that looks at the ending of the file name and determines which files it will act upon. replace the items inside the parentheses with the file types that you want to protect, each one separated by the pipe character. So, for example, if you wanted to protect PDF and RTF files you&#8217;d change it to: <code>RewriteCond %{REQUEST_FILENAME} ^.*(pdf|doc)$</code></p>
<p>That is really all we need but its not very nice to dump the user like that and not inform them of why they were forbidden. They may assume that the site is broken. So lets do this the right way and get the users redirected to a page that will inform them of why they were denied access to the content.</p>
<h2>Redirecting the Access Denied</h2>
<p>For this we&#8217;ll need a page template. You can create anything you&#8217;d like, but the basics of it are: </p>
<p><div class="hl-wrapper"><div class="hl-main"><ol class="hl-main"><li>&nbsp;<span class="hl-inlinetags">&lt;?php</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">/*</span><span class="hl-comment">*</span></li>
<li><span class="hl-comment">&nbsp; * Template Name: 403</span></li>
<li><span class="hl-comment">&nbsp; *</span></li>
<li><span class="hl-comment">&nbsp; * The template for displaying 403 pages (Forbidden/Not Allowed).</span></li>
<li><span class="hl-comment">&nbsp; </span><span class="hl-comment">*/</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp; </span><span class="hl-identifier">get_header</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-inlinetags">?&gt;</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    &lt;div id=&quot;container&quot;&gt;</span></li>
<li><span class="hl-code">&nbsp;        &lt;div id=&quot;content&quot; role=&quot;main&quot;&gt;</span></li>
<li><span class="hl-code">&nbsp;            &lt;div id=&quot;post-0&quot; class=&quot;post error403 not-allowed&quot;&gt;</span></li>
<li><span class="hl-code">&nbsp;                &lt;h1 class=&quot;entry-title&quot;&gt;</span><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-identifier">_e</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">Action Not Allowed</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">twentyten</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-inlinetags">?&gt;</span><span class="hl-code">&lt;/h1&gt;</span></li>
<li><span class="hl-code">&nbsp;                &lt;div class=&quot;entry-content&quot;&gt;</span></li>
<li><span class="hl-code">&nbsp;                    &lt;p&gt;</span><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-identifier">_e</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Apologies, but you are not allowed to download files while not logged in.</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">twentyten</span><span class="hl-quotes">&quot;</span><span class="hl-code">; </span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-inlinetags">?&gt;</span><span class="hl-code">&lt;/p&gt;</span></li>
<li><span class="hl-code">&nbsp;                &lt;/div&gt;&lt;!-- .entry-content --&gt;</span></li>
<li><span class="hl-code">&nbsp;            &lt;/div&gt;&lt;!-- #post-0 --&gt;</span></li>
<li><span class="hl-code">&nbsp;        &lt;/div&gt;&lt;!-- #content --&gt;</span></li>
<li><span class="hl-code">&nbsp;    &lt;/div&gt;&lt;!-- #container --&gt;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-identifier">get_footer</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-inlinetags">?&gt;</span></li></ol></div></div></p>
<p>Your template will obviously look a bit different. I did this one as an extension to the new Twenty Ten theme in WordPress 3.0 and based it off of the provided 404 template.</p>
<p>Save the file to your theme&#8217;s directory. It doesn&#8217;t matter what you name it. WordPress will actually pick up on the <code>Template Name: 403</code> portion as the template ID. </p>
<p>Next we need to create a page in the WordPress admin for our notification page. Create a new page, name it whatever you want. For my purposes I titled the page &#8220;Not Allowed&#8221; so my slug ended up as &#8220;not-allowed&#8221;. You can edit these to be any values you want if the page title created a slug that you don&#8217;t like. You&#8217;ll need that slug here in the next step. Next select the 403 page template from page templates select input in the Attributes meta box (typically on the right side of the page, underneath the Publish button. Publish the page.</p>
<p>Now let&#8217;s alter that <code>.htacess</code> directive to redirect to this page instead of showing that unfriendly Apache notice. The modified directives are:</p>
<p><div class="hl-wrapper"><div class="hl-main"><ol class="hl-main"><li>&nbsp;<span class="hl-identifier">RewriteCond</span><span class="hl-code"> %{</span><span class="hl-identifier">REQUEST_FILENAME</span><span class="hl-code">} ^.*</span><span class="hl-brackets">(</span><span class="hl-identifier">mp3</span><span class="hl-code">|</span><span class="hl-identifier">m4a</span><span class="hl-brackets">)</span><span class="hl-code">$</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">RewriteCond</span><span class="hl-code"> %{</span><span class="hl-identifier">HTTP_COOKIE</span><span class="hl-code">} !^.*</span><span class="hl-identifier">wordpress_logged_in</span><span class="hl-code">.*$ [</span><span class="hl-identifier">NC</span><span class="hl-code">]</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-identifier">RewriteRule</span><span class="hl-code"> . /</span><span class="hl-reserved">not</span><span class="hl-code">-</span><span class="hl-identifier">allowed</span><span class="hl-code"> [</span><span class="hl-identifier">R</span><span class="hl-code">,</span><span class="hl-identifier">L</span><span class="hl-code">]</span></li></ol></div></div></p>
<p>The relevant change happened on the third line where the dash was replaced by the relative url to my 403 page. In my case that is <code>/not-allowed</code>. Yours will differ depending upon how named your page. Don&#8217;t forget the leading slash when adding your slug so that it&#8217;s a valid relative path. (This can be an absolute path as well, ie: one that contains the full <code>http://domain.com/blah-blah</code> but there&#8217;s no need to do that here unless you&#8217;ve got valid reason to do so, like if you want to redirect the user to a different domain).</p>
<p>Now, whenever someone who is not logged in tries to download a file type that you&#8217;ve specified they&#8217;ll be redirected to your 403 page. What you tell them there is up to you.</p>
<h2>But&hellip;</h2>
<p>&hellip;now, if you&#8217;re theme lists out pages anywhere, you&#8217;ve got this 403 page sticking its nose in where it doesn&#8217;t belong. Not very pretty, now, is it? This is pretty easily remedied. Head on in to the WP Admin and to the page edit screen for the 403 page. Take note of its page ID in the url. It will be the number after the word &#8220;post=&#8221; in the url. For example, if your URL looks like <code>http://wp30.local/wp-admin/post.php?post=8&#038;action=edit</code> the post id is <b>8</b>.</p>
<p>We now need to make an addition to your theme&#8217;s <code>functions.php</code> file. This file is located in your theme directory. Open this file and add in the following code:</p>
<p><div class="hl-wrapper"><div class="hl-main"><ol class="hl-main"><li>&nbsp;<span class="hl-inlinetags">&lt;?php</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> Do error page excludes</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">exclude_error_pages</span><span class="hl-brackets">(</span><span class="hl-var">$excludes</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-identifier">array_push</span><span class="hl-brackets">(</span><span class="hl-var">$excludes</span><span class="hl-code">, </span><span class="hl-number">8</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-var">$excludes</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-comment">//</span><span class="hl-comment"> we don't want any funny stuff in the admin, only add to front end</span><span class="hl-comment"></span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code">!</span><span class="hl-identifier">is_admin</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;    </span><span class="hl-identifier">add_filter</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">wp_list_pages_excludes</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">exclude_error_pages</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;</span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-brackets">}</span><span class="hl-code"></span></li>
<li><span class="hl-code">&nbsp;</span><span class="hl-inlinetags">?&gt;</span></li></ol></div></div></p>
<p>On the line that says <code>array_push($excludes, 8);</code> replace the <code>8</code> with the id of the page you just created. This will keep the function <code>wp_list_pages()</code> from outputting the 403 page in any of its lists. </p>
<p><b>Note:</b> if you&#8217;ve got other places in your theme that are pulling page lists through different means you&#8217;ll want to modify or filter those results as well. Depending upon the methods used to make the lists you can probably exclude the page as a parameter of the call for pages instead of using a filter. Your mileage will vary, but it is certainly doable.</p>
<h2>Ta da!</h2>
<p>And there you have it. Simple and straight forward. No real frills, though. As it sits now the user is redirected to a page that just tells then simply that they need to be a logged in user. That&#8217;s not very informative all by itself. There are a hundred ways to modify this to make it more convenient on the user.</p>
<p>Hopefully this gives you some ideas on what can be done to help legitimate users get to your content while keeping the rif-raff from poaching it.</p>
]]></content:encoded>
			<wfw:commentRss>http://top-frog.com/2010/07/01/a-simple-way-to-limit-file-downloads-to-only-logged-in-users-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: top-frog.com @ 2012-02-04 19:11:20 by W3 Total Cache -->
