<?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>Ptah Dunbar &#187; WordPress</title>
	<atom:link href="http://ptahdunbar.com/blog/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://ptahdunbar.com</link>
	<description>Web Craftsman, WordPress &#38; BuddyPress hacker, and Entrepreneur</description>
	<lastBuildDate>Wed, 17 Mar 2010 14:53:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<atom:link rel='hub' href='http://ptahdunbar.com/?pushpress=hub'/>
		<item>
		<title>Hold your horses, it&#8217;s alpha software.</title>
		<link>http://ptahdunbar.com/wordpress/hold-your-horses-its-alpha-software/</link>
		<comments>http://ptahdunbar.com/wordpress/hold-your-horses-its-alpha-software/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 14:45:37 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=968</guid>
		<description><![CDATA[I&#8217;m noticing a recurring event in the WordPress community that has happened before back when WordPress version 2.7 was in development. However this time, I&#8217;m on the other side of the fence.
Late 2008, WordPress version 2.7 was in development and the backend interface was to receive a new facelift based on the usability testing conducted&#8211;code [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m noticing a recurring event in the WordPress community that has happened before back when WordPress version 2.7 was in development. However this time, I&#8217;m on the other side of the fence.</p>
<p>Late 2008, WordPress version 2.7 was in development and the backend interface was to receive a new facelift based on the usability testing conducted&#8211;code name <a href="http://wordpress.org/development/2008/10/usability-testing-report-25-and-crazyhorse/">Crazy Horse</a>. This was a major change to the interface and <a href="http://weblogtoolscollection.com/archives/2008/09/02/first-look-at-wordpress-27/">it didn&#8217;t come welcomed when the community first saw the base UI-sans design in trunk</a>. I was even a bit frustrated as it looked horrible. Despite knowing that WordPress was still in development, the community started throwing negative criticism thinking that the barebones UI was the final look. However little did we know that the actual &#8220;design&#8221; was being actively worked on by Matt Thomas and the community was basing their negative criticism off of alpha software. Low and behold, <a href="http://wordpress.org/development/2008/10/the-visual-design-of-27/">the design was finally committed to trunk and everyone loved it</a>!</p>
<p>Now in version 3.0, <a href="http://wpdevel.wordpress.com/2010/02/04/suggest-agenda-items-for-feb-11th-2010-d/comment-page-1/#comment-4810">we&#8217;re getting a new menu management system</a>. This is going to be a highly used feature so there&#8217;s been a lot of critiquing and concern about it&#8217;s current state. Days after the original feature freeze (Feb 15th), <a href="http://core.trac.wordpress.org/changeset/13257">WooThemes navigation system was contributed into WordPress</a>. The community was grateful of WooThemes, but also concerned about the feature freeze deadline and getting the system integrated into core from a UI and coding perspective. So in addition to a several other developers, I stepped in and we all started reworking the codebase and making the UI more inline with WP&#8217;s UI conventions.</p>
<p>Long story short, after one of my patches <a href="http://core.trac.wordpress.org/changeset/13704/">got committed</a>, <a href="http://wpdevel.wordpress.com/2010/03/16/im-kind-of-thrown-by-what-has-turned-u/">Jane Wells</a> posted her thoughts on it&#8217;s current <em>in-development</em> state along with comments pretty much +1&#8242;ing her concerns. The gist of her post was summed up to WP needing &#8220;a *basic* menu feature that plugins can build on.&#8221;</p>
<p>And the irony being that that&#8217;s <em>exactly</em> <a href="http://core.trac.wordpress.org/changeset/13393">what</a> <a href="http://core.trac.wordpress.org/changeset/13395">my</a> <a href="http://core.trac.wordpress.org/changeset/13473">patches</a> <a href="http://core.trac.wordpress.org/changeset/13512">were</a> <a href="http://core.trac.wordpress.org/changeset/13704">doing</a>. I cleaned up the interface and I reworked the codebase to make it easier for plugin authors to add their own menu item types. So now with the <a href="http://core.trac.wordpress.org/attachment/ticket/11817/menus_super_nova.diff">menu super nova patch</a> in, the underlying code to support any post type and taxonomy is there which is pretty much what plugin authors will want to extend in Menus. Before this patch, it wasn&#8217;t possible. And because that patch was already huge, I moved everything over to the next patch sprint which was to limit the UI&#8217;s menu item types to just pages and categories with the additional post types and taxonomies being disabled from the screen. To enable them would just be a checkbox away in the screen options tab. <strong>But</strong> before that could even happen, the menus system is being criticized—<em>just like crazy horse</em>—as if everything was final when we haven&#8217;t even hit beta yet.</p>
<p>My point is, hold off on any negative criticism regarding the development of alpha software. Features are still being actively fine-tuned and bugs are still being ironed out. So hold your horses, it&#8217;s alpha software.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/hold-your-horses-its-alpha-software/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Round 2: Preset Widgets to Widget Areas</title>
		<link>http://ptahdunbar.com/wordpress/round-2-preset-widgets-to-widget-areas/</link>
		<comments>http://ptahdunbar.com/wordpress/round-2-preset-widgets-to-widget-areas/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 01:07:39 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=939</guid>
		<description><![CDATA[A while ago, I wrote about how to preset widgets to widget areas (sidebars) in themes, but that method doesn&#8217;t work anymore with the new multi-widget implementation. Here&#8217;s the new way:
Step 1: Add a new instance of the widget to the options table
update_option( 'widget_search', array( 2 =&#62; array( 'title' =&#62; '' ), '_multiwidget' =&#62; 1 ) [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I wrote about <a href="http://ptahdunbar.com/wordpress/droppin-knowledge-on-wordpress-how-to-preset-widgets-to-widget-areas/">how to preset widgets to widget areas</a> (sidebars) in themes, but that method doesn&#8217;t work anymore with the new multi-widget implementation. Here&#8217;s the new way:</p>
<h3><em>Step 1</em>: Add a new instance of the widget to the options table</h3>
<pre>update_option( 'widget_search', array( 2 =&gt; array( 'title' =&gt; '' ), '_multiwidget' =&gt; 1 ) );</pre>
<p>Parameters:</p>
<ul>
<li>Prefix <code>widget_</code> with the <em>id base</em> of the Widget&#8217;s class.</li>
<li>A two-dimensional array with:
<ul>
<li>the first array containing the widget&#8217;s settings</li>
<li>and the second containing the required: <code>'_multiwidget' =&gt; 1</code></li>
</ul>
</li>
</ul>
<p class="note">Note: In the second parameter of <code>update_option</code>, I gave the array a key value of <strong>2</strong>. This number is <em>intentionally</em> there. More on that in step 2.</p>
<p>Do as many of those <code>update_option</code> calls for each widget instance you&#8217;d like to register. Then move along to step two:</p>
<h3><em>Step 2</em>: Update the sidebars options table</h3>
<pre>update_option( 'sidebars_widgets', array(
	'sidebar-1' =&gt; array(
		'search-2',
	),
	'wp_inactive_widgets' =&gt; array(),
	'array_version' =&gt; 3
));</pre>
<p>The only thing you have to change here is the array in the second parameter:</p>
<ul>
<li>The array keys should be the <em>id</em> of the widget area
<ul>
<li>And it&#8217;s values should be the <em>id base</em> of the widget&#8217;s class, a dash, and then the same number we used as a key for the widget (created in step 1). In this case, it&#8217;s <strong>2</strong>.</li>
</ul>
</li>
</ul>
<p>You may optionally preset widgets as inactive by throwing them in the <code>wp_inactive_widgets</code> array. And I wouldn&#8217;t mess with the array_version array. This is a hack since we&#8217;re not using any proper APIs to preset widgets so don&#8217;t go messing around with too much.</p>
<p>Et volia! You just perform the equivalent of selecting a widget from the available widgets section, dragging that instance over to a widget area, configured it, and saved the changes.. all through code!</p>
<p><a href="http://ptahdunbar.com/wp-content/uploads/2010/02/preset-widgets.php_.txt">Here&#8217;s the complete code</a> along with additional sidebars and widgets so you see how that looks.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/round-2-preset-widgets-to-widget-areas/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Introducing The Devel Plugin</title>
		<link>http://ptahdunbar.com/wordpress/introducing-the-devel-plugin/</link>
		<comments>http://ptahdunbar.com/wordpress/introducing-the-devel-plugin/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 16:29:27 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=918</guid>
		<description><![CDATA[Over the years, I&#8217;ve built up quiet the library of &#8220;mini&#8221; plugins that I use during plugin and theme development. They&#8217;ve provided me with a ton of value and I&#8217;d like to share them with you. But instead of releasing a ton of small mini plugins geared around the same idea, that is, helping out [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, I&#8217;ve built up quiet the library of &#8220;mini&#8221; plugins that I use during plugin and theme development. They&#8217;ve provided me with a ton of value and I&#8217;d like to share them with you. But instead of releasing a ton of small mini plugins geared around the same idea, that is, helping out during plugin and theme development&#8230; I figured why not just release one container plugin to house them all. Say hello to <a title="The Devel Plugin" href="http://ptahdunbar.com/plugins/devel">Devel</a>.</p>
<h3>Devel</h3>
<p><a href="http://ptahdunbar.com/plugins/devel">Devel is a WordPress plugin</a> made up of &#8220;components&#8221; (which are the mini plugins) which can be activated or deactivated so you only use what you need. For the 0.1 release, I&#8217;ve bundled only one component with devel and that is the <em>Custom Fields Manager</em>.</p>
<h3>Custom Fields Manager</h3>
<p>The Custom Fields Manager component displays a listing of all custom fields available in your WordPress site. This is handy for when over the years, you&#8217;ve used a few dozen custom fields and would like to pin point all the posts that their used in to maybe modify or delete them. Well with the Custom Fields Manager, you can. In addition, you can edit a custom field to update it&#8217;s <code>meta_key</code> value, which will update all of it&#8217;s instances on your site. This is useful for when you&#8217;ve misspelled a custom field in one of your posts, or if a plugin changed which custom field it needs you to use. Finally, with Custom Fields Manager, you can delete individual custom fields or delete them in bulk. And that&#8217;s what you can expect from the Custom Fields Manager component. It provides very handy administrative task for managing your custom fields.</p>
<h3>The Components API</h3>
<p>In addition, there&#8217;s a neat components API built in so you can add your own components to the list. I&#8217;m not the only developer with a library of useful mini plugins, so devel allows you to bundle your own set. Thanks to <a href="http://justintadlock.com">Justin Tadlock</a> and his <a href="http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin">Members plugin</a> which is where I got the components idea from.</p>
<h3><a href="http://downloads.wordpress.org/plugin/devel.zip">Download Devel Now</a>.</h3>
<p>P.S. Once I polish up all of my mini plugins, I&#8217;ll gradually add them as components to devel. For now, enjoy the CFM.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/introducing-the-devel-plugin/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Comments Loop Widget</title>
		<link>http://ptahdunbar.com/wordpress/the-comments-loop-widget/</link>
		<comments>http://ptahdunbar.com/wordpress/the-comments-loop-widget/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 01:30:34 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=905</guid>
		<description><![CDATA[Last week I introduced the WordPress Loop widget which received a positive response from the community with over 600 downloads. Today I&#8217;d like to introduce it&#8217;s companion, the Comments Loop widget.
With the comments loop widget, you now have that always-a-hassle-to-create comments.php file completely revamped and widgetized. You can have multiple instances of the comments loop widget [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I introduced <a href="http://ptahdunbar.com/wordpress/the-wordpress-loop-widget/">the WordPress Loop widget</a> which received a positive response from the community with over <em>600</em> downloads. Today I&#8217;d like to introduce it&#8217;s companion, <a href="http://ptahdunbar.com/plugins/comments-loop/">the Comments Loop widget</a>.</p>
<p>With the comments loop widget, you now have that <em>always-a-hassle-to-create</em> comments.php file completely <em>revamped</em> and <em>widgetized</em>. You can have multiple instances of the comments loop widget for each comment type, easily allowing you to separate comments from trackbacks.</p>
<p>I&#8217;ll let the widget settings do the talking:<br />
<a href="http://ptahdunbar.com/wp-content/uploads/2010/01/screenshot-11.png"><img class="alignnone size-medium wp-image-908" title="Comments Loop Widget Settings" src="http://ptahdunbar.com/wp-content/uploads/2010/01/screenshot-11-300x205.png" alt="Comments Loop Widget Settings" width="300" height="205" /></a></p>
<p>Oh, and there&#8217;s more&#8230;</p>
<p>You know a comments loop widget wouldn&#8217;t be complete without the comments form:<br />
<a href="http://ptahdunbar.com/wp-content/uploads/2010/01/screenshot-2.png"><img class="alignnone size-medium wp-image-907" title="Comments Form Widget Settings" src="http://ptahdunbar.com/wp-content/uploads/2010/01/screenshot-2-300x226.png" alt="Comments Form Widget Settings" width="300" height="226" /></a></p>
<p>With the <a title="Comments Loop widget" href="http://ptahdunbar.com/plugins/comments-loop/">Comments Loop widget</a> in your arsenal, you&#8217;ll never need to edit your <code>comments.php</code> file again. Just create a new sidebar in any of your singular based templates (e.g. single.php, page.php, attachment.php). All the wording is editable from the widgets admin, all elements have semantic css class/id names, and if you love hooks, <a href="http://wordpress.org/extend/plugins/comments-loop/faq/">there&#8217;s plenty of those</a>.</p>
<p><a href="http://downloads.wordpress.org/plugin/comments-loop.zip">Download it now.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/the-comments-loop-widget/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>The WordPress Loop Widget</title>
		<link>http://ptahdunbar.com/wordpress/the-wordpress-loop-widget/</link>
		<comments>http://ptahdunbar.com/wordpress/the-wordpress-loop-widget/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 15:15:15 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=871</guid>
		<description><![CDATA[WordPress has definitely beefed up support for widgets making it easier than ever to instantiate multiple widgets without too much hassle. I&#8217;ve been meaning to build a plethora of features based off the new system. The first on my list was to wigitize the WordPress loop. So here we go&#8230;
With the WordPress Loop widget, you&#8217;ll be [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress has definitely beefed up support for widgets making it easier than ever to instantiate multiple widgets without too much hassle. I&#8217;ve been meaning to build a plethora of features based off the new system. The first on my list was to wigitize the WordPress loop. So here we go&#8230;</p>
<p>With the <a href="http://ptahdunbar.com/plugins/wordpress-loop/">WordPress Loop widget</a>, you&#8217;ll be able to create custom loops for your content, and display them exactly how you like—all without touching any code! It&#8217;s got all the bells and whistles you&#8217;d might expect:</p>
<div id="attachment_880" class="wp-caption alignnone" style="width: 310px"><a href="http://ptahdunbar.com/wp-content/uploads/2010/01/screenshot-1.png"><img class="size-medium wp-image-880" title="Screenshot of the WordPress Loop widget settings" src="http://ptahdunbar.com/wp-content/uploads/2010/01/screenshot-1-300x171.png" alt="" width="300" height="171" /></a><p class="wp-caption-text">Click on the screenshot to view bigger version</p></div>
<p>Of course if you know your way around PHP, then there&#8217;s <a href="http://wordpress.org/extend/plugins/wordpress-loop/other_notes/">4 well-placed action hooks</a> you can hook into.</p>
<p><a href="http://downloads.wordpress.org/plugin/wordpress-loop.zip">Download it now</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/the-wordpress-loop-widget/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Consolidate Options with Arrays in your WordPress Themes</title>
		<link>http://ptahdunbar.com/wordpress/consolidate-options-with-arrays-in-your-wordpress-themes/</link>
		<comments>http://ptahdunbar.com/wordpress/consolidate-options-with-arrays-in-your-wordpress-themes/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 00:38:14 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=788</guid>
		<description><![CDATA[As more and more themes start growing in complexity and features, storing information in the database is a natural progression towards saving any user preferences for that particular theme. In this article we&#8217;re going to talk about how you can consolidate all those theme options into a single database entry. Then we&#8217;re going to create [...]]]></description>
			<content:encoded><![CDATA[<p>As more and more themes start growing in complexity and features, storing information in the database is a natural progression towards saving any user preferences for that particular theme. In this article we&#8217;re going to talk about how you can consolidate all those theme options into a single database entry. Then we&#8217;re going to create a set of functions to easily interface with those options for use throughout your template files.</p>
<p>In this example, we&#8217;re going to look at the popular k2 theme and see what it takes to consolidate their settings into one single database entry.</p>
<p>Upon installation, k2 runs an install function that adds several settings into the database.</p>
<pre>function install() {
	add_option( 'k2version', K2_CURRENT );
	add_option( 'k2asidescategory', '0' );
	add_option( 'k2livesearch', '1' );
	add_option( 'k2rollingarchives', '1' );
	add_option( 'k2archives', '0' );
	add_option( 'k2sidebarmanager', '0' );
	add_option( 'k2columns', '2' );

	// Added 1.0-RC8
	add_option( 'k2animations', '1' );
	add_option( 'k2entrymeta1', __('Published on %date% in %categories%. %comments% %tags%', 'k2_domain') );
	add_option( 'k2entrymeta2', '' );
	add_option( 'k2widgetoptions', array() );

	$defaultjs = "// Lightbox v2.03.3 - Adds new images to lightbox\nif (typeof myLightbox != 'undefined' &amp;&amp; myLightbox instanceof Lightbox &amp;&amp; myLightbox.updateImageList) {\n\tmyLightbox.updateImageList();\n}\n";
	add_option( 'k2ajaxdonejs', $defaultjs );
}</pre>
<p>We&#8217;re going to recreate that install function, but first, lets add a new function that stores the default values for each option as an array:</p>
<pre>function k2_default_options() {
	$defaultjs = "// Lightbox v2.03.3 - Adds new images to lightbox\nif (typeof myLightbox != 'undefined' &amp;&amp; myLightbox instanceof Lightbox &amp;&amp; myLightbox.updateImageList) {\n\tmyLightbox.updateImageList();\n}\n";
	$options = array(
		'version' =&gt; K2_CURRENT,
		'asidescategory' =&gt; false,
		'livesearch' =&gt; true,
		'rollingarchives' =&gt; true,
		'archives' =&gt; false,
		'sidebarmanager' =&gt; false,
		'archives' =&gt; false,
		'columns' =&gt; '2',
		'animations' =&gt; true,
		'entrymeta1' =&gt; __('Published on %date% in %categories%. %comments% %tags%', 'k2_domain'),
		'entrymeta2' =&gt; '',
		'widgetoptions' =&gt; array(),
		'ajaxdonejs' =&gt; $defaultjs,
	);
	return $options;
}</pre>
<p>You&#8217;ll noticed that I removed all prefixes of k2 as their not needed when everything is being stored under one entry. I also converted all the 0&#8217;s and 1&#8217;s into their boolean values. Now let&#8217;s recreate the install function:</p>
<pre>function install() {
	add_option( 'kaytwo', k2_default_options() );
}</pre>
<p>It&#8217;s as simple as that. Retrieving those values is just as easy:</p>
<pre>$kaytwo = get_option( 'kaytwo' );

echo $kaytwo['version'];
echo $kaytwo['columns'];
echo $kaytwo['entrymeta1'];</pre>
<p>Updating options involves retrieving the entire options array and updating only those that need to be updated.</p>
<pre>$kaytwo = get_option( 'kaytwo' );

$kaytwo['version'] = '1.0';
$kaytwo['columns'] = '4';
$kaytwo['entrymeta2'] = __('Posted in %categories%. Tagged: %tags%', 'k2_domain');

update_option( 'kaytwo', $kaytwo );</pre>
<p class="warning">Remember to include <strong>all options</strong>, even those that are not being updated themselves. Failure to do so removes those options from the database <em>completely</em>.</p>
<p>Deleting an option is similar to updating. Retrieve the entire options array and unset those that need to be removed:</p>
<pre>$kaytwo = get_option( 'kaytwo' );

unset( $kaytwo['sidebarmanager'] );
unset( $kaytwo['asidescategory'] );

update_option( 'kaytwo', $kaytwo );</pre>
<p>And that&#8217;s how you would consolidate all your options under a single database entry. But why stop here? Since we&#8217;re going to be interfacing with the database all throughout our WordPress theme, let&#8217;s make these calls into functions.</p>
<pre>define( 'THEMEOPTIONS', 'kaytwo' );

/**
 * Returns the value of an option from the db if it exists.
 *
 * @since 0.4
 *
 * @param string $name Option Name.
 * @return mixed Returns the option's value if it exists, false if it doesn't.
 */
function framework_get_option( $name ) {
	$options = get_option( THEMEOPTIONS );
	if ( isset($options[$name]) ) {
		return $options[$name];
	} else {
		return false;
	}
}

/**
 * Adds an option to the options db.
 *
 * @since 0.4
 *
 * @param string $name Option Name. Must be unique.
 * @param mixed $value Option Value.
 * @return bool True on success, false if the option already exists.
 */
function framework_add_option( $name, $value ) {
	$options = get_option( THEMEOPTIONS );
	if ( $options and !isset($options[$name]) ) {
		$options[$name] = $value;
		return update_option( THEMEOPTIONS, $options );
	} else {
		return false;
	}
}

/**
 * Updates an option to the options db.
 *
 * @since 0.4
 *
 * @param string $name Option Name. Must be unique.
 * @param mixed $value Option Value.
 * @return bool true|false
 */
function framework_update_option( $name, $value ) {
	$options = get_option( THEMEOPTIONS );
	if ( $value != $options[$name] ) {
		$options[$name] = $value;
		return update_option( THEMEOPTIONS, $options );
	} else {
		return false;
	}
}

/**
 * Deletes an option from the options db.
 *
 * @since 0.4
 *
 * @param string $name Option Name. Must be unique.
 * @return bool true|false
 */
function framework_delete_option( $name ) {
	$options = get_option( THEMEOPTIONS );
	if ( $options[$name] ) {
		unset( $options[$name] );
		return update_option( THEMEOPTIONS, $options );
	} else {
		return false;
	}
}</pre>
<p>Just define <code>THEMEOPTIONS</code> as the name of the database entry and your all set.</p>
<p>To read more on this topic, check out this post on <a href="http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/">Striderweb</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/consolidate-options-with-arrays-in-your-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smarter Hooks: Contextual Hooks</title>
		<link>http://ptahdunbar.com/wordpress/smarter-hooks-contextual-hooks/</link>
		<comments>http://ptahdunbar.com/wordpress/smarter-hooks-contextual-hooks/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 20:06:26 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[droppin' knowledge on WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=770</guid>
		<description><![CDATA[The article has been updated with a working example on how I&#8217;ve implemented the atomic hook approach in WP Framework. It&#8217;s also WordPress 2.9 compatible for custom post types and taxonomies.
In the last article, we looked at a simple way for making your template files more cleaner and DRY using do_atomic(), a function that registers [...]]]></description>
			<content:encoded><![CDATA[<p class="note">The article has been updated with a working example on how I&#8217;ve implemented the atomic hook approach in WP Framework. It&#8217;s also WordPress 2.9 compatible for custom post types and taxonomies.</p>
<p><a href="http://ptahdunbar.com/wordpress/smarter-hooks/">In the last article</a>, we looked at a simple way for making your template files more cleaner and <abbr title="Don't Repeat Yourself">DRY</abbr> using <code>do_atomic()</code>, a function that registers three predefined <code>do_actions()</code> for any particular location. In this article, we&#8217;re going to step it up a notch and talk about context and how we can create context sensitive action hooks.</p>
<p>Let&#8217;s talk about what we can do now. WordPress allows you to create action hooks at any point in your WordPress theme to allow other functions to be executed at that particular location. Well that&#8217;s pretty cool. But what about context? If you&#8217;ve ever used any sandbox-based theme, you should be familiar with the class generating functions it pours into the body tag and other sections throughout your theme. Those functions give CSS clear context as to what page is being displayed and a lot more specifics.</p>
<p>So if we had a <code>#header</code> div that displayed our site&#8217;s name and tagline, those class generating functions would allow us to style the <code>#header</code> div differently for pages, archives, or any other template without adding any <code>if, else</code> logic to the actual template file.</p>
<pre>&lt;!--BEGIN #header--&gt;
&lt;div id="header"&gt;
	&lt;h1 id="logo"&gt;&lt;a href="&lt;?php bloginfo( 'url' ); ?&gt;"&gt;&lt;?php bloginfo( 'name' ) ?&gt;&lt;/a&gt;&lt;/h1&gt;
	&lt;p id="tagline"&gt;&lt;?php bloginfo( 'description' ) ?&gt;&lt;/p&gt;
&lt;!--END #header--&gt;
&lt;/div&gt;</pre>
<pre>#header { background-image: url( '../images/header.jpg' ); }
.page #header { background-image: url( '../images/header-page.jpg' ); }
.single #header { background-image: url( '../images/header-single.jpg' ); }</pre>
<p>So that got me thinking, why not do this for action hooks too?</p>
<p class="alert"><a href="http://ptahdunbar.com/wordpress/smarter-hooks-contextual-hooks/#comment-4482">Chris Jean</a> wrote another version of the <code>get_context()</code> function which you should definitely  <a href="http://new.gaarai.com/pd_hierarchy_context.phps">check out</a>.</p>
<pre>/**
 * Retrive the context of the queried template.
 *
 * @since 0.4
 * @return array $query_context
 */
function get_query_context() {
	global $wp_query, $query_context;

	/* If $query_context-&gt;context has been set, don't run through the conditionals again. Just return the variable. */
	if ( is_array( $query_context-&gt;context ) )
		return $query_context-&gt;context;

	$query_context-&gt;context = array();

	/* Front page of the site. */
	if ( is_front_page() )
		$query_context-&gt;context[] = 'home';

	/* Blog page. */
	if ( is_home() )
		$query_context-&gt;context[] = 'blog';

	/* Singular views. */
	elseif ( is_singular() ) {
		$query_context-&gt;context[] = 'singular';
		$query_context-&gt;context[] = "singular-{$wp_query-&gt;post-&gt;post_type}";
		$query_context-&gt;context[] = "singular-{$wp_query-&gt;post-&gt;post_type}-{$wp_query-&gt;post-&gt;ID}";
	}

	/* Archive views. */
	elseif ( is_archive() ) {
		$query_context-&gt;context[] = 'archive';

		/* Taxonomy archives. */
		if ( is_tax() || is_category() || is_tag() ) {
			$term = $wp_query-&gt;get_queried_object();
			$query_context-&gt;context[] = 'taxonomy';
			$query_context-&gt;context[] = $term-&gt;taxonomy;
			$query_context-&gt;context[] = "{$term-&gt;taxonomy}-" . sanitize_html_class( $term-&gt;slug, $term-&gt;term_id );
		}

		/* User/author archives. */
		elseif ( is_author() ) {
			$query_context-&gt;context[] = 'user';
			$query_context-&gt;context[] = 'user-' . sanitize_html_class( get_the_author_meta( 'user_nicename', get_query_var( 'author' ) ), $wp_query-&gt;get_queried_object_id() );
		}

		/* Time/Date archives. */
		else {
			if ( is_date() ) {
				$query_context-&gt;context[] = 'date';
				if ( is_year() )
					$query_context-&gt;context[] = 'year';
				if ( is_month() )
					$query_context-&gt;context[] = 'month';
				if ( get_query_var( 'w' ) )
					$query_context-&gt;context[] = 'week';
				if ( is_day() )
					$query_context-&gt;context[] = 'day';
			}
			if ( is_time() ) {
				$query_context-&gt;context[] = 'time';
				if ( get_query_var( 'hour' ) )
					$query_context-&gt;context[] = 'hour';
				if ( get_query_var( 'minute' ) )
					$query_context-&gt;context[] = 'minute';
			}
		}
	}

	/* Search results. */
	elseif ( is_search() )
		$query_context-&gt;context[] = 'search';

	/* Error 404 pages. */
	elseif ( is_404() )
		$query_context-&gt;context[] = 'error-404';

	return $query_context-&gt;context;
}</pre>
<p><code>get_query_context()</code> returns an array containing the context of the current queried template. And it only runs once per page, even if there are multiple calls to it, so there&#8217;s no performance lost. <code>get_query_context()</code> is also custom post type aware.</p>
<p>Now, that we have some context, let&#8217;s put it into action. Here&#8217;s the new and suped-up <code>do_action()</code> — <code>do_atomic()</code>:</p>
<pre>function do_atomic( $tag = '', $args = '' ) {
	if ( !$tag )
		return false;

	/* Do actions on the basic hook. */
	do_action( $tag, $args );

	/* Loop through context array and fire actions on a contextual scale. */
	foreach ( (array) get_query_context() as $context )
		do_action( "{$tag}_{$context}", $args );
}</pre>
<p>So now using <code>do_atomic()</code>, we can treat our action hooks just like we always did. In addition, <code>do_atomic()</code> registers up to <em>22 different contexts</em>, so if you&#8217;d like to display something specific to page templates or archives-based templates, <code>do_atomic()</code> allows you to do so without creating any additional code.</p>
<p>Let&#8217;s go back to our header.php and replace the #header div with this:</p>
<pre>&lt;!--BEGIN #header--&gt;
&lt;div id="header"&gt;
	&lt;?php do_atomic( 'theme_header' ); ?&gt;
&lt;!--END #header--&gt;
&lt;/div&gt;</pre>
<p>And now, when a user queries a page template, you&#8217;ll have four actions fired in this order:</p>
<ol>
<li><span style="font-family: monospace, 'Times New Roman', 'Bitstream Charter', Times, serif;">add_action( &#8216;theme_header&#8217;, &#8216;my_custom_header&#8217; );</span></li>
<li><span style="font-family: monospace, 'Times New Roman', 'Bitstream Charter', Times, serif;">add_action( &#8216;theme_header_singular&#8217;, &#8216;my_custom_singular_header&#8217; );</span></li>
<li><span style="font-family: monospace, 'Times New Roman', 'Bitstream Charter', Times, serif;">add_action( &#8216;theme_header_page&#8217;, &#8216;my_custom_page_header&#8217; );</span></li>
<li><span style="font-family: monospace, 'Times New Roman', 'Bitstream Charter', Times, serif;">add_action( &#8216;theme_header_page-id-5&#8242;, &#8216;my_custom_page_foobar_header&#8217; );</span></li>
</ol>
<p>This way, you can specify a variety of looks for the header all while keeping your template files and functions clean and clutter free of <code>if, else</code> and <code>is_*</code> statements. And if by any chance you have more than one of those contextual hooks fired on a given page, simple call <code>remove_action();</code> so only the desired one gets executed.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/smarter-hooks-contextual-hooks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Smarter Hooks</title>
		<link>http://ptahdunbar.com/wordpress/smarter-hooks/</link>
		<comments>http://ptahdunbar.com/wordpress/smarter-hooks/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 12:19:50 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[droppin' knowledge on WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=763</guid>
		<description><![CDATA[Now that everyone&#8217;s finally understanding the benefits of using theme frameworks and the like, I&#8217;m noticing a lot more hooks in themes:
theme_before_location();
theme_location();
theme_after_location();
Where location is the location of that particular hook (e.g. header, footer, loop). Now that&#8217;s great and all, but here&#8217;s a smarter way:
do_atomic( 'location' );
Where do_atomic is:
// Registers three action hooks at once.
function do_atomic( [...]]]></description>
			<content:encoded><![CDATA[<p>Now that everyone&#8217;s finally understanding the benefits of using theme frameworks and the like, I&#8217;m noticing a lot more hooks in themes:</p>
<pre>theme_before_location();
theme_location();
theme_after_location();</pre>
<p>Where location is the location of that particular hook (e.g. header, footer, loop). Now that&#8217;s great and all, but here&#8217;s a smarter way:</p>
<pre>do_atomic( 'location' );</pre>
<p>Where do_atomic is:</p>
<pre>// Registers three action hooks at once.
function do_atomic( $location = '' ) {
	if ( !isset($location) ) return;

	do_action( "theme_before_{$location}" );
	do_action( "theme_{$location}" );
	do_action( "theme_after_{$location}" );
}</pre>
<p>Makes for much cleaner template files. The next article on smarter hooks will take this concept to an even higher level.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/smarter-hooks/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>On using WordPress Theme Frameworks</title>
		<link>http://ptahdunbar.com/wordpress/on-using-wordpress-theme-frameworks/</link>
		<comments>http://ptahdunbar.com/wordpress/on-using-wordpress-theme-frameworks/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 22:04:57 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=732</guid>
		<description><![CDATA[In my last post, Kel from BadCat design brought up a very important question about theme frameworks that needs to be discussed:
On the same path… If you have a child theme (I’ll use Ian Stewart’s pro/paid Thematic child theme called Power Blog, as the example) and want to customize that &#8211; what do you do? [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://ptahdunbar.com/wordpress/does-your-theme-have-children/">last post</a>, Kel from <a href="http://www.badcat.com/">BadCat design</a> brought up a very important question about theme frameworks that needs to be discussed:</p>
<blockquote cite="http://ptahdunbar.com/wordpress/does-your-theme-have-children/#comment-3372"><p>On the same path… If you have a child theme (I’ll use Ian Stewart’s pro/paid Thematic child theme called Power Blog, as the example) and want to customize that &#8211; what do you do? Currently we’re talking about customizing themes by using Child Themes. If I wanted to make mods to Power Blog, I’d have to change the child theme directly, thus negating some of the reasons for using a Child theme &#8211; like upgradability.</p>
<p>Do we get to a day where we need grandchildren themes? I think your code might be the start of a way to “group” the family theme files together. -<a href="http://ptahdunbar.com/wordpress/does-your-theme-have-children/#comment-3372">Kel</a></p></blockquote>
<p>The day WordPress starts talking about &#8220;grandchild&#8221; themes is the same day I&#8217;ll convert all my blogs over to <span style="text-decoration: line-through;">movable type</span> Habari.</p>
<p>Way back when I started talking about <a href="http://ptahdunbar.com/projects/wp-framework/brainstorming-a-wordpress-theming-framework/">theme frameworks</a>, I talked about how <a href="http://wpframework.com">WP Framework</a> stands out:</p>
<blockquote><p>One of the main design goals I wanted to achieve with WP Framework that differentiates it from other frameworks is the fact that <strong><em>it’s not styled</em></strong>.</p></blockquote>
<p>A <a href="http://wpframework.com">WordPress theme framework</a> <strong>should be design-agnostic</strong>. That&#8217;s why it&#8217;s a <a href="http://www.google.com/search?q=define%3Aframework"><em>framework</em></a>. It should only contain the building blocks and the most essential code (by the way, <a href="http://wpframework.com/versions/024-release/">WP Framework 0.2.4</a> has just be released!).</p>
<p><a href="http://carringtontheme.com">Carrington</a> gets it. <a href="http://alexking.org">Alex King</a> built <a href="http://carrington.googlecode.com/svn/framework/trunk/">a base framework</a> of carrington, basically extracted all the template logic and things that made his theme work into a &#8220;core&#8221; framework. <a href="http://carringtontheme.com/themes/">When he builds themes off of carrington</a>, he simply extends the core framework by building on top of it; <strong>not</strong> via a child theme.</p>
<p>So if users of <a href="http://blog.carringtontheme.com/">Carrington blog</a> wanted to customize it, they would create a child theme for it and modify it accordingly. Here&#8217;s two possible scenario&#8217;s that show the benefits of what I&#8217;m describing:</p>
<ul class="fat">
<li>Carrington blog gets an update that includes a new section above the sidebar (a feature dealing with the design, not the logic). Users would simply download/update Carrington blog and the new section would appear above the sidebar as expected. All of the user&#8217;s changes for Carrington is preserved and left intact via the child theme.</li>
<li>But let&#8217;s say Carrington framework fixes a bug in it&#8217;s atomic template system (an issue dealing with the framework logic, not the design). There would be an update available to <a href="http://carringtontheme.com/themes/">all themes based on carrington</a>, and users would simply download/update carrington blog (or which ever theme based on Carrington they have) and the fix gets applied. The user&#8217;s modifications to Carrington blog are left intact via the child theme.</li>
</ul>
<p>It&#8217;s important to think of a theme framework as the logic of the theme, not the design or the underlying xHTML.</p>
<h3>To put this into a step by step process:</h3>
<ol>
<li>Start with a blank WordPress theme framework</li>
<li>Create your WordPress theme based off said framework</li>
<li>Now to customize this WordPress theme (which is essentially the first two steps combined), create a child theme for it.</li>
</ol>
<p>That&#8217;s how WordPress theme frameworks <em>should</em> work. In Kel&#8217;s case, <a href="http://themeshaper.com/thematic/">Thematic</a> already consist of the first two steps described above when it should only be the first one. So now that she&#8217;s using the <a href="http://themeshaper.com/thematic-power-blog-theme/">Thematic Power Blog</a>, she won&#8217;t be able to customize her theme using a child theme because it&#8217;s already one.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/on-using-wordpress-theme-frameworks/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Does your theme have children?</title>
		<link>http://ptahdunbar.com/wordpress/does-your-theme-have-children/</link>
		<comments>http://ptahdunbar.com/wordpress/does-your-theme-have-children/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 03:13:17 +0000</pubDate>
		<dc:creator>Ptah Dunbar</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[droppin' knowledge on WordPress]]></category>

		<guid isPermaLink="false">http://ptahdunbar.com/?p=722</guid>
		<description><![CDATA[When working with WordPress theme frameworks or any parent theme, sometimes you might want to figure out whether a child theme is active or not. Here&#8217;s a quick function that&#8217;ll do exactly that:
function has_kids() {
	if (STYLESHEETPATH !== TEMPLATEPATH) return true;
	return false;
}

if ( has_kids() ) {
	// do stuff
}
This function works whether you call it from a [...]]]></description>
			<content:encoded><![CDATA[<p>When working with WordPress theme frameworks or any parent theme, sometimes you might want to figure out whether a child theme is active or not. Here&#8217;s a quick function that&#8217;ll do exactly that:</p>
<pre>function has_kids() {
	if (STYLESHEETPATH !== TEMPLATEPATH) return true;
	return false;
}

if ( has_kids() ) {
	// do stuff
}</pre>
<p>This function works whether you call it from a child theme or parent.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptahdunbar.com/wordpress/does-your-theme-have-children/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
