<?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>wesbillman &#187; Wordpress</title>
	<atom:link href="http://www.wesbillman.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wesbillman.com</link>
	<description>Something to keep me busy</description>
	<lastBuildDate>Mon, 14 Jun 2010 20:34:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Building my first WordPress plugin</title>
		<link>http://www.wesbillman.com/2008/11/building-my-first-wordpress-plugin/</link>
		<comments>http://www.wesbillman.com/2008/11/building-my-first-wordpress-plugin/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 04:15:43 +0000</pubDate>
		<dc:creator>wes</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.wesbillman.com/2008/11/building-my-first-wordpress-plugin-2/</guid>
		<description><![CDATA[Take a look to the right of my site, see that little twitter feed on the sidebar?  That&#8217;s a new plugin I just created.  I had tried a few different twitter plugins for WordPress, but none of them did exactly what I wanted.  Plus, I have been meaning to take some time to figure out [...]]]></description>
			<content:encoded><![CDATA[<p>Take a look to the right of my site, see that little twitter feed on the sidebar?  That&#8217;s a new plugin I just created.  I had tried a few different twitter plugins for <a href="http://www.wordpress.org/">WordPress</a>, but none of them did exactly what I wanted.  Plus, I have been meaning to take some time to figure out how to create plugins and this was a good opportunity to do just that.  Feel free to comment if there are easier/better ways of creating plugins.</p>
<p>The first thing I did was create a new directory in my <em>wp-content/plugins/</em> directory.  I named my plugin <em>twitkick. </em>The name is derived from twitter and kickstand.  <a href="http://www.kickstandinteractive.com">Kickstand</a> is the name of my web development agency, I plan to make more plugins under the kickstand name.</p>
<p>Inside <em>wp-content/plugins/twitkick</em> I created a new file named <em>twitkick.php</em>.  At the top of that file I needed to include some information.</p>
<blockquote><p>&lt;?php<br />
/*<br />
Plugin Name: Twitter Kicker<br />
Plugin URI: http://wesbillman.com/twitter-kicker<br />
Description: Twitter Kicker for WordPress<br />
Author: Wes Billman<br />
Author URI: http://wesbillman.com<br />
*/<br />
?&gt;</p></blockquote>
<p><span id="more-131"></span>The above should get the plugin to appear in your WordPress plugins list.  Now I&#8217;m going to make the plugin actually do something.  I started building my plugin by creating the admin page first and then the actual content.  So, to hook into the admin page I added the following to twitkick.php.</p>
<blockquote><p>// Hook for adding admin menus<br />
add_action(&#8216;admin_menu&#8217;, &#8216;tk_admin_page&#8217;);</p></blockquote>
<p>This will add a hook to WordPress to call &#8220;tk_admin_page&#8221; when building the admin menu.  Now I needed to add code for &#8220;tk_admin_page&#8221;.</p>
<blockquote><p>// action function for above hook<br />
function tk_admin_page() {<br />
// Add a new submenu under Options:<br />
add_options_page(&#8216;Twitter Kicker&#8217;, &#8216;Twitter Kicker&#8217;, 8, &#8216;twitkickoptions&#8217;, &#8216;tk_options_page&#8217;);<br />
}</p></blockquote>
<p>Then, I created an options page to control the options for my plugin.  Most of the code below is just for styling to match WordPress admin pages.  The important part is &#8220;get_option(&#8216;twitter_username&#8217;);&#8221; this is the only option I created for my plugin.</p>
<blockquote><p>// tk_options_page() displays the page content for the Test Options submenu<br />
function tk_options_page() {<br />
?&gt;<br />
&lt;div class=&#8221;wrap&#8221;&gt;<br />
&lt;h2&gt;Twitter Kicker&lt;/h2&gt;</p>
<p>&lt;form method=&#8221;post&#8221; action=&#8221;options.php&#8221;&gt;<br />
&lt;?php wp_nonce_field(&#8216;update-options&#8217;); ?&gt;</p>
<p>&lt;table class=&#8221;form-table&#8221;&gt;</p>
<p>&lt;tr valign=&#8221;top&#8221;&gt;<br />
&lt;th scope=&#8221;row&#8221;&gt;Twitter Username&lt;/th&gt;<br />
&lt;td&gt;&lt;input type=&#8221;text&#8221; name=&#8221;twitter_username&#8221; value=&#8221;&lt;?php echo get_option(&#8216;twitter_username&#8217;); ?&gt;&#8221; /&gt;&lt;/td&gt;<br />
&lt;/tr&gt;</p>
<p>&lt;/table&gt;</p>
<p>&lt;input type=&#8221;hidden&#8221; name=&#8221;action&#8221; value=&#8221;update&#8221; /&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;page_options&#8221; value=&#8221;twitter_username&#8221; /&gt;</p>
<p>&lt;p class=&#8221;submit&#8221;&gt;<br />
&lt;input type=&#8221;submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;?php _e(&#8216;Save Changes&#8217;) ?&gt;&#8221; /&gt;<br />
&lt;/p&gt;</p>
<p>&lt;/form&gt;<br />
&lt;/div&gt;</p>
<p>&lt;?php<br />
}</p></blockquote>
<p>At this point I had a functioning admin page that would create  and save my options.  So, it&#8217;s time to make the plugin display in the sidebar (hopefully you&#8217;re using a theme with proper widget hooks).  I added a new hook function &#8220;add_action(&#8216;init&#8217;, &#8216;tk_init&#8217;)&#8221;</p>
<blockquote><p>// Hook for adding admin menus<br />
add_action(&#8216;admin_menu&#8217;, &#8216;tk_add_pages&#8217;);<br />
add_action(&#8216;init&#8217;, &#8216;tk_init&#8217;);</p></blockquote>
<p>And finally, populate the &#8220;tk_init&#8221; function to get the plugin to display.</p>
<blockquote><p>// action function for above hook<br />
function tk_init() {<br />
if ( !function_exists(&#8216;register_sidebar_widget&#8217;) || !function_exists(&#8216;register_widget_control&#8217;) )<br />
return;</p>
<p>function widget_twitkick($args) {</p>
<p>//setup some variables<br />
$twitter_url = &#8216;http://twitter.com/&#8217;;<br />
$user_feed_url = $twitter_url . &#8216;statuses/user_timeline/&#8217; . get_option(&#8216;twitter_username&#8217;) . &#8216;.rss&#8217;;<br />
$user_feed_url.= &#8216;?count=5&#8242;;<br />
$user_twitter_home = $twitter_url . get_option(&#8216;twitter_username&#8217;);</p>
<p>echo &#8220;&lt;li id=\&#8221;twitkick\&#8221; class=\&#8221;widget twitkick\&#8221;&gt;&#8221;;<br />
?&gt;<br />
&lt;div id=&#8221;twitter_div&#8221;&gt;<br />
&lt;h1 class=&#8221;sidebar-title&#8221;&gt;Twitter&lt;/h1&gt;<br />
&lt;ul id=&#8221;twitter_update_list&#8221;&gt;&lt;/ul&gt;<br />
&lt;/div&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;http://twitter.com/javascripts/blogger.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;http://twitter.com/statuses/user_timeline/wesbillman.json?callback=twitterCallback2&amp;amp;count=5&#8243;&gt;&lt;/script&gt;<br />
&lt;?php<br />
echo &#8220;&lt;/li&gt;&#8221;;<br />
}</p>
<p>register_sidebar_widget(array(&#8216;Twitter Kicker&#8217;, &#8216;widgets&#8217;), &#8216;widget_twitkick&#8217;);<br />
}</p></blockquote>
<p>That should be all.  Please add a comment if you have any suggestions or questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wesbillman.com/2008/11/building-my-first-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
