<?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>Nerdaphernalia &#187; tutorials</title>
	<atom:link href="http://striderweb.com/nerdaphernalia/tag/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://striderweb.com/nerdaphernalia</link>
	<description>"It's All Geek To Me"</description>
	<lastBuildDate>Wed, 21 Dec 2011 18:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Add New Headers to WordPress Plugins or Themes</title>
		<link>http://striderweb.com/nerdaphernalia/2009/11/add-new-headers-to-wordpress-plugins-or-themes/</link>
		<comments>http://striderweb.com/nerdaphernalia/2009/11/add-new-headers-to-wordpress-plugins-or-themes/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 22:25:11 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[Codecraft]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/?p=266</guid>
		<description><![CDATA[I&#8217;ve had a few patches committed to WordPress core in the last few versions, and have sadly neglected to do writeups about them so that others could take advantage of the new features. I hope to remedy that in the next few posts. First off, WordPress 2.9 has a new feature that allows you to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a few patches committed to WordPress core in the last few versions, and have sadly neglected to do writeups about them so that others could take advantage of the new features.  I hope to remedy that in the next few posts.  First off, WordPress 2.9 has a new feature that allows you to add to the list of headers that are checked when you run either <code>get_plugin_data()</code> or <code>get_theme_data()</code>.</p>
<p>For example:  Let&#8217;s say you want to make a plugin that works with other plugins.  For other plugins to be compatible with it, however, they need to provide some new piece of information, and you want to do this with a custom header.  So we&#8217;re going declare a new plugin header.  Let&#8217;s call it&#8230; oh&#8230;. &#8220;Demo Header&#8221;.  Here&#8217;s the code; just drop this in a plugin and activate:</p>
<pre><code>function plugin_header_demo( $extra_headers ) {
	$extra_headers[] = 'Demo Header';
	return $extra_headers;
}
add_filter( 'extra_plugin_headers', 'plugin_header_demo' );</code></pre>
<p>Pretty simple, eh?  What we&#8217;ve just done is added &#8220;Demo Header&#8221; to the list of headers that WordPress will check for when <code>get_plugin_data()</code> is run.   Now, along with Name, Version, Author, and so forth, a value for Demo Header is returned as well.</p>
<p>Note that this is only for cases where you want <em>any</em> plugin checked for this header.  This changes the <code>get_plugin_data()</code> function and takes effect every time that function is run, on any plugin.</p>
<p>Want to do it for themes?  The code is almost identical:</p>
<pre><code>function theme_header_demo( $extra_headers ) {
	$extra_headers[] = 'Demo Header';
	return $extra_headers;
}
add_filter( 'extra_theme_headers', 'theme_header_demo' );</code></pre>
<p>Note that this does not allow you to alter the pre-existing headers in any way.  You can&#8217;t, for example, remove the &#8220;Name&#8221; header.</p>
<p>Personally, I intend to use this for a third-party update check plugin, which will also be incorporated into <a href="http://code.google.com/p/strider-core/">Strider Core</a>.  For that use, I&#8217;ll add an &#8220;Update URL&#8221; header (or similar).</p>
<p>Next up:  How to define your own custom <code>get_XXX_data()</code> function that works like the ones for plugins or themes.</p>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2009
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2009/11/add-new-headers-to-wordpress-plugins-or-themes/">Permalink to Add New Headers to WordPress Plugins or Themes</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2009/11/add-new-headers-to-wordpress-plugins-or-themes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consolidate Options with Arrays in your WordPress Plugins</title>
		<link>http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/</link>
		<comments>http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 22:24:15 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[Codecraft]]></category>
		<category><![CDATA[Webcraft]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[elegant design]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[settings]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/?p=78</guid>
		<description><![CDATA[If you&#8217;ve ever written a plugin for WordPress you&#8217;ve probably dealt with giving the end user options. Unless you&#8217;ve taken the low road and forced the user to directly edit the plugin file, &#8220;options&#8221; means a Settings screen in the WordPress admin, and most likely you are storing those options in the blog&#8217;s wp-options table. [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever written a plugin for WordPress you&#8217;ve probably dealt with giving the end user options.  Unless you&#8217;ve taken the low road and forced the user to directly edit the plugin file, &#8220;options&#8221; means a Settings screen in the WordPress admin, and most likely you are storing those options in the blog&#8217;s <code>wp-options</code> table.  Over time, bloggers using various plugins can end up with hundreds of <a href="#fnote78_1" class="fnotelink">extraneous records in their options table<sup>*</sup></a>.  If they ever stop using a plugin, or if they ever want to manually clear out options, this job can be made difficult by all the clutter, and the problem is made far worse when plugin authors add a new record for each separate setting in a plugin.  Beyond the mess, plugins written this way generally make many more calls to the database than they need to, which adds unnecessary burden on the server.</p>
<p>I have seen and used plugins that added anywhere from ten to thirty new records to the options table, and a correspondent of mine reports that he has encountered a plugin that, upon activation, adds <span class="pullquote"><!-- A whopping 140 new records.... Egad! -->a whopping <em>140</em> new records to <code>wp_options</code>.   Egad!</span>  There has to be a better way!</p>
<p>There <em>is</em> a better way.  With a few simple changes to your code, plugin authors can put all the various settings into an array, and enter that array as a single record in the options table.  This article will show you how.</p>
<p>On this site I use a plugin called ShrinkyLink.  It performs the straightforward but useful function of shortening long URLs to a specified length, or replacing the link text entirely with a specified string.  It was created by Andrew Rader, but as far as I can tell his web site no longer exists. For the purposes of this article, it has a number of good qualities:</p>
<ul>
<li>It inserts 10 separate records into the WordPress options table</li>
<li>It is not likely to see further updates from the original author</li>
<li>It is useful and thus worthy of updating</li>
<li>The original author was kind enough to release it under the <a href="http://www.gnu.org/licenses/gpl-2.0.html">GPL2 license</a></li>
</ul>
<p>The last version of ShrinkyLink was 0.2, released in 2006.  Today we&#8217;re going to begin the rehabilitation of this plugin and create a version 0.3 that stores all its settings in a single array.</p>
<p>I&#8217;m going to split this into multiple sections:</p>
<ol>
<li>How to set and retrieve settings using arrays</li>
<li>Upgrading your plugin&#8217;s Admin Screen form to use an array</li>
<li>Upgrading existing settings from multiple records to a single array</li>
</ol>
<p>Let&#8217;s get to it.</p>
<p>(...)<br/>Read the rest of <a href="http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/">Consolidate Options with Arrays in your WordPress Plugins</a> (1,731 words)</p>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2008
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/">Permalink to Consolidate Options with Arrays in your WordPress Plugins</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Give your WordPress plugin credit without cluttering the GUI</title>
		<link>http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/</link>
		<comments>http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 13:34:03 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[GUI Goodness]]></category>
		<category><![CDATA[Webcraft]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/?p=73</guid>
		<description><![CDATA[In a previous post I discussed the idea of locating your plugin&#8217;s Settings screen where it made sense within the Admin menus &#8212; giving an example of my own pull-quotes plugin&#8217;s Settings going under the Design menu. I briefly touched on a further aspect of this, when I suggested that authors not make their plugins [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="/nerdaphernalia/2008/06/on-plugin-design/">previous post</a> I discussed the idea of locating your plugin&#8217;s Settings screen where it made sense within the Admin menus &#8212; giving an example of my own pull-quotes plugin&#8217;s Settings going under the Design menu.  I briefly touched on a further aspect of this, when I suggested that authors not make their plugins scream &#8220;This is a plugin!&#8221;</p>
<p><img src="/wp-content/docs/nerd/images/holiday_inn_sign.jpg" alt="A massive neon Holiday Inn sign" title="Ah, the 70s..." style="float: right;" />I&#8217;m sure a lot of people reading that first thought &#8220;But wait!  I put a lot of time into my plugin &#8212; I <em>want</em> people to know that it&#8217;s a plugin!&#8221;  So we end up with an admin screen titled <strong>John&#8217;s Comment Filter Plugin 3.2</strong> or worse, a &#8220;<a href="http://en.wikipedia.org/wiki/Mystery_meat_navigation">mystery meat</a>&#8221; menu item that <a href="#fnote73_1" class="fnotelink">doesn&#8217;t identify what the plugin does at all<sup>1</sup></a>!  That first example is somewhat like having a store with a giant flashing neon sign up front &#8212; it certainly gets the information across, but it&#8217;s not all that attractive, and very obtrusive on the surrounding landscape.</p>
<p>I admit that we&#8217;re riding a line here &#8212; we all want credit for our hard work; but awkward plugin integration, spread out over multiple plugins, can end up making WordPress itself look awfully kludgy.  <span class="pullquote pqLeft"><!-- Our plugins deserve better -->Our blogs, and our plugins, deserve better than that!</span></p>
<p>So, we&#8217;re looking for a way to give credit where credit is due, while maintaining a clean integrated interface that looks as though it were a part of WordPress from the beginning.  First, name the menu item for what the screen is for, not what the plugin is called.  Ditto the page &lt;title&gt; and header.  By way of example, my pull-quotes plugin is called &#8220;JavaScript Pull-Quotes&#8221;, but the Admin screen is under Design -&gt; Pull-Quotes, and the page title and header read &#8220;Pull-Quote Settings&#8221;.  The menu item and page header do <em>not</em> have to match the name of the plugin!</p>
<p>Okay, so&#8230; what if you still want to show the plugin name, and maybe have a link back to the plugin&#8217;s homepage?  Simply allow your eyes to drift downward to the bottom of the admin screen&#8230;</p>
<p><img src="/wp-content/docs/nerd/images/discreet_plugin_attribution.png" height="146" width="469" alt="screenshot" title="" /></p>
<p>There&#8217;s the name of the plugin, the version number, and a link back to the home page; but it&#8217;s discreet and unobtrusive &#8212; it looks as though it belongs there.  The information is there if you&#8217;re interested, but it doesn&#8217;t get in your way if you&#8217;re not; giving us a good balance between giving credit and keeping the GUI clean.  Of course, if enough plugin authors start doing it on all their plugins, people will come to expect that bit of extra info, and that little slice of screen real estate will be as good as gold.</p>
<p>Here&#8217;s how I do it:</p>
<ul>
<li>Within the function that creates the content of the Admin page itself, put the following line (probably best at the very beginning or very end of the function):
<pre><code>add_action( 'in_admin_footer', 'myplugin_admin_footer' );</code>
</pre>
<p>This attaches a function to the page footer that will insert our attribution text.
</li>
<li>Then of course we have to add the footer function itself:
<pre><code>function myplugin_admin_footer() {
	$plugin_data = get_plugin_data( __FILE__ );
	printf('%1$s plugin | Version %2$s&lt;br /&gt;', $plugin_data['Title'], $plugin_data['Version']);
}</code>
</pre>
</li>
</ul>
<p>That&#8217;s pretty straightforward &#8212; all we&#8217;re doing is outputting a line of HTML &#8212; but I should point out a couple of things.  <del datetime="2008-07-02T04:35:59+00:00" title="Removed -- see update note at bottom of article">First, we&#8217;re wrapping it in an <code>if()</code> and checking against <code>$_SERVER['REQUEST_URI']</code> because we don&#8217;t want our plugin&#8217;s attribution showing up on every page.  (Of course, you&#8217;ll have to change the URL string in that <code>if()</code> so it&#8217;s right for your particular page.)</del>  You can use <code>in_admin_footer</code> to insert anything you like, of course, but in the interests of creating something resembling a standard, I hope you consider sticking to the format I give above.  (One alternate that comes to mind, however, is that some people might prefer to use something like &#8220;Comments Filter Plugin | Version 3.2 | By John Smith&#8221;.  Go for it. <img src='http://striderweb.com/nerdaphernalia/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )  I definitely recommend the <code >&lt;br /&gt;</code> at the end of the text you&#8217;re inserting &#8212; otherwise it will be clumped on the same line as the existing text, which will look cluttered and will diminish your own plugin&#8217;s attribution.</p>
<p>We&#8217;ve just torn down the ugly neon sign, and replaced it with an engraved brass plaque next to the door.  Not too bad, that.  In the longer run, this is something that might be nice to roll into core WordPress code, which would <em>really</em> make it a consistent standard.  Until then, it&#8217;s quite easy to give your own plugins credit in a way that cleanly and elegantly integrates with WordPress.</p>
<p class="update">[Update: Ozh improved upon my code a bit by moving the <code>add_action()</code> into the function that creates the Admin page itself.  It simplified things quite nicely, and the code above has been adjusted accordingly.]</p>
<p class="update">[There are updates to this topic <a href="http://striderweb.com/nerdaphernalia/2008/07/wordpress-plugin-attribution-footer-update/">here</a> and <a href="http://striderweb.com/nerdaphernalia/2008/07/on-attribution-and-plugin-priorities-in-wordpress/">here</a>.]</p>
<p class="note">Previously: <a href="/nerdaphernalia/2008/06/wp-use-action-links/">Use Action Links to direct users straight to your WordPress plugin&#8217;s admin page</a></p>
<p class="note">Coming next: <a href="/nerdaphernalia/2008/07/consolidate-options-with-arrays/">Consolidating your plugin&#8217;s settings so you don&#8217;t clutter up users&#8217; <code>wp_options</code> tables</a></p>
<div class="fnote" id="fnote73_1">1: I didn&#8217;t originally intend to name names, but a good example jumped out at me recently.  Under the &#8220;Manage&#8221; menu I have an item called &#8220;<a href="http://joelstarnes.co.uk/pagemash/">pageMash</a>&#8220;.  Quick (no peeking!) &#8212; what does it do???  It&#8217;s an <em>amazing</em> plugin, by the way, just poorly integrated in the menus.</div>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2008
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/">Permalink to Give your WordPress plugin credit without cluttering the GUI</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Use Action Links to direct users straight to your WordPress plugin&#8217;s admin page</title>
		<link>http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/</link>
		<comments>http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 14:30:12 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[GUI Goodness]]></category>
		<category><![CDATA[Webcraft]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/?p=72</guid>
		<description><![CDATA[I&#8217;ve recently come across repeated discussions (especially on the wp-hackers mailing list) debating where plugin authors should place their custom admin pages. I discussed that question directly in my previous post, and basically stated that the plugin&#8217;s admin page can go any number of places, depending on what the plugin does. Some people disagree with [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently come across repeated discussions (especially on the <a href="http://lists.automattic.com/mailman/listinfo/wp-hackers">wp-hackers mailing list</a>) debating where plugin authors should place their custom admin pages.  I discussed that question directly in my <a href="/nerdaphernalia/2008/06/on-plugin-design/" title="Nerdaphernalia: On Plugin Design and Integration">previous post</a>, and basically stated that the plugin&#8217;s admin page can go any number of places, depending on what the plugin does.  Some people disagree with this argument, saying that <strong>all</strong> plugin admin screens should go under one menu &#8212; usually &#8220;Settings&#8221; or &#8220;Plugins&#8221;, depending on whom you ask.</p>
<p><span class="pullquote">While I disagree, they do raise one good point</span>:  many end users will have trouble finding your admin page because they have come to expect such pages to all be dumped under Settings.  Many plugin authors solve this by hard coding a link into the plugin Description, but this really isn&#8217;t the right place for that, and it can create inappropriate clutter in <a class="fnotelink" href="#fnote72_1">certain situations<sup>1</sup></a>.  There is a better way.</p>
<p>WordPress 2.5 makes it fairly easy for plugin authors to add &#8220;action&#8221; links to the Plugin Management screen, like so:</p>
<p><img src="/wp-content/docs/nerd/images/plugin_action_link.gif" alt='Screen shot of a "Settings" link next to the normal plugin "Deactivate" link' title="" height="68" width="488" /><br />
(...)<br/>Read the rest of <a href="http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/">Use Action Links to direct users straight to your WordPress plugin&#8217;s admin page</a> (522 words)</p>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2008
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/">Permalink to Use Action Links to direct users straight to your WordPress plugin&#8217;s admin page</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

