<?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>Archetyped &#8250; Lab</title>
	<atom:link href="http://archetyped.com/lab/feed/" rel="self" type="application/rss+xml" />
	<link>http://archetyped.com</link>
	<description>Explore, Experiment, Inspire</description>
	<lastBuildDate>Thu, 26 Aug 2010 23:55:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Cornerstone: Now is the Time for Action (and Filters)</title>
		<link>http://archetyped.com/lab/cornerstone-now-is-the-time-for-action-and-filters/</link>
		<comments>http://archetyped.com/lab/cornerstone-now-is-the-time-for-action-and-filters/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 21:47:21 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Feature]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cornerstone]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[Hooks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=624</guid>
		<description><![CDATA[<p><em>Content Types finally get some action</em></p>Cornerstone's content types now have the ability to hook into Wordpress with actions and filters, making it easy to fully customize how post fields are retrieved, displayed, and saved.]]></description>
			<content:encoded><![CDATA[<p><em>Content Types finally get some action</em></p><p><a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone&#8217;s</a> content types now have the ability to hook into WordPress with <a href="http://codex.wordpress.org/Plugin_API/Action_Reference" target="_blank">actions</a> and <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference" target="_blank">filters</a>, making it easy to fully customize how post fields are retrieved, displayed, and saved.</p>
<h3>Background</h3>
<p>With the release of <a href="http://wordpress.org/news/2004/05/heres-the-beef/" target="_blank">WordPress 1.2</a>, customizing WordPress has been greatly simplified by the inclusion of a <a href="http://codex.wordpress.org/Plugin_API" target="_blank">plugin API</a>.  This API is comprised of <strong>actions</strong> and <strong>filters</strong> that provide specific points in WordPress for plugins to &#8220;hook&#8221; into and customize how WordPress functions.  This makes WordPress an incredibly flexible platform for any type of project ranging from simple blogs to complex web applications.</p>
<p>Similarly, Cornerstone&#8217;s content types are like <em>mini plugins</em> that customize <strong>posts</strong> for a particular use or purpose. Thus, content types would also benefit greatly from the ability to hook into WordPress&#8217; actions and filters.</p>
<h3>Explore</h3>
<p>I openly admit that while I had this on my to-do list for a while, I was actually <em>tricked</em> into implementing this functionality into Cornerstone when I wanted to create a rich text (aka <a href="http://wikipedia.org/wiki/WYSIWYG" target="_blank">WYSIWYG</a>) field for use in content types.  This would make it simpler to format content in text fields, since the standard <code>textarea</code> field is simply plain text (no formatting).</p>
<p>Since WordPress uses <a href="http://tinymce.moxiecode.com/" target="_blank">TinyMCE</a> as its rich text editor by default, it was a logical choice for Cornerstone&#8217;s <code>richtext</code> field, so I did some exploratory work to determine how TinyMCE is implemented in WordPress itself.</p>
<p>As I said, I was <em>tricked</em> into enabling actions and filters for content types.  When I started looking into using TinyMCE in a field, I assumed that it would require adding Javascript to a page (since this is how TinyMCE is implemented by default), which Cornerstone&#8217;s content types can already do:</p>
<pre class="brush:php;gutter:false">$field-&gt;add_script($context, $handle, $uri, $dependencies);</pre>
<p>However, WordPress uses an action to call a function that handles all of the configuration and Javascript loading separately:</p>
<pre class="brush:php;gutter:false">add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );</pre>
<p>I was already committed.  Cornerstone&#8217;s content types would need to have access to actions and filters.</p>
<h3>Experiment</h3>
<p>There were a couple of questions that needed to be answered before hooks would be enabled in Cornerstone.</p>
<h4>1. Which content types to register hooks for?</h4>
<p>During initialization, all content types are registered so that WordPress has access to them.  However, not all content types are used in every request, so it would not be a good idea to register the hooks for <em>all</em> content types, but rather only the ones that are used in the current request.  Therefore, the first step is to determine which content types are used in the current request.</p>
<h4>2. When to register hooks for content types?</h4>
<p>Once we&#8217;ve determined which content types are currently in use, we can register the hooks for them.  The issue here is that we need to <em>use</em> a hook to register the hooks for the content types, so we&#8217;ve already lost one potential hook for content types to use.  We also need to make sure that WordPress is far enough along in its initialization process to be able to accept a content type&#8217;s hooks (i.e. environmental variables set, default post types registered, etc.), which may remove yet more hooks from those that content types can use.</p>
<p>After a bit of research and testing, the optimal hook to use for registering actions and filters for content types was <code>init</code>:</p>
<pre class="brush:php;gutter:false">add_action('init', 'add_hooks', 11);</pre>
<p>This means that the <code>init</code> action and any hook that precedes it will not be available for content types.  I&#8217;m not particularly fond of this limitation, but it is mitigated by the fact that there are only a few hooks before <code>init</code> and the vast majority of content types will use hooks that come <em>after</em> <code>init</code>.  Nonetheless, I would be happier if <code>init</code> were available to content types (since it&#8217;s a pretty common hook), so I&#8217;m still looking at some options for bringing it back into the fold.</p>
<p>In the end, enabling action and filter hooks for Cornerstone&#8217;s content types was not as involved as I imagined it would be (hence why it sat on my to-do list for as long as it did), and the ability to hook into WordPress with content types was well worth the time and effort.</p>
<h3>Payoff</h3>
<p>The payoff for the work is that hooking to WordPress is as simple as this:</p>
<pre class="brush:php;gutter:false">$richtext-&gt;add_action('admin_print_footer_scripts', 'wp_tiny_mce', 25);</pre>
<p>Even better is that the possibilities are now endless.  Just as with plugins, it&#8217;s really now down to our imagination to use Cornerstone&#8217;s content types to customize WordPress to the needs of our projects.</p>
<p><a href="http://archetyped.com/lab/cornerstone-now-is-the-time-for-action-and-filters/"> Cornerstone: Now is the Time for Action (and Filters)</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 25, 2010 11:47am</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/cornerstone-now-is-the-time-for-action-and-filters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cornerstone: Structure Now More Structured</title>
		<link>http://archetyped.com/lab/cornerstone-structure-now-more-structured/</link>
		<comments>http://archetyped.com/lab/cornerstone-structure-now-more-structured/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 04:03:47 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Cornerstone]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=619</guid>
		<description><![CDATA[Wordpress has a nice little UI element below the post title field that updates to show you the post's permalink after you have entered a title for the post.  This permalink preview is useful because it provides the user with feedback on the post they are in the process of writing.   It's also great because it showed me that Cornerstone had a little bug.]]></description>
			<content:encoded><![CDATA[<p>WordPress has a nice little UI element below the post title field that  updates to show you the post&#8217;s permalink after you have entered a title  for the post.  This permalink preview is useful because it provides the  user with feedback on the post they are in the process of writing.    It&#8217;s also great because it showed me that <a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone</a> had a little bug.</p>
<p>The other day, I fired up WordPress to write a new post, added the title, and started to write the post&#8217;s content, when I noticed something strange was going on with the permalink preview:</p>
<div id="attachment_622" class="wp-caption alignnone" style="width: 449px"><img class="size-full wp-image-622" title="Permalink Bugg" src="http://archetyped.com/wp-content/uploads/cnr_bug_permalink.gif" alt="" width="439" height="147" /><p class="wp-caption-text">Oops</p></div>
<h3>The Bug</h3>
<p>One of Cornerstone&#8217;s main features is <strong>Structure</strong>.  Structure allows a site to have sections and for authors to add posts to any of these sections.  When a post is added to a section, Structure makes sure the post&#8217;s permalink is logically connected to the section&#8217;s permalink.</p>
<ul>
<li>Section: <code>http://site-name.com/section-name/</code></li>
<li>Post: <code>http://site-name.com/section-name/post-name/</code></li>
</ul>
<p>Cornerstone adds a new permalink structure to <strong>Settings &gt; Permalinks</strong> in the site&#8217;s admin area which lets users enable this type of logical connection between posts and sections.</p>
<ul>
<li>Structured: <code>/%postpath%/%postname%/</code></li>
</ul>
<p>On this particular occasion, I had not yet selected a section for the post, which is was fortuitous because it revealed that Structure&#8217;s permalink modification was not working quite right for drafts.  In truth, it was not working <em>at all</em> because Structure was disabled for drafts.</p>
<pre class="brush:php">function post_link($permalink, $post, $leavename = false) {
	global $wp_query;
	if ( !$this-&gt;using_post_permastruct()
		|| ( !$this-&gt;util-&gt;check_post($post) )
		|| !$this-&gt;util-&gt;property_exists($post, 'post_name')
		|| empty($post-&gt;post_name)
		|| !$this-&gt;util-&gt;property_exists($post, 'post_parent')
		|| 0 == $post-&gt;post_parent )
		return $permalink;

//	...continue modifying permalink...</pre>
<p>According to this code, the custom permalink structure will not be used if any of the following conditions are met:</p>
<ul>
<li>Cornerstone&#8217;s custom permalink structure is not enabled</li>
<li>Valid post not passed to function</li>
<li>Post has no name (e.g. drafts)</li>
<li>Post is not in a section</li>
</ul>
<p>Since the function stopped before making any modifications to the draft post&#8217;s permalink, the permalink generated by WordPress remained.  However, since Cornerstone&#8217;s permalink structure contains a custom <a href="http://codex.wordpress.org/Using_Permalinks#Structure_Tags" target="_blank">structure tag</a> (<code>%postpath%</code>), WordPress did not know what to do with it and simply left it in the permalink (only replacing the standard <code>%postname%</code> tag).</p>
<p>Posts without sections are simply supposed to be located at the site&#8217;s root level (e.g. <code>http://site-name.com/post-name/</code>), but the conditions that were set to determine whether a post&#8217;s permalink should be modified were overly aggressive.  The result was that any post that wasn&#8217;t in a section would have an invalid permalink.</p>
<h3>The Fix</h3>
<p>Thankfully, the solution to this issue was quite apparent&#8211; simplify!</p>
<pre class="brush:php">function post_link($permalink, $post, $leavename = false) {
	global $wp_query, $cnr_content_utilities;

	if ( !$this-&gt;using_post_permastruct()
		|| ( !$this-&gt;util-&gt;check_post($post) )
		|| ( empty($post-&gt;post_name) &amp;&amp; empty($post-&gt;post_title) ) )
		return $permalink;

//	...continue modifying post permalink...</pre>
<p>Now the custom permalink structure would be used for a post except under just a few conditions:</p>
<ul>
<li> Custom permalink structure is not activated by user</li>
<li>Valid post not passed to function</li>
<li> Post has no name <em>or </em>title (e.g. drafts)</li>
</ul>
<p>We check for the existence of the post&#8217;s title if there is no post name (i.e. the post&#8217;s slug) because in certain instances, the post passed to this function may not yet have a slug, but it will have a title (which we can still work with).  Only if the post has neither slug nor title will we halt further processing (since we can&#8217;t build a full permalink without at least one of those values).</p>
<p>Finally, since custom post types made their full debut in WordPress 3.0, we need a small addition to support them as well.  Cornerstone allows putting items with custom post types into sections as well, so the same permalink structure is used for items that have a section selected (i.e. <code>/section-name/post-name/</code>).  However, by default, the permalink structure for items with custom content types is <code>/post-type/post-name/</code>, so if an item is <em>not</em> in a section and it has a custom post type, then the default permalink structure should be used.</p>
<p>So our final conditional statement looks like:</p>
<pre class="brush:php">function post_link($permalink, $post, $leavename = false) {
	global $wp_query, $cnr_content_utilities;

	if ( !$this-&gt;using_post_permastruct()
		|| ( !$this-&gt;util-&gt;check_post($post) )
		|| ( empty($post-&gt;post_name) &amp;&amp; empty($post-&gt;post_title) )
		|| ( !$cnr_content_utilities-&gt;is_default_post_type($post-&gt;post_type) &amp;&amp; empty($post-&gt;post_parent) ) )
		return $permalink;

//	...continue modifying post permalink...</pre>
<p>Now post permalinks work just fine and <a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone&#8217;s</a> <strong>Structure</strong> is even more structured than before.</p>
<p><a href="http://archetyped.com/lab/cornerstone-structure-now-more-structured/"> Cornerstone: Structure Now More Structured</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 20, 2010 06:03pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/cornerstone-structure-now-more-structured/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Favicon Rotator 1.1: Optimized Icons</title>
		<link>http://archetyped.com/lab/favicon-rotator-1-1-optimized-icons/</link>
		<comments>http://archetyped.com/lab/favicon-rotator-1-1-optimized-icons/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 00:10:00 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[Favicon]]></category>
		<category><![CDATA[Favicon Rotator]]></category>
		<category><![CDATA[Icon]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Update]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=617</guid>
		<description><![CDATA[Favicon Rotator received a few updates recently, but the main highlight is that optimized icons are now created for uploaded images.]]></description>
			<content:encoded><![CDATA[<p><a href="http://archetyped.com/tools/favicon-rotator/" title="Favicon Rotator">Favicon Rotator</a> received a few updates recently, but the main highlight is that optimized icons are now created for uploaded images.</p>
<h3>Why?</h3>
<p>The primary purpose of Favicon Rotator was to make it simple to upload a favicon for a WordPress site.  So in version 1.0, the plugin basically loaded the image as it was uploaded by the user.  This works perfectly fine, especially if the user uploads an image <em>meant</em> to be a favicon (i.e. 16&#215;16 resolution).  Larger images were properly loaded as well, but it was left up to the browser to resize the image to fit in the 16&#215;16 space in the browser&#8217;s address bar.  The other issue was that if the user selected a large image to use as a favicon, then the site&#8217;s loading time could be increased since the entire image needed to be downloaded (regardless of how small it was being displayed).</p>
<p>I definitely am not a fan of slower loading, but I was initially hesitant to create additional files since WordPress already automatically creates thumbnail files for all uploaded images, which is a waste of disk space if the user will never use them.  However, due to the potential for increased load times and the hit-or-miss results when letting the browser resize large images, I decided that Favicon Rotator should create an image optimized for use as a favicon.</p>
<p>Thankfully, WordPress is not stupid (quite smart in fact), and it will not create additional intermediate files (thumbnails, etc.) if the original image is smaller than the intermediate sizes.  This means that if a user does upload a 16&#215;16 image file that is already optimized for use as a favicon, no additional files will be created.  Therefore, only images that would benefit from an intermediate file will have one created.</p>
<h3>When?</h3>
<p>Favicon Rotator doesn&#8217;t create favicon-sized files for <em>all </em>images uploaded to WordPress, but rather only when certain criteria are met:</p>
<ul>
<li>Images that are uploaded via Favicon Rotator&#8217;s admin page</li>
<li>Images that were uploaded by other means, but are selected for use as a favicon</li>
</ul>
<p>This minimizes the number of extraneous files in WordPress since optimized icons are created on-demand and saved for future use (so icons for an image are only created once).</p>
<h3>How?</h3>
<p>Adding a new intermediate size for uploaded images is very simple.  It only takes one quick line of code:</p>
<pre class="brush:php;gutter:false">add_image_size($image_size, $width, $height, $crop);</pre>
<p>Then, you simply add a hook to register this new size once WordPress has loaded.  Basically any hook including and beyond <code>init</code> will do, but I chose to hook into <code>intermediate_image_sizes</code> so that the favicon image size is added only when the available intermediate image sizes are requested (otherwise the favicon image size would be added during every request whether it was needed or not).</p>
<pre class="brush:php;gutter:false">add_filter('intermediate_image_sizes', 'add_intermediate_image_size');</pre>
<p>The custom function to add the favicon image size can be very simple:</p>
<pre class="brush:php">function add_intermediate_image_size($sizes) {
	add_image_size('favicon', 16, 16, true);
	$sizes[] = 'favicon';
	return $sizes;
 }</pre>
<p>However, since we only want to create an optimized file when uploading or selecting a file specifically for use as a favicon, we need to add a bit more code:</p>
<pre class="brush:php">function add_intermediate_image_size($sizes) {
	$img = array('width' =&gt; 0, 'height' =&gt; 0, 'crop' =&gt; true);
	if ( $this-&gt;is_custom_media() ) {
		$img['width'] = $this-&gt;icon_dimensions['w'];
		$img['height'] = $this-&gt;icon_dimensions['h'];
	}
	add_image_size($this-&gt;icon_size, $img['width'], $img['height'], $img['crop']);
	$sizes[] = $this-&gt;icon_size;
	return $sizes;
 }</pre>
<p>This updated function does the following:</p>
<ol>
<li>Creates a default array with zeroed-out values for the intermediate image (more on why later)</li>
<li>Checks if the current request is initiated by Favicon Rotator (e.g. uploading/selecting an image via the admin page).  If so, set actual width/height values for favicon image (using object variables)</li>
<li>Adds image size to WordPress</li>
<li>Adds size name (e.g. &#8216;favicon&#8217;) to array of intermediate images sizes (using an object variable)</li>
<li>Return updated array of intermediate image sizes to filter</li>
</ol>
<p>The reason why we create an array with zeroed-out values for the image dimensions is because the intermediate image sizes may be requested in multiple situations (e.g. when deleting an image attachment from WordPress) so we need to add a valid size to the list of intermediate sizes whenever it is requested.  However, since we don&#8217;t want to actually <em>create</em> an additional favicon file for images unless they are uploaded/selected via Favicon Rotator&#8217;s admin page, we set the width/height to 0, which WordPress will then skip when creating intermediate images.</p>
<h3>That&#8217;s a wrap!</h3>
<p>By adding this functionality, favicons from large images look better <em>and</em> load faster, which makes this a worthwhile update for me.  As with most updates, I don&#8217;t really know where I&#8217;m going next (since I usually include everything I want to before updating), so any further updates will likely be based on user feedback.  If you have any requests, make sure to <a href="http://archetyped.com/tools/favicon-rotator/#respond" title="Provide feedback for Favicon Rotator">leave a comment</a> to let me know how Favicon Rotator can be improved.</p>
<p><a href="http://archetyped.com/lab/favicon-rotator-1-1-optimized-icons/"> Favicon Rotator 1.1: Optimized Icons</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 20, 2010 02:10pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/favicon-rotator-1-1-optimized-icons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making of: Favicon Rotator</title>
		<link>http://archetyped.com/lab/making-of-favicon-rotator/</link>
		<comments>http://archetyped.com/lab/making-of-favicon-rotator/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 20:46:28 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Favicon]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Story]]></category>
		<category><![CDATA[WebDev]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=607</guid>
		<description><![CDATA[From a one-line of hack I was inspired to make a "quick and simple" plugin for Wordpress. This is the story of how Favicon Rotator came to be.]]></description>
			<content:encoded><![CDATA[<p>From a one-line of hack I was inspired to make a <em>&#8220;quick and simple&#8221;</em> plugin for WordPress.  This is the story of how <a href="http://archetyped.com/tools/favicon-rotator/" title="Favicon Rotator">Favicon Rotator</a> came to be.</p>
<h3>Inspiration</h3>
<p>When designing this site, I created several different <a href="http://wikipedia.org/wiki/Favicon" target="_blank">favicons</a>.  I narrowed it down to the icons that I liked best, but in the end, I couldn&#8217;t decide on just one.</p>
<div id="attachment_609" class="wp-caption alignnone" style="width: 310px"><img class="size-full wp-image-609" title="Favorite Favicons" src="http://archetyped.com/wp-content/uploads/favorite_favicons.gif" alt="" width="300" height="70" /><p class="wp-caption-text">Favorite Favicons</p></div>
<p>Then I thought, &#8220;why not both?&#8221; and so with a simple line of code, I rewarded my indecision and setup the site&#8217;s theme to randomly choose between the two different favicons each time the site was loaded.</p>
<pre class="brush:xml;gutter:false">&lt;link rel="icon" type="image/gif" href="&lt;?php bloginfo('template_directory'); ?&gt;/images/favicon_&lt;?php echo rand(1, 2); ?&gt;.gif" /&gt;
</pre>
<p>It was a quick solution and I was happy with the end result, but maintainability is a big thing for me and I had thought that it would be great if a site&#8217;s favicon could be easily added or changed as simply as adding a photo to a post in WordPress.  Even better, if <em>multiple</em> icons were added, it would automatically rotate through them, displaying a random icon each time the site is loaded.  I&#8217;m not sure if anyone else does that or even wanted such an ability, but after adding multiple icons to this site, I knew it was something I dug.</p>
<h3>Exploration</h3>
<p>Once I <a href="http://archetyped.com/lab/cornerstone-we-have-compatibility/" title="Cornerstone: We have compatibility!">reached a milestone</a> in <a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone</a>, I decided to spend some time exploring some of the other ideas I had swirling around in my head.  Favicon Rotator was one of the ideas I decided to work on because I felt I could finish it quickly and would be good experience for the next phase of Cornerstone (administration UI&#8217;s, etc.).</p>
<h4>Planning</h4>
<p>The first step was planning out the plugin.  The concept was pretty simple (add/manage favicon from admin page) and the ideas I had for implementation (mostly) clear, but I find that it&#8217;s a good first step to get those ideas out on paper or screen.  Doing this helps to clarify the purpose and expectations for the project, making for a much smoother workflow overall.</p>
<p>I manage the majority of my projects using a customized version of <a href="http://www.tiddlywiki.com/" target="_blank">TiddlyWiki</a> (a small and fast self-contained wiki), so the first thing I did was create a new project and set about listing all of the features I envisioned for this project.  <strong>Total time:</strong> 5 minutes.</p>
<div id="attachment_610" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-610" title="Feature List" src="http://archetyped.com/wp-content/uploads/favicon-rotator_features.png" alt="" width="500" height="281" /><p class="wp-caption-text">Feature List: Different colors indicate feature progress</p></div>
<h4>Wireframes</h4>
<p>While not always necessary, <a href="http://en.wikipedia.org/wiki/Website_wireframe" target="_blank">wireframing</a> is a quick way to iterate through ideas to optimize a layout.  The goal was to make it incredibly simple to add a favicon to the site, so sketching out a few wireframes of the admin interface to make it as simple as possible would be time well spent.</p>
<div id="attachment_612" class="wp-caption alignnone" style="width: 160px"><a href="http://archetyped.com/wp-content/uploads/favrot_wf_01.gif"><img class="size-thumbnail wp-image-612" title="Initial Wireframes - Rapid Iteration" src="http://archetyped.com/wp-content/uploads/favrot_wf_01-150x150.gif" alt="" width="150" height="150" /></a><p class="wp-caption-text">Initial Wireframes - Rapid Iteration</p></div>
<p>I drew out the wireframes with a thick sharpie to keep focus on the overall UI design and to keep from getting lost in the little details at this point.  I love to take the time to focus on the tiniest details, but at this phase the big picture was the priority so that I could move to the next phase quickly.  This worked out really well and helped me to arrive at an overall layout that I was happy to move forward with after a few iterations. <strong>Total time:</strong> 45 minutes.</p>
<div id="attachment_611" class="wp-caption alignnone" style="width: 160px"><a href="http://archetyped.com/wp-content/uploads/favrot_wf_02.gif"><img class="size-thumbnail wp-image-611" title="Final Wireframes" src="http://archetyped.com/wp-content/uploads/favrot_wf_02-150x150.gif" alt="" width="150" height="150" /></a><p class="wp-caption-text">Final Wireframes</p></div>
<h3>Experimentation</h3>
<p>Now that I knew what I wanted the plugin to do and how I wanted it to work, it was now time to develop it!  This was the basic order of events during development:</p>
<ol>
<li>Build administration UI
<ul>
<li>Setup layout (based on wireframes)</li>
<li>Add functionality to elements (“add new” button, “remove icon” buttons, “save changes” button, etc.)</li>
</ul>
</li>
<li>Handle retrieving icon(s) from the database</li>
<li>Handle saving icon selection(s) to the database</li>
<li>Handle uploading and selecting images to use as icons</li>
<li>Randomly select an icon and display it when site is loaded</li>
</ol>
<h4>1. Build administration UI</h4>
<p>Building the UI was quick and simple thanks to the wireframes.  I&#8217;ve also used much of WordPress&#8217; own CSS classes for many UI elements (buttons, headers, etc.), which I think is always a good idea because it makes it easier for users to use (since they&#8217;re already familiar with WP&#8217;s UI), it saves time when building the UI, and it will remain consistent with the rest of WordPress&#8217; admin UI if they ever change the official design.  For the icon containers themselves, I&#8217;ve decided to keep the design rather simple, but may decide to make them a bit more &#8220;WordPress-y&#8221; in the future so that it looks fully integrated.</p>
<div id="attachment_602" class="wp-caption alignnone" style="width: 400px"><img class="size-full wp-image-602" title="Favicon Management" src="http://archetyped.com/wp-content/uploads/favicon-rotator_admin-page.png" alt="" width="390" height="230" /><p class="wp-caption-text">Favicon Management UI</p></div>
<h4>2. Handle retrieving icon(s) from the database</h4>
<p>Since the functionality to actually <em>add</em> an icon to the list had not yet been developed (see step 4), I started off by adding some temporary data to the <code>wp_options</code> table where I would be storing the icon selections.  Using that data, I developed the functionality to retrieve those values and build an element with the necessary icon information to be displayed to the user.  Icon data was also added to a hidden form field that was updated whenever the icon selection was changed.</p>
<h4>3. Handle saving icon selection(s) to the database</h4>
<p>Though users added/removed favicons in a very visual &#8220;point and click&#8221; way, saving their changes was a much more straightforward process.  Data for the selected icons are stored in a hidden form field which is updated with a dash of Javascript whenever favicons are added and removed from the list.  When the &#8220;Save changes&#8221; button is clicked, the value from this form field is simply saved to the database.</p>
<h4>4. Handle uploading and selecting images to use as icons</h4>
<p>WordPress already has fairly robust media management capabilities built-in and since I&#8217;ve used it quite a bit in Cornerstone, I decided to use it in Favicon Rotator too.  Mind you, this is not simply plug and play as there are a number of hoops to jump through to place nice with WordPress.  Thankfully, no hacks are needed (mostly) because WordPress&#8217; provides the necessary plugin hooks.</p>
<h5><strong>Launching the media upload UI</strong></h5>
<p>Launching the media upload UI is pretty straightforward.  Just build a link to <code>admin/media_upload.php</code> with the appropriate URL query variables set.</p>
<pre class="brush:html;gutter:false">&lt;a href="http://archetyped.com/wp-admin/media-upload.php?post_id=0&amp;tab=type&amp;type=fvrt_icon&amp;fvrt_action=1&amp;TB_iframe=1" class="thickbox"&gt;Open Upload UI&lt;/a&gt;
</pre>
<p>The necessary URL query variables are:</p>
<ul>
<li><code>post_id</code> &#8211; The ID of the post that the media is being uploaded for.  Media uploads are referred to as &#8220;attachments&#8221; in WordPress because they are <em>attached</em> to other content (posts, pages, etc.).  In this case, we don&#8217;t want to attach the upload icons to a specific post, so we just set this variable to <code>0</code></li>
<li><code>tab</code> &#8211; The media management UI has several tabs, each with a different purpose (upload media, browse library, etc.).  The upload tab is displayed by default, but in this case, this variable is set to <code>type</code>, which will cause the type URL variable to be processed (see below for why)</li>
<li><code>type</code> &#8211; The type of media being uploaded/browsed (image, audio, video, etc.).  When the type is processed, WordPress fires an action formatted as <code>media_upload_{type}</code>, so in our case, an action called <code>media_upload_fvrt_icon</code> will be fired.  I can then hook into this action to gain control over how uploads are handled.</li>
<li><code>fvrt_action</code> &#8211; Specifies that the media upload UI was launched by Favicon Rotator.  This is a custom variable I add so that I can quickly determine whether to hook into the actions and filters fired by the media upload UI (e.g. when the UI is launched to upload images for a post, I don&#8217;t need to hook into it).</li>
<li><code>TB_iframe</code> &#8211; Whether or not the media UI is launched in an iframe (which it is in when used on the post edit form and in Favicon Rotator).</li>
</ul>
<p>Also, by adding class=&#8221;thickbox&#8221; to the link, the resulting link will open in a non-modal popup (a lightbox) without leaving the current page.  I also needed to load the necessary files for the thickbox functionality:</p>
<pre class="brush:php;gutter:false">add_thickbox(); //Adds thickbox files to page header</pre>
<h5>Add an &#8220;Add icon&#8221; button to uploaded media</h5>
<p>Once the media upload UI is displayed, we need a way for the user to select an image and add it to the list of favicons.  To do this, Favicon Rotator hooks into the <code>attachment_fields_to_edit</code> filter to modify the fields/buttons that are displayed when viewing an attachment&#8217;s details in the media management UI.</p>
<p>Using this filter, all extraneous edit fields and buttons are removed (to keep things as simple as possible) and the &#8220;Add icon&#8221; button is added.</p>
<p>The end result is a clean UI with a simple button to add an icon to the list</p>
<div id="attachment_613" class="wp-caption alignnone" style="width: 160px"><a href="http://archetyped.com/wp-content/uploads/media_details_default.png"><img class="size-thumbnail wp-image-613" title="Default Media Details" src="http://archetyped.com/wp-content/uploads/media_details_default-150x150.png" alt="" width="150" height="150" /></a><p class="wp-caption-text">Default Media Details</p></div>
<div id="attachment_614" class="wp-caption alignnone" style="width: 160px"><a href="http://archetyped.com/wp-content/uploads/media_details_favrot.png"><img class="size-thumbnail wp-image-614" title="Media Details for favicon selection" src="http://archetyped.com/wp-content/uploads/media_details_favrot-150x150.png" alt="" width="150" height="150" /></a><p class="wp-caption-text">Media Details for favicon selection</p></div>
<h5>Adding the selected icon to the list</h5>
<p>Once the user has clicked the &#8220;Add icon&#8221; button for an image, the final step is sending the selected icon from the media management UI (in the &#8220;lightbox&#8221; popup) into the favicon list on the admin page.  This is handled in essentially the same way that images are inserted into posts.  The basic methodology is as follows:</p>
<ol>
<li>User clicks &#8220;Add icon&#8221; button for an image.  This submits a form.</li>
<li>The form submission is evaluated to determine which image the &#8220;Add icon&#8221; button was clicked for</li>
<li>The image&#8217;s details (ID, source URL, and file name) are sent via Javascript to the underlying admin page</li>
<li>The media upload UI is closed</li>
</ol>
<p>Once the admin page receives the image data, it builds a new icon container for the image and adds it to the list of icons.  The image&#8217;s ID is then added to the hidden form field that corresponds to the icons in the list.</p>
<p>Finally (phew!), when the user clicks the &#8220;Save changes&#8221; button, the icon ID&#8217;s are saved in the <code>wp_options</code> table for safe-keeping.  This is the other benefit of using WordPress&#8217; built-in media management functionality&#8211; since attachments in WordPress are essentially posts, we can simply save their ID and reference it to retrieve the rest of their data.  As a bonus, WordPress also has several functions specifically for retrieving attachment data (source URL, etc.) which saves us from having to develop those tools ourselves.</p>
<p>Development was clearly the longest phase in the entire process, but it  was sped up greatly by the initial planning and wireframing that gave me  a clear direction for the entire development phase.  <strong>Total time:</strong> 19 hours</p>
<h3>Wrap Up</h3>
<p>The initial motivation for developing Favicon Rotator was to provide others with the capability to display multiple favicons randomly like this site does.  However, during development, I realized that the real value of the plugin was quite a bit simpler and made it useful to a much wider audience.  Favicon Rotator enables anyone to easily add a favicon to their site (regardless of whether or not they want to rotate between multiple icons).  Users no longer need to edit theme files, manually upload images via FTP, or copy/paste URL&#8217;s to favicon files just to simply add a favicon to their site.</p>
<p>This is a capability that is missing in WordPress at the moment, so while I&#8217;m happy that I made a plugin that accomplishes my initial (though obscure) goal of icon randomness, I&#8217;m actually more enthused about the plugin&#8217;s potential to enable users to easily do something that may have been out of reach for them previously.</p>
<p><a href="http://archetyped.com/lab/making-of-favicon-rotator/"> Making of: Favicon Rotator</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 17, 2010 10:46am</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/making-of-favicon-rotator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redactor &#8211; Quality time with TinyMCE</title>
		<link>http://archetyped.com/lab/redactor-quality-time-with-tinymce/</link>
		<comments>http://archetyped.com/lab/redactor-quality-time-with-tinymce/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 08:46:18 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Privacy]]></category>
		<category><![CDATA[Redact]]></category>
		<category><![CDATA[WebDev]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=595</guid>
		<description><![CDATA[Today I moved on to working on working on implementing redaction in Wordpress' visual editor, otherwise known as TinyMCE.]]></description>
			<content:encoded><![CDATA[<p>Today I moved on to working on working on implementing redaction in WordPress&#8217; visual editor, otherwise known as <a href="http://tinymce.moxiecode.com/">TinyMCE</a>.</p>
<p>In general, I&#8217;m not a huge fan of WYSIWYG editors because what-you-see-is-<strong>not</strong>-always-what-you-get, and TinyMCE is no exception.  It&#8217;s neither the fastest nor the most lightweight editor out there, but it is quite capable and the plugin API is rather robust.  Over time, I have given the visual editor some leeway and have become accustomed to letting it handle my paragraph tags and bolded text.  Honestly, it&#8217;s not half bad and I find myself writing in the visual editor more and more often, only switching to the HTML editor when I need to make sure the proper markup is written.</p>
<p>At any rate, since I use WordPress&#8217; visual editor fairly regularly (along with the majority of WordPress users out there, I&#8217;d assume), I decided to add redaction support to TinyMCE.  I <em>could</em> do it quick and dirty and just add a button that wraps the redact shortcode around the selected text, but that wouldn&#8217;t be fun.  Instead, redacting text in the visual editor will function very similarly to the way you would make text bold or italic.  Basically, click the &#8220;Redact text&#8221; button on the toolbar and the text styling is changed to indicate that it is redacted.  I think this is one of the benefits of the visual editor as visual cues make navigating through a post&#8217;s content far faster for most users than looking at the HTML source.</p>
<p>So far, I&#8217;ve:</p>
<ul>
<li>Added a button to TinyMCE&#8217;s toolbar to activate/deactivate redaction</li>
<li>Setup CSS to provide visual cues to identify redacted text</li>
<li>Started work on wrapping selected text in the redact shortcode</li>
</ul>
<p>The interesting bit about TinyMCE is that you can add additional HTML markup in the post content to help with the visual cues in the visual editor, but when you view the source, you can swap out the presentation markup for the markup you want to be saved with the post content.  This makes it incredibly customizable in terms of presentation <em>and</em> final markup.</p>
<p>The main thing that&#8217;s left is to refine how selected text is wrapped with the shortcode.  Some things to consider when manipulating the selected text:</p>
<ol>
<li>Is the selected text part of a larger chunk of chunk of text that has already been redacted?</li>
<li>Should the selected text be wrapped or unwrapped with the shortcode?</li>
<li>What should happen when no text is selected?</li>
</ol>
<p>We definitely want to avoid nesting redaction shortcodes within each other so I&#8217;m going to take some time on this to make sure it works the way one would expect it to in the different situations.</p>
<p>I&#8217;m planning on putting together a tutorial on making a TinyMCE plugin for WordPress once I&#8217;ve released this plugin.  Even though I&#8217;ve done a fair amount of TinyMCE plugin development specifically for WordPress, I think having a quick step by step reference for creating a plugin for the visual editor would be a nice way to jump start development on the next one.  Hopefully others will find it useful as well.</p>
<p>On a different but related note, I was surprised today when I noticed that WordPress was telling me to update Redactor as a new version has just become available.</p>
<p><img class="alignnone size-full wp-image-598" title="Update Redactor" src="http://archetyped.com/wp-content/uploads/redactor_update_2010-08-09.png" alt="" width="416" height="61" /></p>
<p>I found this perplexing at first because I was sure I hadn&#8217;t published an updated version of the plugin that I didn&#8217;t know about on my own development version of WordPress.  It appears that the &#8220;Updates&#8221; section of WordPress merely looks for matching plugin names on WordPress.org (as opposed to checking the plugin URI as well) as it turns out that I was being notified of a new version of a <a href="http://wordpress.org/extend/plugins/redactor/">different plugin</a> with the same name.</p>
<p>I checked whether there was already a plugin called &#8220;Redactor&#8221; on WordPress&#8217; website last week to avoid confusion when I first started writing about my plugin.  I figured this other plugin must be very new.  It is, it was released <em>today</em>.</p>
<p>What&#8217;s cool is that it has many of the same features that have or am planning to implement in my plugin (from manual shortcodes to automated text replacement).  It&#8217;s always nice to have more than one option.  While Redactor is just a code name for the plugin during development, I was considering the possibility of using it as the official name (since it&#8217;s rather descriptive of it&#8217;s functionality), but I guess the decision has been made for me.  Thanks!</p>
<p><a href="http://archetyped.com/lab/redactor-quality-time-with-tinymce/"> Redactor &#8211; Quality time with TinyMCE</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 9, 2010 10:46pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/redactor-quality-time-with-tinymce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redactor: A New Privacy Plugin for WordPress</title>
		<link>http://archetyped.com/lab/redactor-a-new-privacy-plugin-for-wordpress/</link>
		<comments>http://archetyped.com/lab/redactor-a-new-privacy-plugin-for-wordpress/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 05:30:14 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=592</guid>
		<description><![CDATA[I cracked open Eclipse today and started working on a new WordPress plugin that I got the idea for .  The plugin is called Redactor and as the name implies, it allows authors to redact text in posts.  In other words, you can mask, obfuscate, or otherwise hide text in posts that you want to ...]]></description>
			<content:encoded><![CDATA[<p>I cracked open Eclipse today and started working on a new WordPress plugin that I got the idea for <a href="http://archetyped.com/lab/what-you-should-know-now-is-that-dump-is-now-know/" title="What you should know now is that Dump is now Know">yesterday</a>.  The plugin is called Redactor and as the name implies, it allows authors to <em>redact</em> text in posts.  In other words, you can mask, obfuscate, or otherwise hide text in posts that you want to keep private.</p>
<p>The idea came about as a way to allow people to write without any filtering while still having piece of mind that they aren&#8217;t fully disclosing all of their personal information with the rest of the internet.  Personal journals, freewriting, and partially declassified government documents are all perfect places for Redactor.</p>
<p>Today I setup the plugin framework, created the <a href="http://codex.wordpress.org/Shortcode_API">shortcode</a> to wrap around text that should be redacted, and added a button to the HTML text editor to automatically wrap selected text with the shortcode.</p>
<h3>Example</h3>
<p>Say an author wrote the following:</p>
<pre>Hello, my name is Joanie and I love Chachi</pre>
<p>This might be a bit too revealing for just anyone to see so, the author <em>redacts</em> some of the text</p>
<pre>Hello, my name is &#91;redacted&#93;Joanie&#91;/redacted&#93; and I love &#91;redacted&#93;Chachi&#91;/redacted&#93;</pre>
<p>When this post is viewed publicly, it will be displayed as</p>
<pre>Hello, my name is XXXXXX and I love XXXXXX</pre>
<p>Personally-identifying information redacted!  Take that ID thieves!</p>
<p>Pretty spiffy right?  The benefit is that the author (and any other logged in user with sufficient permissions) will still be able to see the original unredacted text in all its glory.</p>
<p>Of course, the plugin will be customizable, allowing authors to change the text used in place of redacted text.</p>
<h3>Next</h3>
<p>I have a bunch of ideas for this plugin, but my plan is to get the basic functionality working and release the plugin quickly.  To this end, the next step is adding a TinyMCE plugin so that authors can specify text to be redacted from the visual editor without having to manually write out the shortcode.</p>
<p><a href="http://archetyped.com/lab/redactor-a-new-privacy-plugin-for-wordpress/"> Redactor: A New Privacy Plugin for WordPress</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 6, 2010 07:30pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/redactor-a-new-privacy-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What you should know now is that Dump is now Know</title>
		<link>http://archetyped.com/lab/what-you-should-know-now-is-that-dump-is-now-know/</link>
		<comments>http://archetyped.com/lab/what-you-should-know-now-is-that-dump-is-now-know/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 02:40:44 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Cornerstone]]></category>
		<category><![CDATA[Lesson]]></category>
		<category><![CDATA[Update]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=589</guid>
		<description><![CDATA[<p><em>Another adventure of bug squashing and lessons learned</em></p>Archetyped is updated and ]]></description>
			<content:encoded><![CDATA[<p><em>Another adventure of bug squashing and lessons learned</em></p><p>I completed the changes to this site that I started <a href="http://archetyped.com/lab/names-taken-bugs-squashed/" title="Names Taken, Bugs Squashed">yesterday</a> but didn&#8217;t finish because of some last-minute bugs (glad to have found them before uploading).  The main issue keeping me from updating the site was that the featured posts functionality of <a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone</a> was not working properly.  Featured posts in Cornerstone are similar to WordPress&#8217; own sticky posts functionality in that it lets you place specific posts in front of the normal chronologically-sorted posts, which is useful when you want to highlight certain content.  Featured posts in Cornerstone differs from WordPress&#8217; sticky posts in that it offers somewhat more customizability and control over how/when featured posts are displayed.</p>
<p>However, due to some changes last night, the featured posts weren&#8217;t being retrieved for output on the site.  To be quite honest, I wasn&#8217;t sure what I could have changed yesterday that could have broken the featured posts functionality, so I had no idea what to expect when I started investigating it this morning.  Thankfully the issue was relatively minor and was causing the wrong section ID to be used when attempting to retrieve featured posts for a specific section of the site.  I tightened up a couple conditional statements to make sure the section ID is properly retrieved and featured posts were once again working!</p>
<p>With that out of the way, I proceeded to prepare for deploying all updates to the production server.  Since everything had been updated to work with WordPress 3.0+, the first order of business was upgrading the production server to WordPress 3.0.1.  After that, I updated Cornerstone and the site&#8217;s theme files.  I cleared my cache, hit refresh, and held my breath.  The site loaded up fine and everything is working great on the production server!  The final step was changing the Dump section to <a href="http://archetyped.com/know/" title="Know">Know</a>, which basically entailed adjusting the section&#8217;s title, slug, and icon.</p>
<p>It took longer than expected for such a small change (all I originally intended to do was change the name of a section), but in the end the site is much better and more stable for the work that went into it.</p>
<h3>Lessons learned</h3>
<p>As with any situations that require troubleshooting, there are always lessons to be learned.  Here are some I lessons learned or reaffirmed today:</p>
<ul>
<li><strong>Test, Test, Test</strong> &#8211; before any update big or small, I always follow the same workflow:
<ol>
<li>Develop and test the code on my computer</li>
<li>Upload updates to the offsite <em>staging</em> server (basically a private mirror of the public production server) to test for issues not found while testing locally</li>
<li>Upload updates to the <em>production </em>server (the public site) and run through tests to confirm no issues exist</li>
</ol>
<p>The goal is of course to avoid any downtime on the public site and this basic workflow has saved me many headaches on all of my projects.  I should note that prior to each step I also backup all relevant files and databases so that I can revert to a working version very quickly and start fresh if things get too messy while I troubleshoot an issue.</li>
<li><strong>Exercise caution when manipulating WordPress&#8217; post queries</strong> &#8211; Cornerstone hooks into the post query process in several modules (permalink rewriting, content types, featured posts, etc.) and I feel rather comfortable manipulating the query variables to retrieve the posts that I want, but it is also very easy to invalidate the query with just a small change.  Vigilance is key when manipulating post query objects.</li>
</ul>
<p>I enjoy troubleshooting because I like the challenge of finding elegant solutions to problems.  Nonetheless, I am glad that I was able to work out the issues rather quickly today because it feels good to have my production site running the latest version of WordPress.</p>
<h3>Next</h3>
<p>I&#8217;m about to start working on 2 small WordPress plugins that I have been thinking about recently (one of them since this morning).  One is intended to improve privacy and the other will make it easier to customize a site&#8217;s favicon from within WordPress.  I&#8217;m looking forward to it.</p>
<p><a href="http://archetyped.com/lab/what-you-should-know-now-is-that-dump-is-now-know/"> What you should know now is that Dump is now Know</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 5, 2010 04:40pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/what-you-should-know-now-is-that-dump-is-now-know/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Names Taken, Bugs Squashed</title>
		<link>http://archetyped.com/lab/names-taken-bugs-squashed/</link>
		<comments>http://archetyped.com/lab/names-taken-bugs-squashed/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 09:21:55 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=566</guid>
		<description><![CDATA[<p><em>Sol smash bugs!  Ah! Bugs now find Sol!</em></p>I fixed a bug or two to make Cornerstone even more compatible, plus made some changes to this site's theme.]]></description>
			<content:encoded><![CDATA[<p><em>Sol smash bugs!  Ah! Bugs now find Sol!</em></p><p>After <a href="http://archetyped.com/lab/cornerstone-we-have-compatibility/" title="Cornerstone: We have compatibility!">declaring compatibility</a> with WordPress 3.0 for <a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone</a> a couple days ago, I of course found a few bugs.  I spent some time squashing those bugs and ended up finding a couple more.</p>
<h3>Cornerstone</h3>
<p>So far, I&#8217;ve only found one new compatibility-related bug in <a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone</a> (I did say I still had testing to do), but it was one that had me digging through a lot more code than I would have liked to get to the root of the issue.  As I was running through my tests, I noticed that all page permalinks were coming up as &#8220;page not found&#8221;.  I initially thought that this was due to some overzealous permalink rewriting, but the issue was still there after disabling all rewrite rule modifications.</p>
<p>After disabling about half of Cornerstone&#8217;s functionality to determine the cause of the issue, I narrowed it down to a conditional statement in the <a href="http://archetyped.com/lab/cornerstone-all-content-types-aboard/" title="Cornerstone: All Content Types Aboard!">recent update</a> I made to the Content Types module.  The conditional was supposed to determine the different situations where the additional post types should be added to the query so that all posts (regardless of their post type) were retrieved and displayed.  While most of the bases were covered, I forgot to exclude the situation were only one content item (i.e. a post, a page, an attachment, etc.) was requested.  I added an additional statement to the excluded situations,</p>
<pre class="brush:php;gutter:false">is_singular()</pre>
<p>and pages were loading up as good as new!  I then just re-enabled all of the modules that I disabled while I was troubleshooting the issue and we were back in business.</p>
<h3>Archetyped</h3>
<p>I recently decided to change the name of the <a href="http://archetyped.com/know/" title="Know">Dump</a> section since the content I&#8217;ve been adding to has been more resource-based as opposed to just brain <em>dumps</em> that I initially imagined I would be using that section for (turns out that&#8217;s what the <a href="http://archetyped.com/blog/" title="Blog">Blog</a> section is good for).  While WordPress makes this a fairly painless process, as it provides the UI to change the section&#8217;s title and slug (used in the URI) as well as handling redirects for links to posts in the old section, I still had a bit of manual work to do.  Specifically, I had to change the icon used to specify the section content belongs to.</p>
<div id="attachment_570" class="wp-caption aligncenter" style="width: 101px"><img class="size-full wp-image-570" title="Old Dump Section Icon" src="http://archetyped.com/wp-content/uploads/icon_dump_old.gif" alt="" width="91" height="70" /><p class="wp-caption-text">Old Dump Section Icon</p></div>
<p>Since I was changing the icon text, I also decided to rectify something that started bugging me about these icons.  With text this small, Photoshop&#8217;s antialiasing causes the icon text to appear blurry and dull.  I don&#8217;t feel that they are clear enough, so I decided to remove the antialiasing all together since small text will generally be sharper and easier to read without any antialiasing applied.  However, it obviously would not do to have sharp text  just for one section, so I decided to change <em>all</em> of the icons.  It&#8217;s not really that bad, since there aren&#8217;t that many sections.</p>
<p><img class="aligncenter size-full wp-image-571" title="Old vs. New Icons" src="http://archetyped.com/wp-content/uploads/icon_comparison.gif" alt="" width="198" height="120" /></p>
<p>I think the new icons are much clearer and more readable so it was worth the time to rebuild all of the section icons.  All I really had to do to add them to the theme was overwrite the old image files with the newly generated ones.  Easy.</p>
<p>However, as I was testing the new icons, I noticed that the section descriptions were no longer showing up.</p>
<div id="attachment_572" class="wp-caption aligncenter" style="width: 517px"><img class="size-full wp-image-572" title="Section title and description" src="http://archetyped.com/wp-content/uploads/blog_title-description.gif" alt="" width="507" height="183" /><p class="wp-caption-text">Section title and description</p></div>
<p>I initially wasn&#8217;t sure why this was, but it seemed to be related to differences in WordPress 3.0 and earlier versions of WordPress as my test server (using 3.0) was having this issue, while another test server (that uses an earlier version of WordPress) does not.  By inspecting the query variables for the page, I was able to see that the global <code>$pages</code> variable was not being populated with the current page&#8217;s content, which caused an issue because the <code>get_the_content()</code> function used in the theme uses this variable to retrieve a post&#8217;s content.  To resolve this issue, I simply wrapped the page&#8217;s output in the following conditional statement to pre-populate all of the necessary variables with the page&#8217;s data.</p>
<pre class="brush:php">if ( have_posts() ) : the_post(); //Setup page data
/* Page Output */
endif; //End page output
</pre>
<p>Finally, it appears that my featured posts are no longer being properly retrieved.  As it stands, I&#8217;m not sure why this is, but it will have to wait until tomorrow as I&#8217;ve run out of time today.</p>
<p>Finding bugs is not always fun, but it is always good because it means that I&#8217;m able to fix an issue that I previously didn&#8217;t know about.  As much as I&#8217;d like my code to be perfect right out of the gate, I know there will always be room for improvement and optimization, so I&#8217;m thankful I at least came across these bugs before deploying my updates to my production server.</p>
<p><a href="http://archetyped.com/lab/names-taken-bugs-squashed/"> Names Taken, Bugs Squashed</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 4, 2010 11:21pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/names-taken-bugs-squashed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cornerstone: We have compatibility!</title>
		<link>http://archetyped.com/lab/cornerstone-we-have-compatibility/</link>
		<comments>http://archetyped.com/lab/cornerstone-we-have-compatibility/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 09:01:32 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Compatibility]]></category>
		<category><![CDATA[Cornerstone]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=542</guid>
		<description><![CDATA[<p><em>Compatibility is so (not) overrated</em></p>I made good progress today as I completed far more than expected while working to make Cornerstone compatible with Wordpress 3.0]]></description>
			<content:encoded><![CDATA[<p><em>Compatibility is so (not) overrated</em></p><p>Well that didn&#8217;t take as long as I expected it to.  While I still have some tests to run through, all work has been completed to make <a href="http://archetyped.com/tools/cornerstone/" title="Cornerstone">Cornerstone</a> compatible with WordPress 3.0!  I was expecting this to take at least 2-3 days due to the amount of code I had to check, but after finishing what I had scheduled for today, I decided to just keep chugging along and ended up finishing everything on my list without much delay.</p>
<p>Here&#8217;s a rundown of what I did today:</p>
<h3>Structure</h3>
<h4>Permalink Structure</h4>
<p>The first thing on the list was adjusting the permalink structure for posts with custom post types.  By default, the structure for posts with custom post types is <code>/post-type/post-name/</code>, which doesn&#8217;t cut it when posts can now be added to a specific section regardless of their post type.  What we want is for all posts to use <code>/section-name/post-name/</code> as their permalink structure.  I didn&#8217;t think this would be too difficult to rectify, and thankfully it wasn&#8217;t.  A quick look at <code>get_permalink()</code> (which Cornerstone hooks into to filter a post&#8217;s permalink) revealed that posts with custom post types were processed separately from standard posts:</p>
<pre class="brush:php;first-line:110">elseif ( in_array($post-&gt;post_type, get_post_types( array('_builtin' =&gt; false) ) ) )
	return get_post_permalink($post, $leavename, $sample);</pre>
<p>So in addition to hooking into <code>post_link</code> for standard posts, we also need to hook into <code>post_type_link</code> (which is called in <code>get_post_permalink()</code>).  Thankfully, both filter hooks pass the default permalink along with the current post&#8217;s data (except that <code>post_link</code> supplies the entire post object while <code>post_type_link</code> only supplies the post&#8217;s ID) so the same handler can be used for both:</p>
<pre class="brush:php">add_filter('post_link', $this-&gt;m('post_link'), 10, 2); //Standard posts
add_filter('post_type_link', $this-&gt;m('post_link'), 10, 2);  //Custom post types</pre>
<p>With this additional hook added, posts with custom post types now have <code>/section-name/post-name/</code> as their permalink structure.</p>
<h4>Post Sections</h4>
<p><a href="http://archetyped.com/wp-content/uploads/cnr_structure_section_selec.gif"><img class="alignnone size-full wp-image-549" title="Section Selection" src="http://archetyped.com/wp-content/uploads/cnr_structure_section_selec.gif" alt="" width="327" height="112" /></a></p>
<p>Next on my list was providing the UI on the edit forms for custom post types to select the section the post should be saved to.  Prior to WordPress 3.0, I added the section selector to the edit form sidebar by hooking into the <code>do_meta_boxes</code> action.  This works exactly as it should on the edit form for custom post types in WordPress 3.0, save for one difference&#8211; the action hook now passes the <em>post type</em> of the post currently being edited (as opposed to being hardcoded as &#8220;post&#8221; in earlier versions of WordPress).  Since we only wanted the section selector to be added to the sidebar of the <em>post </em>edit form, that&#8217;s exactly what the handler looked for before adding the section selector meta box:</p>
<pre class="brush:php">if ( 'post' == $type &amp;&amp; 'side' == $context )
	add_meta_box($this-&gt;add_prefix('section'), 'Section', $this-&gt;m('admin_post_sidebar_section'), 'post', 'side', 'high');</pre>
<p>Since the post type can now be variable, the condition for adding a the section selector meta box needed to be expanded a bit:</p>
<pre class="brush:php">$child_types = get_post_types(array('show_ui' =&gt; true, '_builtin' =&gt; false));
$child_types[] = 'post';
$side_context = 'side';
$priority = 'high';
if ( in_array($type, $child_types) &amp;&amp; $side_context == $context )
	add_meta_box($this-&gt;add_prefix('section'), __('Section'), $this-&gt;m('admin_post_sidebar_section'), $type, $context, $priority);</pre>
<p>Basically, all custom post types that would have an edit form are retrieved, the &#8220;post&#8221; post type is added to the array of possible post types, and a check is performed to see if the current post type is included in this array.  If so, the meta box is added and the section selector is displayed on edit form&#8217;s sidebar.  I also took this opportunity to move some of the values in the <code>add_meta_box</code> call out into separate variables to further simplify future maintenance.</p>
<h3>Taxonomies</h3>
<p><a href="http://archetyped.com/wp-content/uploads/cnr_taxonomies.gif"><img class="alignnone size-full wp-image-550" title="Taxonomies" src="http://archetyped.com/wp-content/uploads/cnr_taxonomies.gif" alt="" width="327" height="359" /></a><br />
I honestly thought it would take longer than it did to go through and fix the compatibility issues with permalinks and section selection so that was really all I had intended to work on today.  After finishing them so quickly, I decided that I would work on getting the rest of the edit form for custom post types to work properly.  The first thing was adding access to the standard post taxonomies (specifically, categories and post tags) on custom post type edit forms.</p>
<p>Once again, I thought I was in for some digging through WordPress&#8217; code, and once again, it turned out to be incredibly simple.  WordPress provides the <a href="http://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type"><code>register_taxonomy_for_object_type()</code></a> function that makes it very simple to connect a previously-registered taxonomy to a post type.  I could have used this, but WordPress <em>also</em> provides the ability to automatically register a taxonomy with a post type at the same time the post type itself is registered.  This is accomplished by adding a single item to the arguments array passed to <code>register_post_type()</code> when registering a new post type:</p>
<pre class="brush:php">//...additional arguments for the post type being registered
'taxonomies' =&gt; get_object_taxonomies('post')
</pre>
<p>By using <code>get_object_taxonomies('post')</code>, we can be sure that any taxonomies registered to the standard &#8220;post&#8221; post type is also registered to our custom content types.  In the future, I may add functionality to enable more control over which custom content types will inherit the taxonomies from WordPress&#8217; built-in post type, but for now this makes the edit form for custom content types functional and useful for those wanting to use the same basic taxonomies with all content types.</p>
<h3>Content Type Fields</h3>
<p><a href="http://archetyped.com/wp-content/uploads/cnr_content_type_fields.gif"><img class="alignnone size-full wp-image-548" title="Content Type Fields" src="http://archetyped.com/wp-content/uploads/cnr_content_type_fields.gif" alt="" width="247" height="327" /></a><br />
The final thing that remained to make Cornerstone compatible with WordPress 3.0 was displaying a content type&#8217;s predefined fields on the edit form.  The implementation prior to WordPress 3.0 employed multiple hooks to make it all work (since custom post type functionality was not as fully fleshed out as it is in 3.0), but now all I needed was one hook:</p>
<pre class="brush:php">add_action('do_meta_boxes', $this-&gt;m('admin_do_meta_boxes'), 10, 3);
//Build UI on post edit form
</pre>
<p>The handler is also very simple.  Once it confirms that the context is appropriate for building the fields for a content type, the processing is handed off to an instance object of the content type definition which has a method to build the fields in meta boxes for output on the edit form:</p>
<pre class="brush:php">function admin_do_meta_boxes($type, $context, $post) {
	//Validate $type. Should be 'post', 'page', or a custom post type for our purposes
	if ( in_array($type, array_merge(array_keys($this-&gt;get_types()), array('post', 'page'))) ) {
		//Get content type definition
		$ct =&amp; $this-&gt;get_type($post);
		//Pass processing to content type instance
		$ct-&gt;admin_do_meta_boxes($type, $context, $post);
	}
}
</pre>
<h3>Coming up next</h3>
<p>With the compatibility work on Cornerstone out of the way, I can now continue where I left off before upgrading to WordPress 3.0 and start developing additional features and functionality for Cornerstone.  Here&#8217;s my basic plan:</p>
<ol>
<li>Complete compatibility testing, fixing any small issues I missed</li>
<li>Develop UI for managing custom content types and their fields</li>
</ol>
<p>The content type/field management UI will be heavy with &#8220;drag and drop&#8221; functionality to make adding and customizing content types very quick and simple.  This is one of the last major milestones I&#8217;m working towards before Cornerstone enters the public beta phase, so I am pretty excited to get started on this.</p>
<p>At the same time, I have a few other ideas for projects that have been dancing around in my head for the past few days and I&#8217;ve been itching to explore some of them.  I don&#8217;t intend to stay away from Cornerstone development for too long, but several of these projects will actually be using Cornerstone as the foundation of their functionality so I&#8217;ll still be working on Cornerstone as I explore these other projects.</p>
<p><a href="http://archetyped.com/lab/cornerstone-we-have-compatibility/"> Cornerstone: We have compatibility!</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on August 2, 2010 11:01pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/cornerstone-we-have-compatibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cornerstone: All Content Types Aboard!</title>
		<link>http://archetyped.com/lab/cornerstone-all-content-types-aboard/</link>
		<comments>http://archetyped.com/lab/cornerstone-all-content-types-aboard/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 06:36:21 +0000</pubDate>
		<dc:creator>Sol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Content Types]]></category>
		<category><![CDATA[Hooks]]></category>
		<category><![CDATA[Post Types]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://archetyped.com/?p=527</guid>
		<description><![CDATA[<p><em>Queries are blind when it comes to custom content types</em></p>Work continues on Wordpress 3.0 compatibility for Cornerstone.  Custom content types get their piece of the pie.]]></description>
			<content:encoded><![CDATA[<p><em>Queries are blind when it comes to custom content types</em></p><p>My main goal today was including all content items (regardless of post type) for display on the front end.  This would return content type functionality to what it was prior to WordPress 3.0.  Custom post types are now 1st-class citizens in WordPress, each with their own place in the <code>post_type</code> column of the <code>wp_posts</code> table.  They&#8217;ve been promoted to the <em>big show</em> and are no longer relagated to the <code>wp_postmeta</code> table with all the other <em>secondary</em> post data.</p>
<p>For my purposes, custom <em>content types</em> (Cornerstone&#8217;s extension of WordPress&#8217; own <em>post types</em>) should generally not interfere with the retrieval of content, but serve primarily to indicate the types of metadata a content item can/should contain.  Since I&#8217;ve decided to synchronize custom content types with WordPress&#8217; custom post types for better compatibility, we now have a small issue since the default posts query (e.g. used on the home page, etc.) only retrieves content items with &#8220;post&#8221; as the post type, so items with other content types are left in the dust and not retrieved.  Isn&#8217;t that just how it always is?  You get a leg up in the world, only to be pushed back down.  I say equality for all content types!</p>
<p>To rectify this and allow all content items regardless of content type to be retrieved in default post queries, I&#8217;ve hooked into the <code>pre_get_posts</code> action to modify the query before any posts are retrieved.</p>
<pre class="brush:php">add_action('pre_get_posts', $this-&gt;m('pre_get_posts'), 20);
//Calls internal method</pre>
<p>When the <code>pre_get_posts</code> action is fired, Cornerstone&#8217;s <code>pre_get_posts</code> method:</p>
<ul>
<li>Checks to make sure the query is a standard post query</li>
<li>Retrieves all custom content types and adds them to the <code>post_type</code> query variable</li>
</ul>
<pre class="brush:php">/**
 * Modifies query parameters to include custom content types
 * @param WP_Query $q Reference to WP_Query object being used to perform posts query
 * @see WP_Query for reference
 */
function pre_get_posts($q) {
	$qv =&amp; $q-&gt;query_vars;
	$pt =&amp; $qv['post_type'];

	/* Do not continue processing if:
	 * &gt; In admin section
	 * &gt; Single object requested
	 * &gt; More than one post type is already specified
	 * &gt; Post type other than 'post' is supplied
	 */
	if ( is_admin()
	|| is_singular()
	|| ( is_array($pt)
		&amp;&amp; ( count($pt) &gt; 1
			|| 'post' != $pt[0] )
		)
	|| !in_array($pt, array('post', null))
	) {
		return false;
	}
	$default_types = $this-&gt;get_default_post_types();
	$custom_types = array_diff(array_keys($this-&gt;get_types()), $default_types);
	if ( !count($custom_types) )
		return false;
	//Wrap post type in array
	if ( empty($pt) || is_null($pt) )
		$pt = array('post');
	if ( !is_array($pt) )
		$pt = array($pt);
	//Add custom types to query
	foreach ( $custom_types as $type ) {
		$pt[] = $type;
	}
}
</pre>
<p>With the additional content types added to the query, all content items are now retrieved in standard post queries (ultimately, each custom content type will have the option to define whether it is included in standard queries or not).  All is now right with the world and I can sleep soundly knowing that custom content types are getting a <a href="http://www.thefreedictionary.com/fair+shake">fair shake</a>.</p>
<h3>Next</h3>
<p>Work on content types continues as permalinks for content with custom post types need to have the ability use the <code>section-name/post-name</code> permalink structure enabled by Cornstone (by default it&#8217;s <code>post-type/post-name</code>).  Once that&#8217;s sorted, I&#8217;m heading back to the admin section to work on the edit form for items with custom post types.</p>
<p><a href="http://archetyped.com/lab/cornerstone-all-content-types-aboard/"> Cornerstone: All Content Types Aboard!</a> was originally published on <a href="http://archetyped.com">Archetyped</a> on July 30, 2010 08:36pm</p>]]></content:encoded>
			<wfw:commentRss>http://archetyped.com/lab/cornerstone-all-content-types-aboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
