<?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>ajaxtime.com &#187; make plugin</title>
	<atom:link href="http://www.ajaxtime.com/tag/make-plugin/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ajaxtime.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 13 Apr 2010 14:41:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to write a Wordpress plugin: episode 1 &#8211; getting started</title>
		<link>http://www.ajaxtime.com/how-to-write-a-wordpress-plugin-episode-1-getting-started.html</link>
		<comments>http://www.ajaxtime.com/how-to-write-a-wordpress-plugin-episode-1-getting-started.html#comments</comments>
		<pubDate>Thu, 16 Apr 2009 07:58:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[make plugin]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress plugin]]></category>

		<guid isPermaLink="false">http://www.ajaxtime.com/?p=84</guid>
		<description><![CDATA[Wordpress plugins are the single best way of integrating new functionality into a Wordpress install. You write the plugin, upload it to your site and activate it. If you grow tired of it, you de-activate it - it really is that simple. ]]></description>
			<content:encoded><![CDATA[<p><strong>Wordpress is amazing, let&#8217;s get that out of the way. While I don&#8217;t use it for this website I do use it for a couple of other things and it&#8217;s just an incredible project &#8211; but what makes it incredible? It&#8217;s the variety and depth of plugins that are available. So I&#8217;m going to be writing a series of tutorials on &#8220;how to make a Wordpress plugin&#8221;. Welcome to episode one.</strong></p>
<p>Wordpress plugins are the single best way of integrating new functionality into a Wordpress install. You write the plugin, upload it to your site and activate it. If you grow tired of it, you de-activate it &#8211; it really is that simple. There are hundreds of great plugins already available but it&#8217;s always handy to know how to write one yourself, so here we go.</p>
<p><strong>Episode 1: Making a very simple plugin and getting it recognised</strong><br />
The first step is to actually create your plugin and get it recognised within Wordpress before trying to include any functionality. So in this episode we&#8217;re going to create a very basic plugin that doesn&#8217;t actually do anything and install it.</p>
<p><strong>#1 &#8211; Headers are important</strong><br />
Wordpress needs quite a strict setup in the head of the PHP file to identify the attributes of your plugin, so I&#8217;ll show you how mine looks:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">?</a></div>
</div>
<ol class="dp-c">
<li class="alt"><span><span class="comment">/* </span> </span></li>
<li><span><span class="comment">Plugin Name: Seopher.com Demonstration Plugin </span> </span></li>
<li class="alt"><span><span class="comment">Plugin URI: http://www.seopher.com </span> </span></li>
<li><span><span class="comment">Description: This is just a demonstration plugin to show how you build one </span> </span></li>
<li class="alt"><span><span class="comment">Author: Steven York of Seopher.com </span> </span></li>
<li><span><span class="comment">Version: 0.1 </span> </span></li>
<li class="alt"><span><span class="comment">Author URI: http://www.seopher.com </span> </span></li>
<li><span><span class="comment">*/</span><span>  </span></span></li>
</ol>
</div>
<p><textarea class="php" style="display: none;" cols="80" rows="5" name="code">/* Plugin Name: Seopher.com Demonstration Plugin Plugin URI: http://www.seopher.com Description: This is just a demonstration plugin to show how you build one Author: Steven York of Seopher.com Version: 0.1 Author URI: http://www.seopher.com */ </textarea> &#8220;Plugin Name&#8221;, &#8220;Author&#8221; and &#8220;Description&#8221; are rather self explanatory. &#8220;Plugin URI&#8221; is a direct link to the project page for this plugin, where users can visit for updates, support etc. The version is a number you wish to assign to the release, so version it however you like. &#8220;Author URI&#8221; is your website. In this instance the &#8220;Author URI&#8221; and &#8220;Plugin URI&#8221; are the same because this is only a demonstration plugin rather than a dedicated project.</p>
<p><strong>#2 &#8211; Plugin content</strong><br />
I then wrote a function to initialise the plugin, this is called later to write some content onto the specific plugin configuration page (under &#8220;Options&#8221;, where you see all the other plugin config pages). All this function does at the moment is return some HTML as a token gesture to show that we&#8217;ve actually got something working. The &#8220;wrap&#8221; div is significant because that is a Wordpress wide constant, placing all your content into a suitably styled container.</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">?</a></div>
</div>
<ol class="dp-c">
<li class="alt"><span><span class="keyword">function</span><span> initDemoPlugin()   </span></span></li>
<li><span>{   </span></li>
<li class="alt"><span>       </span></li>
<li><span>    ?&gt;   </span></li>
<li class="alt"><span>        &lt;div </span><span class="keyword">class</span><span>=</span><span class="string">&#8220;wrap&#8221;</span><span>&gt;   </span></li>
<li><span>            &lt;h2&gt;Seopher.com demonstration plugin&lt;/h2&gt;   </span></li>
<li class="alt"><span>            This is just some sample content to show that we&#8217;ve got control over the content of this page.  Rawr!   </span></li>
<li><span>        &lt;/div&gt;   </span></li>
<li class="alt"><span>    &lt;?php   </span></li>
<li><span>}   </span></li>
</ol>
</div>
<p><textarea class="php" style="display: none;" cols="80" rows="5" name="code">function initDemoPlugin() {      	?&gt;     	&lt;div class=&#8221;wrap&#8221;&gt;         	&lt;h2&gt;Seopher.com demonstration plugin&lt;/h2&gt;             This is just some sample content to show that we&#8217;ve got control over the content of this page.  Rawr!         &lt;/div&gt;     &lt;?php } </textarea></p>
<p><strong>#3 &#8211; Add the plugin to the submenu</strong><br />
This step involves writing a function to add the plugin into the &#8220;Options&#8221; sub-menu so that when it is activated you have somewhere to visit to configure the settings. See the code below:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="http://www.seopher.com/articles/how_to_write_a_wordpress_plugin_episode_1__getting_started#">?</a></div>
</div>
<ol class="dp-c">
<li class="alt"><span><span class="keyword">function</span><span> addPluginToSubmenu()    </span></span></li>
<li><span>{   </span></li>
<li class="alt"><span>    add_submenu_page(</span><span class="string">&#8216;options-general.php&#8217;</span><span>, </span><span class="string">&#8216;Seopher demo plugin page&#8217;</span><span>, </span><span class="string">&#8216;Seopher demo plugin&#8217;</span><span>, 10, </span><span class="keyword">__FILE__</span><span>, </span><span class="string">&#8216;initDemoPlugin&#8217;</span><span>);   </span></li>
<li><span>}   </span></li>
<li class="alt"><span>  </span></li>
<li><span>add_action(</span><span class="string">&#8216;admin_menu&#8217;</span><span>, </span><span class="string">&#8216;addPluginToSubmenu&#8217;</span><span>);   </span></li>
</ol>
</div>
<p><textarea class="php" style="display: none;" cols="80" rows="5" name="code">function addPluginToSubmenu()  {     add_submenu_page(&#8217;options-general.php&#8217;, &#8216;Seopher demo plugin page&#8217;, &#8216;Seopher demo plugin&#8217;, 10, __FILE__, &#8216;initDemoPlugin&#8217;); }  add_action(&#8217;admin_menu&#8217;, &#8216;addPluginToSubmenu&#8217;); </textarea> All we&#8217;re doing is tying into the &#8220;add_submenu_page&#8221; function, where we&#8217;re passing several parameters. Firstly we&#8217;re specifying the parent page (in this case options-general.php) that the sub-menu page will sit under. The second parameter is the page title for the new page (as seen in the browser&#8217;s title bar). The third param is what appears in the sub-menu navigation. The next parameter is the priority of this function which can just be left at 10 for now. The final param is the function that is called to populate the page, in this case it&#8217;s the function we created in step #2.</p>
<p>Finally we use the Wordpress function &#8220;add_action&#8221; to call the function we&#8217;ve just written, simple!</p>
<p><strong>#4 &#8211; Upload the PHP file</strong><br />
So if you compile all the code we&#8217;ve shown so far (or download my version here) into a PHP file, you can then upload it to the Wordpress install. Upload the PHP file to &#8220;/wp-content/plugins/&#8221; and you&#8217;re done.</p>
<p><strong>#5 &#8211; Activate the plugin!</strong><br />
Log into your Wordpress install and visit the &#8220;Plugins&#8221; tab and you should see something similar to the picture below:</p>
<p><img title="wordpress plugin" src="http://www.ajaxtime.com/wp-content/uploads/auto_save_image/2009/04/005858ydd.gif" alt="wordpress plugin" /></p>
<p>That&#8217;s your plugin! Click &#8220;activate&#8221; on the right hand side and it&#8217;s now active!</p>
<p><strong>#6 &#8211; Visit the config</strong><br />
Click &#8220;Options&#8221; and you should see our plugin added to the sub-menu as per the screenshot below:</p>
<p><img title="wordpress plugin" src="http://www.ajaxtime.com/wp-content/uploads/auto_save_image/2009/04/005858LcZ.gif" alt="wordpress plugin" /></p>
<p>Clicking on that takes you to our plugin configuration page. All this page does is output the return of our initDemoPlugin() function that we wrote in #2. So clicking on &#8220;Seopher demo plugin&#8221; takes us to this page:</p>
<p><img title="wordpress plugin" src="http://www.ajaxtime.com/wp-content/uploads/auto_save_image/2009/04/0058591bv.gif" alt="wordpress plugin" /></p>
<p><strong>So there you have it, 6 steps to creating a dummy Wordpress plugin. In episode two I&#8217;ll start going through how we start integrating functionality into the plugin and we can start making something useful. I hope this was useful, check back soon for updates.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxtime.com/how-to-write-a-wordpress-plugin-episode-1-getting-started.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
