<?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; settings</title>
	<atom:link href="http://striderweb.com/nerdaphernalia/tag/settings/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.2</generator>
		<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>33</slash:comments>
		</item>
	</channel>
</rss>

