<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>brandontreb.com</title>
	
	<link>http://brandontreb.com</link>
	<description>Code, Nerdyness, and Nonsense</description>
	<lastBuildDate>Wed, 07 Jul 2010 00:23:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/brandontreb" /><feedburner:info uri="brandontreb" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Test Version of TweetPress 3.0</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/iRhjHKfNkQ8/</link>
		<comments>http://brandontreb.com/test-version-of-tweetpress-3-0/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 00:23:24 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Nerdyness]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[tweetpress]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=838</guid>
		<description><![CDATA[So WordPress 3.0 has broken Tweetpress for many people.  If you are daring, willing to help, and experiencing issues with Tweetpress, please download the 3.0 test build of Tweetpress and install it on your WordPress blog. Here are your next steps after installation: Make sure you add your Twitter username and Password to the Tweetpress [...]]]></description>
			<content:encoded><![CDATA[<p>So WordPress 3.0 has broken Tweetpress for many people.  If you are daring, willing to help, and experiencing issues with Tweetpress, please download the 3.0 test build of Tweetpress and install it on your WordPress blog.</p>
<p>Here are your next steps after installation:</p>
<ol>
<li>Make sure you add your Twitter username and Password to the Tweetpress settings in your wp-admin and save it</li>
<li>Attempt to post a photo to Twitter using Twitter for iPhone</li>
<li>If it works, you win, let me know, if not do this:
<ol>
<li>go back to the tweetpress admin in wp-admin</li>
<li>click the log link at the very bottom</li>
<li>copy the text and email it to brandontreb [at] gmail [dot] com with the subject &#8220;Tweetpress Log&#8221;</li>
</ol>
</li>
</ol>
<p>This will really help me troubleshoot the issues that everyone has been having.</p>
<p>Thanks!</p>
<p><a href="http://brandontreb.com/wp-content/uploads/2010/07/tweetpress.zip">Download Tweetpress Test Build 3.0</a></p>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/iRhjHKfNkQ8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/test-version-of-tweetpress-3-0/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://brandontreb.com/test-version-of-tweetpress-3-0/</feedburner:origLink></item>
		<item>
		<title>Feedburner Anywhere Plugin Released</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/srnLnTbSGzU/</link>
		<comments>http://brandontreb.com/feedburner-anywhere-plugin-released/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 23:00:49 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[Feedburner]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[subscriber]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=833</guid>
		<description><![CDATA[I have just released another WordPress plugin called Feedburner Anywhere. What it does is allow you to display your RSS subscriber count anywhere on your blog. You have the choice of using the built-in widget, embedding it in your posts/pages, or a combination of both. Check out my sidebar for an example of usage. Download [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption aligncenter" style="width: 198px"><a href="http://www.crunchbase.com/company/feedburner"><img title="Image representing FeedBurner as depicted in C..." src="http://www.crunchbase.com/assets/images/resized/0000/3292/3292v1-max-250x250.png" alt="Image representing FeedBurner as depicted in C..." width="188" height="44" /></a><p class="wp-caption-text">Image via CrunchBase</p></div>
</div>
<p>I have just released another WordPress plugin called Feedburner Anywhere.</p>
<p>What it does is allow you to display your RSS subscriber count anywhere on your blog.</p>
<p>You have the choice of using the built-in widget, embedding it in your posts/pages, or a combination of both.</p>
<p>Check out my sidebar for an example of usage.</p>
<p><a href="http://wordpress.org/extend/plugins/feedburner-anywhere/">Download Feedburner Anywhere at WordPress.org</a></p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/a163a219-5486-4b37-b958-bc2e76dc02f2/"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=a163a219-5486-4b37-b958-bc2e76dc02f2" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/srnLnTbSGzU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/feedburner-anywhere-plugin-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://brandontreb.com/feedburner-anywhere-plugin-released/</feedburner:origLink></item>
		<item>
		<title>HECK YES C Macro, For When Something Is REALLY True</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/U9XUHhED4nk/</link>
		<comments>http://brandontreb.com/heck-yes-c-macro-for-when-something-is-really-true/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 21:01:06 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerdyness]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[caffeine]]></category>
		<category><![CDATA[compiler directives]]></category>
		<category><![CDATA[macro]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=828</guid>
		<description><![CDATA[Quite possibly the most useful macro you will ever use. #define HECK_YES true &#38;&#38; true &#160; // Usage if&#40;self.sleepy&#41; &#123; self.needsCoffee = HECK_YES; &#125; Now if only I could replace semi colons with exclamation points&#8230;]]></description>
			<content:encoded><![CDATA[<p>Quite possibly the most useful macro you will ever use.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define HECK_YES true &amp;&amp; true</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Usage</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>self.<span style="color: #202020;">sleepy</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   self.<span style="color: #202020;">needsCoffee</span> <span style="color: #339933;">=</span> HECK_YES<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now if only I could replace semi colons with exclamation points&#8230;</p>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/U9XUHhED4nk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/heck-yes-c-macro-for-when-something-is-really-true/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://brandontreb.com/heck-yes-c-macro-for-when-something-is-really-true/</feedburner:origLink></item>
		<item>
		<title>Dynamically Load WordPress Post Images Like Mashable.com</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/lunrxpydiB8/</link>
		<comments>http://brandontreb.com/dynamically-load-wordpress-post-images-like-mashable-com/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 01:00:14 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[laze-load]]></category>
		<category><![CDATA[mashable]]></category>
		<category><![CDATA[wordpress plugin]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=823</guid>
		<description><![CDATA[<h4><a href="http://brandontreb.com/wp-content/uploads/2010/04/jquery_image.png"><img class="aligncenter size-full wp-image-825" title="jquery_image" src="http://brandontreb.com/wp-content/uploads/2010/04/jquery_image.png" alt="" width="600" height="250" /></a></h4>
<h4>What?</h4>
Have you ever noticed that the content on <a href="http://mashable.com/">Mashable.com</a> loads Incredibly fast?  Also, have you noticed that as you scroll the images seem to 'fade' in?  Well, this isn't due to some crazy h4x0r code written specifically by Mashable Engineers.  It's a simple JQuery plugin that loads the images 'Lazily'.]]></description>
			<content:encoded><![CDATA[<h4><a href="http://brandontreb.com/wp-content/uploads/2010/04/jquery_image.png"><img class="aligncenter size-full wp-image-825" title="jquery_image" src="http://brandontreb.com/wp-content/uploads/2010/04/jquery_image.png" alt="" width="600" height="250" /></a></h4>
<h4>What?</h4>
<p>Have you ever noticed that the content on <a href="http://mashable.com/">Mashable.com</a> loads Incredibly fast?  Also, have you noticed that as you scroll the images seem to &#8216;fade&#8217; in?  Well, this isn&#8217;t due to some crazy h4x0r code written specifically by Mashable Engineers.  It&#8217;s a simple JQuery plugin that loads the images &#8216;Lazily&#8217;.</p>
<p>The Jquery plugin can be found <a href="http://plugins.jquery.com/project/lazyload">here</a> and a nice tutorial for implementing it can be found <a href="http://ajaxian.com/archives/lazy-load-plugin-for-jquery">here</a>.</p>
<p>If you don&#8217;t feel like hacking it yourself, read on and I will point you in the direction of a great WordPress plugin that handles this automagically.</p>
<h4>Where?</h4>
<p>Luckily the hard work has been done for you and you can <a href="http://wordpress.org/extend/plugins/jquery-image-lazy-loading/">download a WordPress plugin</a> that will automatically add this functionality to your WordPress blog.</p>
<p>You can <a href="http://wordpress.org/extend/plugins/jquery-image-lazy-loading/">download the plugin from WordPress.org</a></p>
<p>This plugin will work for EVERY image on your blog.  Even the Gravatar icons of the commenters.</p>
<h4>Thats It?</h4>
<p>Yep, try it out.  Just scroll down on my homepage and watch as the images magically fade in.</p>
<p>Happy Wp-ing!</p>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/lunrxpydiB8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/dynamically-load-wordpress-post-images-like-mashable-com/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://brandontreb.com/dynamically-load-wordpress-post-images-like-mashable-com/</feedburner:origLink></item>
		<item>
		<title>WordPress Coding: Programmatically Add Post Tags (and other meta info)</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/zu7JdNNJLmg/</link>
		<comments>http://brandontreb.com/wordpress-coding-programmatically-add-post-tags-and-other-meta-info/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 17:01:45 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[programmatically add tags]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress recipe]]></category>
		<category><![CDATA[wordpress tags]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=812</guid>
		<description><![CDATA[In this tutorial, I will be showing you how to programatically add tags to Wordpress posts.  In addition to tags, I will show you how to update any field for a given post.]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://haacked.com/images/haacked_com/WindowsLiveWriter/CategoriesvsTags_833F/561962_price_tag[3].jpg" title="Tags" class="aligncenter" width="600" /><br />
I was recently working on a script that imports from a custom blogging platform into WordPress and had some need to programmatically add post keywords.</p>
<p>The script to do this is actually quite simple and can be used to update any post attribute.</p>
<p>Here is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Create the post array</span>
<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'ID'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tags_input'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'foo,bar,baz'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
<span style="color: #666666; font-style: italic;">// Update the post</span>
wp_update_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will assign the keywords &#8220;foo&#8221;, &#8220;bar&#8221;, and &#8220;baz&#8221; to the post with ID 5.  This task seems trivial, however it&#8217;s very powerful when you think about automation.  For example, you could write a script to scrape a google search for your target keyword and find related keywords for each of your posts automatically.  Hrm&#8230; plugin idea?</p>
<p>Give it a shot.  More info on available parameters can be found on <a href="http://codex.wordpress.org/Function_Reference/wp_insert_post">WordPress&#8217; site here</a></p>
<p>Here are some of the other fields that you are able to update this way:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">defaults <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'post_status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'draft'</span><span style="color: #339933;">,</span> 
<span style="color: #0000ff;">'post_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'post_author'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$user_ID</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'ping_status'</span> <span style="color: #339933;">=&gt;</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default_ping_status'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
<span style="color: #0000ff;">'post_parent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'menu_order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'to_ping'</span> <span style="color: #339933;">=&gt;</span>  <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'pinged'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'post_password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'guid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'post_content_filtered'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'post_excerpt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'import_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Happy WPCoding!</p>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/zu7JdNNJLmg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/wordpress-coding-programmatically-add-post-tags-and-other-meta-info/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://brandontreb.com/wordpress-coding-programmatically-add-post-tags-and-other-meta-info/</feedburner:origLink></item>
		<item>
		<title>WordPress Programming Tip: Enable Database Error Reporting For Custom Queries</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/-sLgoAMzhj8/</link>
		<comments>http://brandontreb.com/wordpress-programming-tip-enable-database-error-reporting-for-custom-queries/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 00:00:08 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[error_reporting]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=800</guid>
		<description><![CDATA[In this brief tutorial, I will show you how to enable error reporting when testing your own custom Wordpress database queries.  By default, Wordpress has error reporting disabled so that your visitors will never see raw SQL errors.  We will be enabling this reporting on a per-query basis allow you to test out your custom MySQL queries.]]></description>
			<content:encoded><![CDATA[<p>So this one should seem pretty obvious, but it wasn&#8217;t apparent to me at first. &nbsp;It was only after digging through the wp-db.php file that I discovered how to enable error reporting.</p>
<h4>The Problem</h4>
<p>As you may have discovered, the wp_query() function isn&#8217;t a &#8220;one size fit&#8217;s all&#8221; solution. &nbsp;Often times, you may need to query the WordPress database using a custom MySQL query. &nbsp;Especially &nbsp;if you are using WordPress for anything other than a blog (ie <a href="http://freshapps.com">freshapps.com</a>).</p>
<p>When writing custom queries, it can often be frustrating if you make a mistake in the SQL syntax as WordPress will simply display no results. &nbsp;For example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> 
   WHERE post_title = 'foo bar baz&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Outputs Array ( )</span></pre></div></div>

<p>Since we have made an error in our SQL statement (I didn&#8217;t add the second single quote), WordPress will suppress it and simply return an empty array. This is not very helpful for debugging.</p>
<h4>The Solution</h4>
<p>The solution is actually quite simple.  The global $wpdb object has a property called show_errors.  Setting this property to true will cause WordPress to output the SQL errors to the screen for a given query.</p>
<p>Here it is with our example above</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Enables Wordpress's DB Error reporting</span>
<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">show_errors</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> 
   WHERE post_title = 'foo bar baz&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Outputs </span>
<span style="color: #666666; font-style: italic;">// WordPress database error: [You have an error in your </span>
<span style="color: #666666; font-style: italic;">// SQL syntax; check the manual that corresponds to your </span>
<span style="color: #666666; font-style: italic;">// MySQL server version for the right syntax to use near </span>
<span style="color: #666666; font-style: italic;">// ''foo bar baz' at line 1]</span>
<span style="color: #666666; font-style: italic;">// SELECT * FROM wp_posts WHERE post_title = 'foo bar baz</span></pre></div></div>

<p>Now we know what went wrong with our query rather than just receiving empty results.</p>
<p>Let me know if you have any questions or comments.</p>
<p>Happy WPCoding!</p>
<div class="zemanta-pixie" style="margin-top:10px;height:15px"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/a1d99446-c73f-4722-97e6-3e584300069e/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=a1d99446-c73f-4722-97e6-3e584300069e" alt="Reblog this post [with Zemanta]" style="border:none;float:right"></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/-sLgoAMzhj8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/wordpress-programming-tip-enable-database-error-reporting-for-custom-queries/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://brandontreb.com/wordpress-programming-tip-enable-database-error-reporting-for-custom-queries/</feedburner:origLink></item>
		<item>
		<title>WordPress Plugin Development: Your First Plugin</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/QR872_gTGDc/</link>
		<comments>http://brandontreb.com/wordpress-plugin-development-your-first-plugin/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 00:30:33 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress filters]]></category>
		<category><![CDATA[wordpress plugin]]></category>
		<category><![CDATA[wordpress plugin programming]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=778</guid>
		<description><![CDATA[<p>In this tutorial, I will show you the basics of creating a simple Wordpress plugin.  After completing it, you will have the knowledge to expand upon it and create your own Wordpress plugins.</p>


]]></description>
			<content:encoded><![CDATA[<h4>Introduction</h4>
<p>Creating plugins for WordPress seems like a daunting task at first, but the process is actually quite simple.  WordPress&#8217; APIs are very elegant and make plugin development a breeze.</p>
<p>The documentation for writing a plugin can be found <a href="http://codex.wordpress.org/Writing_a_Plugin">here</a>.  Make sure you bookmark it as you will be referring to the documentation quite a bit as you require more functionality.</p>
<h4>WordPress Actions And Filters</h4>
<p>When we talk about creating a plugin for WordPress, it usually refers to extending the functionality.  This could be something as simple as replacing all of the colon-parens with smilies or as complex as doing complete SEO optimization.  Whatever you want to create, chances are you will have to hook into a WordPress Action or Filter.</p>
<p>WordPress Filters are called any time there is data. They are essentially a chain of functions that will be called in order to work on the data in some way.  For example, when WordPress displays the content of your post, rather than it saying &lt;?php echo $content; ?&gt;, it calls the function &lt;?php the_content(); ?&gt;.  Calling this function will invoke the chain of functions to be applied to the content.</p>
<p>To hook a function into this chain, you will use the add_filter function of WordPress.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'myFunc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> myFunc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// Do Something to the content</span>
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the code above our function called myFunc will be called every time the content is displayed in a WordPress post.  I will be explaining the is more detail later in this post.</p>
<p>With the knowlege of actions and filters behind you, you are ready to write your first plugin.</p>
<h4>Setting Up</h4>
<p>The plugin we will be creating is a Word Filter plugin. It could be useful on a blog with multiple authors as a swear word filter.  We will be replace all of the &#8220;naughty words&#8221;, which we define with a substitue.</p>
<p>The first thing you want to do is FTP into your Worpdress site and create the plugin folder.  The location of the folder should be as follows.</p>
<p><strong>/wp-content/plugins/word_filter</strong></p>
<p>Note that any time you create a plugin, it must go inside of the WordPress plugins folder.</p>
<p>Now create a file of the same name in this folder (word_filter.php). This will be the file that will hold all of our plugin code.  Just to reiterate, you should now have a file at this path:</p>
<p><strong>/wp-content/plugins/word_filter/word_filter.php</strong></p>
<p>Now we are ready to begin editing the file&#8230;</p>
<h4>Adding the Meta Information</h4>
<p>In order to identify your plugin (and give you credit for it), you must add the following information to the top of your plugin file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
Plugin Name: Word Filter
Plugin URI: http://brandontreb.com/
Description: This plugin filters out certain words in a post.  Could be used as a swear word filter or just a global find and replace.
Version: 1.0
Author: Brandon Trebitowski
Author URI: http://brandontreb.com
*/</span></pre></div></div>

<p>All of this meta information will be used to identify the plugin.  When the user goes to activate it, all of this info will be displayed in their admin panel.  It will look something like this:</p>
<p><a href="http://brandontreb.com/wp-content/uploads/2010/03/Screen-shot-2010-03-10-at-9.46.09-AM.png"><img src="http://brandontreb.com/wp-content/uploads/2010/03/Screen-shot-2010-03-10-at-9.46.09-AM-500x31.png" alt="" title="Screen shot 2010-03-10 at 9.46.09 AM" width="500" height="31" class="alignleft size-medium wp-image-790" /></a></p>
<p>Coding time&#8230;</p>
<h4>Writing the Code</h4>
<p>The first bit of code for our word filter is the array of words to be replaced.  We will be using associative arrays where the key will be the words we are searching for and the values will be their replacements.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Array of replacements</span>
<span style="color: #000088;">$search_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'idiot'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nice person'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'shutup'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'please be quite'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'love'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As you can see, the word &#8216;idiot&#8217; will be replaced with the words &#8216;nice person&#8217;, etc&#8230;  You could do any amount of replacement here.</p>
<p>The next step is to write our function that will do the replacing.  We will call this function word_filter.  One thing you need to be aware of is the function must take exactly one argument.  This is because we will be hooking into the the_content filter of WordPress.  When our function gets called by the system, it will pass in the post content for every post that gets displayed. Here is what the function will look like.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> word_filter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$search_array</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Modify the content</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$find</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$replace</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$find</span><span style="color: #339933;">,</span><span style="color: #000088;">$replace</span><span style="color: #339933;">,</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Return the content</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Pretty simple ehh? We loop over the $search_array and retrieve its keys and values.  We then substitue the $find string with the $replace string in the post $content.  Finally, we RETURN THE CONTENT.  I emphasized that because it is very important.  Since you are running this function in a chain of others, you must return the content so that the next function can process it.  If you don&#8217;t the chain is broken and your posts won&#8217;t contain any content.</p>
<p>The last thing that must be done is we must hook into the the_content filter of WordPress.  Again, this is how we get our function added to the chain.  To do this, simply add the following line.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Make sure our fn gets called before displaying the content</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'word_filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is just one of the many <a href="http://codex.wordpress.org/Plugin_API">Filters</a> that you are able to hook in to.</p>
<h4>Putting it all together</h4>
<p>When reading tutorial, I generally like to see the final source code in once place.  So, here it is in all of it&#8217;s (very simple) glory.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
Plugin Name: Word Filter
Plugin URI: http://brandontreb.com/
Description: This plugin filters out certain words in a post.  Could be used as a swear word filter or just a global find and replace.
Version: 1.0
Author: Brandon Trebitowski
Author URI: http://brandontreb.com
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Array of replacements</span>
<span style="color: #000088;">$search_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'idiot'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nice person'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'shutup'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'please be quite'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'love'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Make sure our fn gets called before displaying the content</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'word_filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> word_filter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$search_array</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Modify the content</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$find</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$replace</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$find</span><span style="color: #339933;">,</span><span style="color: #000088;">$replace</span><span style="color: #339933;">,</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Return the content</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>*Note: I omitted the php wrapper tags because they were causing problems in the output. Make sure you add them back in.</p>
<p>There you have it! Your first WordPress plugin.  In a later tutorial I will show you how to create an admin panel that will allow users to configure all of the search and replace words.</p>
<p>If you have any comments or questions, feel free to leave them in the comments section of this post.</p>
<p>You may also download the source for this example <a href='http://brandontreb.com/wp-content/uploads/2010/03/word_filter.zip'>here</a>.</p>
<p>Happy WPCoding!</p>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/QR872_gTGDc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/wordpress-plugin-development-your-first-plugin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://brandontreb.com/wordpress-plugin-development-your-first-plugin/</feedburner:origLink></item>
		<item>
		<title>A (Slightly) New Direction…</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/Em-or9XLRYI/</link>
		<comments>http://brandontreb.com/a-slightly-new-direction/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 16:25:16 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[updates]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=771</guid>
		<description><![CDATA[<center><img title="WordPress" src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Wordpress-logo.png/300px-Wordpress-logo.png" alt="WordPress" width="300" height="68" /></center>

Many of you may know that I'm a HUGE fan of <a class="zem_slink" title="WordPress" rel="homepage" href="http://wordpress.org">Wordpress</a>.  I build every single site I create based on the Wordpress engine, even if they are not blogs (ie <a href="http://freshapps.com" target="_blank">FreshApps</a>).]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="display: block; width: 310px; margin: 1em;">
<div class="wp-caption alignleft" style="width: 310px"><a href="http://commons.wikipedia.org/wiki/Image:WordPress-logo.png"><img title="WordPress" src="http://brandontreb.com/wp-content/uploads/2010/03/300px-WordPress-logo.png" alt="WordPress" width="300" height="68" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>Many of you may know that I&#8217;m a HUGE fan of <a class="zem_slink" title="WordPress" rel="homepage" href="http://wordpress.org">WordPress</a>.  I build every single site I create based on the WordPress engine, even if they are not blogs (ie <a href="http://freshapps.com" target="_blank">FreshApps</a>).</p>
<p>That being said, I have decided to shift the focus of this blog slightly to encompass more WordPress related programming.  This is a huge topic and has a huge audience.  I will still be sharing my thoughts about code/Twitter/etc&#8230; while injecting much <em>more</em> content related to WordPress.</p>
<p>I feel that I have a lot to share on that front and can&#8217;t wait to update my theme (to support more content as my main area is a little narrow).</p>
<p>Happy coding <img src='http://brandontreb.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>0</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/c1b4f003-f453-48b3-85f8-39fea8989311/"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=c1b4f003-f453-48b3-85f8-39fea8989311" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/Em-or9XLRYI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/a-slightly-new-direction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://brandontreb.com/a-slightly-new-direction/</feedburner:origLink></item>
		<item>
		<title>Emacs For OSX Is Out!</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/ZtbgJ5Tya3s/</link>
		<comments>http://brandontreb.com/emacs-for-osx-is-out/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 21:44:29 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Nerdyness]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[emacs mac]]></category>
		<category><![CDATA[emacs osx]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=768</guid>
		<description><![CDATA[<p style="text-align: left;"><a href="http://emacsformacosx.com/"><img class="size-medium wp-image-769 alignnone" title="Screen shot 2010-01-29 at 2.39.44 PM" src="http://brandontreb.com/wp-content/uploads/2010/01/Screen-shot-2010-01-29-at-2.39.44-PM-500x498.png" alt="" width="500" height="498" /></a></p>
<p style="text-align: center;">For all you Vi using, Emacs haters out there, I will fight you!</p>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><a href="http://emacsformacosx.com/"><img class="size-medium wp-image-769 alignnone" title="Screen shot 2010-01-29 at 2.39.44 PM" src="http://brandontreb.com/wp-content/uploads/2010/01/Screen-shot-2010-01-29-at-2.39.44-PM-500x498.png" alt="" width="500" height="498" /></a></p>
<p style="text-align: center;">For all you Vi using, Emacs haters out there, I will fight you!</p>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/ZtbgJ5Tya3s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/emacs-for-osx-is-out/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://brandontreb.com/emacs-for-osx-is-out/</feedburner:origLink></item>
		<item>
		<title>The iPad Is Out And It Sounds Like iPod While Plugging Your Nose</title>
		<link>http://feedproxy.google.com/~r/brandontreb/~3/6CyWidjjm5A/</link>
		<comments>http://brandontreb.com/the-ipad-is-out-and-it-sounds-like-ipod-while-plugging-your-nose/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 18:33:43 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[image]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=761</guid>
		<description><![CDATA[<p style="text-align: center;"><img class="aligncenter size-medium wp-image-762" title="appletabletb113" src="http://brandontreb.com/wp-content/uploads/2010/01/appletabletb113-500x332.jpg" alt="" width="500" height="332" /></p>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-medium wp-image-762" title="appletabletb113" src="http://brandontreb.com/wp-content/uploads/2010/01/appletabletb113-500x332.jpg" alt="" width="500" height="332" /></p>
<img src="http://feeds.feedburner.com/~r/brandontreb/~4/6CyWidjjm5A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/the-ipad-is-out-and-it-sounds-like-ipod-while-plugging-your-nose/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://brandontreb.com/the-ipad-is-out-and-it-sounds-like-ipod-while-plugging-your-nose/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 1.470 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-07-29 04:53:50 -->
