<?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>scribu &#187; WordPress</title>
	<atom:link href="http://scribu.net/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://scribu.net</link>
	<description>Hello, this is where scribu geeks out</description>
	<lastBuildDate>Thu, 11 Mar 2010 13:48:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Smarter Navigation: Version 1.2</title>
		<link>http://scribu.net/wordpress/smarter-navigation/sn-1-2.html</link>
		<comments>http://scribu.net/wordpress/smarter-navigation/sn-1-2.html#comments</comments>
		<pubDate>Sat, 06 Mar 2010 13:24:18 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[Smarter Navigation]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=627</guid>
		<description><![CDATA[This version requires PHP 5. If you&#8217;re getting an error on activation, it means you&#8217;re running PHP 4.
Two template tags have been added: 
If you have posts in multiple categories, you can use get_referrer_category() to retrieve the category object, based on the referrer url.
get_referrer_url() returns the full URL of the referrer.
Also, there are two extra [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This version requires PHP 5. If you&#8217;re getting an error on activation, it means you&#8217;re running PHP 4.</strong></p>
<p>Two template tags have been added: </p>
<p>If you have posts in multiple categories, you can use <code>get_referrer_category()</code> to retrieve the category object, based on the referrer url.</p>
<p><code>get_referrer_url()</code> returns the full URL of the referrer.</p>
<p>Also, there are two extra arguments for previous_post_smart() and next_post_smart(): $in_same_cat and $excluded_categories.</p>
<p>This is how the function prototype looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">previous_post_smart<span style="color: #009900;">&#40;</span>
	<span style="color: #000088;">$format</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&amp;laquo; %link'</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'%title'</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$fallback</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$in_same_cat</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$excluded_categories</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/smarter-navigation/sn-1-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Front-end Editor: Common Mistakes In Themes</title>
		<link>http://scribu.net/wordpress/front-end-editor/common-mistakes-in-themes.html</link>
		<comments>http://scribu.net/wordpress/front-end-editor/common-mistakes-in-themes.html#comments</comments>
		<pubDate>Thu, 25 Feb 2010 13:09:57 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[Front-end Editor]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=622</guid>
		<description><![CDATA[Although Front-end Editor tries to be compatible with as many themes as possible, there&#8217;s only so much it can do.
No wp_footer() call
Lots of plugins, including this one, rely on the wp_footer() call to include their JavaScript files. Open your theme&#8217;s footer.php file and make sure you have this line somewhere:

&#60;?php wp_footer&#40;&#41;; ?&#62;]]></description>
			<content:encoded><![CDATA[<p>Although Front-end Editor tries to be compatible with as many themes as possible, there&#8217;s only so much it can do.</p>
<h3>No wp_footer() call</h3>
<p>Lots of plugins, including this one, rely on the <code>wp_footer()</code> call to include their JavaScript files. Open your theme&#8217;s <code>footer.php</code> file and make sure you have this line somewhere:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Using the_title() in the wrong places</h3>
<p>A mistake I see in a lot of themes is code like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Permanent Link to <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;</pre></div></div>

<p>This causes all sorts of problems. You should use <code>the_title_attribute()</code> instead:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Permanent Link to <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;</pre></div></div>

<h3>No id &#038; class attributes for dynamic sidebars</h3>
<p>If you want to have editable text widgets, you&#8217;ll have to change code like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My Sidebar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h4&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h4&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My Sidebar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h4&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h4&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can use &lt;li&gt;s instead of &lt;div&gt;s. The important part is <code>id="%1$s" class="widget %2$s"</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/front-end-editor/common-mistakes-in-themes.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Front-end Editor: Version 1.7</title>
		<link>http://scribu.net/wordpress/front-end-editor/fee-1-7.html</link>
		<comments>http://scribu.net/wordpress/front-end-editor/fee-1-7.html#comments</comments>
		<pubDate>Thu, 18 Feb 2010 00:56:40 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[Front-end Editor]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=617</guid>
		<description><![CDATA[If your theme supports native thumbnails (introduced in WordPress 2.9), you will be able to change them by double-clicking on them. Also, you now have editable_option().]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s get right into it:</p>
<h3>Post thumbnail switching</h3>
<p>If your theme supports <a href="http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/">native thumbnails</a> (introduced in WordPress 2.9), you will be able to change them by double-clicking on them.</p>
<h3>Editable options</h3>
<p>Similarly to editable_images(), you can now have editable bits of text anywhere in your theme. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> editable_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blurb'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
[...]
&nbsp;
Today's mood: <span style="color: #000000; font-weight: bold;">&lt;?php</span> editable_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mood'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>It&#8217;s like text widgets, without the widgets. <img src='http://scribu.net/wp/wp-content/plugins/ym_smilies/images/yahoo_smiley.gif' alt='&#58;&#45;&#41; ' class='wp-smiley' width='18' height='18' title='&#58;&#45;&#41; ' /></p>
<h3>No more autogrow</h3>
<p>If you&#8217;ve been using the basic text editor, you&#8217;ve probably had your share of frustration with the autogrow script. After switching from Autogrow to Growfield without much improvement, I&#8217;ve decided to stick to a normal textarea with a scrollbar.</p>
<p>The rich editor is not affected by this.</p>
<h3>Configurable nicEdit</h3>
<p>I&#8217;ve added two buttons to the rich editor panel: font-family and font-color. More importantly, you can now select which buttons you want to use. Just paste this code in your theme&#8217;s functions.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> configure_fee_nicedit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'buttonList'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'bold'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'italic'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'strikethrough'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'left'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'center'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'right'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$config</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'front_end_editor_nicedit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'configure_fee_nicedit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>See the available <a href="http://nicedit.pbworks.com/Configuration+Options">configuration options</a>.</p>
<h3>Upgrade instructions</h3>
<p>If you have custom code written for the plugin, read on:</p>
<p>Renamed hooks:</p>
<p>front_ed_fields -> front_end_editor_fields<br />
front_ed_allow -> front_end_editor_allow<br />
front_ed_disable -> front_end_editor_disable</p>
<p>Renamed CSS classes:</p>
<p>.front-ed -> .fee-field<br />
.front-ed-{filter} -> .fee-filter-{filter}<br />
.front-ed-container -> .fee-form</p>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/front-end-editor/fee-1-7.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP-UserOnline: Version 2.60</title>
		<link>http://scribu.net/wordpress/wp-useronline/wu-2-60.html</link>
		<comments>http://scribu.net/wordpress/wp-useronline/wu-2-60.html#comments</comments>
		<pubDate>Fri, 12 Feb 2010 01:44:00 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[WP-UserOnline]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=616</guid>
		<description><![CDATA[Last month, Lester Chan, one of the most respected plugin authors in the WordPress world, has announced that he will no longer be able to continue development on his plugins.

Since I use WP-UserOnline on all of my sites, I adopted it (along with WP-PageNavi) and will continue to support it.]]></description>
			<content:encoded><![CDATA[<p>Last month, Lester Chan, one of the most respected plugin authors in the WordPress world, has <a href="http://lesterchan.net/wordpress/2010/01/28/all-good-things-must-come-to-an-end/">announced</a> that he will no longer be able to continue development on his plugins.</p>
<p>Since I use WP-UserOnline on all of my sites, I adopted it (along with WP-PageNavi) and will continue to support it.</p>
<p>Version 2.60 has a few noticeable enhancements:</p>
<p>When viewing the list of online users, admin pages will also have pretty titles, instead of URLs.</p>
<p>Clicking on a user&#8217;s IP addresses now takes you to a much more helpful page on <a href="http://domaintools.com">domaintools.com</a> instead of <a href="http://arin.net">arin.net</a>. As such, I decide to removed the country flag icons, since they slowed down page loads and were a hassle to set up.</p>
<p>Finally, to completely uninstall the plugin, it&#8217;s enough to delete it through the WordPress admin.</p>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/wp-useronline/wu-2-60.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to load JavaScript like a WordPress Master</title>
		<link>http://scribu.net/wordpress/optimal-script-loading.html</link>
		<comments>http://scribu.net/wordpress/optimal-script-loading.html#comments</comments>
		<pubDate>Sat, 16 Jan 2010 00:47:34 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=599</guid>
		<description><![CDATA[If you&#8217;re involved in WordPress development, a challenge that you&#8217;re going to face sooner or later is how to include JavaScript files efficiently.

In this tutorial, I&#8217;m going to show you the best way to do that.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re involved in WordPress development, a challenge that you&#8217;re going to face sooner or later is how to include JavaScript files efficiently.</p>
<p>In this tutorial, I&#8217;m going to show you the best way to do that.</p>
<p>Let&#8217;s say you have a plugin that adds a custom shortcode. The shortcode needs some JavaScript code which requires jQuery.</p>
<p>If you&#8217;re just starting out with WordPress development, you might be tempted to write something like this:</p>
<p><span id="more-599"></span></p>
<h3>How a WordPress Youngling does it</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action('wp_head', 'add_my_script');
&nbsp;
function add_my_script() { ?&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpurl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/wp-content/plugins/my-plugin/jquery.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpurl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/wp-content/plugins/my-plugin/my-script.js&quot;&gt;&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Let&#8217;s see what&#8217;s wrong with that approach:</p>
<p>Firstly, since WordPress 2.6, the user can move the <code>wp-content</code> directory wherever he wants. What does that mean? That&#8217;s right: instant plugin breakage.</p>
<p>Secondly, if the user installs another plugin that also uses jQuery, the page will end up with jQuery being loaded twice.</p>
<p>Fortunately, WordPress lends us a hand with these two problems:</p>
<h3>How a young Padawan does it</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_redirect'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_my_script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> add_my_script<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script'</span><span style="color: #339933;">,</span> plugins_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script.js'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above script ultimately does what the first one does, except:</p>
<ul>
<li>it gets the correct path for the file</li>
<li>it checks if jQuery has already been included or not</li>
<li>the script tag is written in the footer, so the page loads faster</li>
</ul>
<p>That&#8217;s an obvious improvement. But what if the shortcode appears on a single page?</p>
<p>You&#8217;re needlessly including a file 99% of the time, causing slower page loads.</p>
<p>Notice that in the last two examples, we&#8217;ve been using the <code>template_redirect</code> action.</p>
<p>The trouble with <code>wp_enqueue_script()</code> is that you have to call it before <code>wp_head()</code> fires. So,  before the page is rendered, you have to decide if you should add your script or not. Not an easy call to make, is it?</p>
<p>Well, there&#8217;s a secret method that will let you enqueue scripts <em>after</em> the entire page has been displayed.</p>
<h3>The Jedi Knight way</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_footer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'print_my_script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> print_my_script<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$add_my_script</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$add_my_script</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	wp_register_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script'</span><span style="color: #339933;">,</span> plugins_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script.js'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	wp_print_scripts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case, the script will be enqueued only if the <code>$add_my_script</code> global was set at some point during the rendering of the page. </p>
<p>The key here is that you&#8217;re calling <code>wp_print_scripts()</code> directly, instead of relying on WordPress to do it for you.</p>
<p>It will still check if jQuery was already enqueued or not.</p>
<p>You can set the <code>$add_my_script</code> flag from any function or method, including from a shortcode handler:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myshortcode'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_shortcode_handler'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_shortcode_handler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$add_my_script</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$add_my_script</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// actual shortcode handling here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So, the script will be added if <code>[myshortcode ...]</code> was found in any of the posts on the current page.</p>
<p>Nothing more to do here, except wrap it up in a nice class:</p>
<h3>The Jedi Master way</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> My_Shortcode <span style="color: #009900;">&#123;</span>
	static <span style="color: #000088;">$add_script</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myshortcode'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'handle_shortcode'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_footer'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_script'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> handle_shortcode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$add_script</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// actual shortcode handling here</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> add_script<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$add_script</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
		wp_register_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script'</span><span style="color: #339933;">,</span> plugins_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script.js'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		wp_print_scripts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
My_Shortcode<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I hope this tutorial has helped you on your way to mastering WordPress script loading.</p>
<p>Further reading:</p>
<ul>
<li><a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">wp_enqueue_script() reference</a></li>
<li><a href="http://www.appchain.com/how-to-get-a-wordpress-plugin-directory-path-the-best-easyest-correct-way/">Using plugins_url()</a></li>
<li><a href="http://codex.wordpress.org/Shortcode_API">Shortcode API</a></li>
<li><a href="http://en.wikipedia.org/wiki/Jedi#Ranks">Jedi Ranks</a></li>
</ul>
<p>PS: This post was prompted by <a href="http://beerpla.net/2010/01/15/follow-up-to-loading-css-and-js-conditionally/">this question</a> from Artem.</p>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/optimal-script-loading.html/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Smart Archives Reloaded: Version 1.9</title>
		<link>http://scribu.net/wordpress/smart-archives-reloaded/sar-1-9.html</link>
		<comments>http://scribu.net/wordpress/smart-archives-reloaded/sar-1-9.html#comments</comments>
		<pubDate>Tue, 12 Jan 2010 16:26:28 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[Smart Archives Reloaded]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=611</guid>
		<description><![CDATA[Lots of goodies in this release, based on the feedback and requests I got from you guys (and gals).

First off, there&#8217;s a new format called &#8220;menu&#8221;. It&#8217;s basically the year and month menu from the fancy format, but without the post list. It&#8217;s meant to be displayed on year and month based archives.]]></description>
			<content:encoded><![CDATA[<p>Lots of goodies in this release, based on the feedback and requests I got from you guys (and gals).</p>
<h3>The Menu Format</h3>
<p>First off, there&#8217;s a new format called &#8220;menu&#8221;. It&#8217;s basically the year and month menu from the fancy format, but without the post list. It&#8217;s meant to be displayed on year and month based archives, to aid navigation.</p>
<p>Usually, those archives are handled by the <code>archive.php</code> template in your theme, so that&#8217;s where you should use it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> smart_archives<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'format=menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>New arguments</h3>
<p>There are also two new arguments:</p>
<p><strong>month_format</strong> &#8211; can be one of &#8216;numeric&#8217;, &#8217;short&#8217; and &#8216;long&#8217;</p>
<p><strong>posts_per_month</strong> &#8211; set the number of posts displayed per month; by default, all posts are displayed.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> smart_archives<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts_per_month=25'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Finally, you can now customize the look and feel more easily. See <a href="http://scribu.net/wordpress/smart-archives-reloaded/advanced-tweaking.html">Advanced Tweaking</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/smart-archives-reloaded/sar-1-9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smart Archives Reloaded: Advanced Tweaking</title>
		<link>http://scribu.net/wordpress/smart-archives-reloaded/advanced-tweaking.html</link>
		<comments>http://scribu.net/wordpress/smart-archives-reloaded/advanced-tweaking.html#comments</comments>
		<pubDate>Tue, 12 Jan 2010 15:25:01 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[Smart Archives Reloaded]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=610</guid>
		<description><![CDATA[Since version 1.9, you can make modifications to the plugin output, without having to modify the plugin code. This way, your tweaks won&#8217;t be lost when you upgrade the plugin.

If you want to customize the appearance of the archives using your own CSS, here&#8217;s how you do it:]]></description>
			<content:encoded><![CDATA[<p>Since version 1.9, you can make modifications to the plugin output, without having to modify the plugin code. This way, your tweaks won&#8217;t be lost when you upgrade the plugin.</p>
<h3>Custom styling</h3>
<p>If you want to customize the appearance of the archives using your own CSS, here&#8217;s how you do it:</p>
<ol>
<li>Add this code to your theme&#8217;s <code>functions.php</code> file:</li>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smart_archives_load_default_styles'</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return false;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<li>Copy everything from <code>smart-archives-reloaded/inc/styles.dev.css</code> into your theme&#8217;s <code>style.css</code> file.</li>
<li>Change the CSS in your theme&#8217;s <code>style.css</code> file, as needed.</li>
</ol>
<h3>Custom markup</h3>
<p>If you want to go one step further and change the generated HTML markup, you can do that too (understanding of <a href="http://www.php.net/manual/en/language.oop5.inheritance.php">object inheritance</a> is required).</p>
<p>First, take a look at the <code>SAR_Generator</code> class (in <code>smart-archives-reloaded/generator.php</code>).</p>
<p>In your theme&#8217;s <code>functions.php</code> file, you can extend that class, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">smart_archives_load_default_generator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SAR_Custom_Generator <span style="color: #000000; font-weight: bold;">extends</span> SAR_Generator <span style="color: #009900;">&#123;</span>
	protected static <span style="color: #000000; font-weight: bold;">function</span> generate_fancy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// your custom code here</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	protected static <span style="color: #000000; font-weight: bold;">function</span> generate_block<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// more of your custom code here</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, all you have to do is add the &#8216;generator&#8217; argument to the template tag:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> smart_archives<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'generator=SAR_Custom_Generator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/smart-archives-reloaded/advanced-tweaking.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Front-end Editor: Version 1.6</title>
		<link>http://scribu.net/wordpress/front-end-editor/fee-1-6.html</link>
		<comments>http://scribu.net/wordpress/front-end-editor/fee-1-6.html#comments</comments>
		<pubDate>Fri, 01 Jan 2010 12:10:39 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[Front-end Editor]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=607</guid>
		<description><![CDATA[The number of editable elements continues to grow with this version of your favourite inline editor for WordPress:

Besides tags and terms, you can now edit categories as well, using the same interface. They all have autosuggest enabled, to make it easier to work with.

Custom fields with multiple values can also be edited now.]]></description>
			<content:encoded><![CDATA[<p>The number of editable elements continues to grow with this version of your favourite inline editor for WordPress:</p>
<p>Besides tags and terms, you can now edit categories as well, using the same interface. They all have autosuggest enabled, to make it easier to work with.</p>
<p>Custom fields with multiple values can also be edited now. Here&#8217;s a code example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> get_editable_post_meta<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_key'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$values</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;</pre></div></div>

<p>Finally, you can now edit all widget titles, not just titles of text widgets.</p>
<p>Other enhancements:</p>
<ul>
<li>optimized script loading</li>
<li>fixed issue with Internet Explorer</li>
<li>fixed issue with comment paragraphs</li>
<li>fixed issues with the <code>$post</code> global</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/front-end-editor/fee-1-6.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Idea Behind WP Questions</title>
		<link>http://scribu.net/wordpress/idea-behind-wp-questions.html</link>
		<comments>http://scribu.net/wordpress/idea-behind-wp-questions.html#comments</comments>
		<pubDate>Sat, 26 Dec 2009 16:57:46 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[FLOSS]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=606</guid>
		<description><![CDATA[I was just reading this inspiring article called Five things Free Software taught me. One of the things that stuck with me is the idea that knowledge tends to spread, beyond any obstacle.

So instead of working to prevent this spread, why not encourage it?]]></description>
			<content:encoded><![CDATA[<p>I was just reading this inspiring article called <a href="http://trombonechamp.wordpress.com/2009/12/20/five-things-free-software-has-taught-me/">Five things Free Software taught me</a>. One of the things that stuck with me is the idea that knowledge tends to spread, beyond any obstacle.</p>
<blockquote><p>So instead of working to prevent this spread, why not encourage it?  Why not get the ideas, capabilities, and functionality of any given piece of software out to as many people as possible and kindle the flame?  There are many ways to make money, so why choose a method that requires investing just as much time and effort into making software that lots of people want to use as trying to prevent the usage of said software?  It sounds counterintuitive and/or just plain stupid on paper, but is generally seen as the traditional and conservative way to do it.  Physical products must be treated differently than knowledge.</p></blockquote>
<p><span id="more-606"></span></p>
<p>In the WordPress world, people are constantly trying to find new business models that make sense in the context of GPL software. An interesting approach is the recently launched <a href="http://www.wpquestions.com/">WP Questions</a> site. Here&#8217;s how it works:</p>
<p>You ask a support question related to WordPress and put a price tag on it. Whoever answers your question gets that amount of money from you. Note that anyone can see the questions and the answers to them.*</p>
<p>What you&#8217;re paying for is not the knowledge itself &#8211; you could get that free of charge, by asking in the WordPress.org <a href="http://wordpress.org/support/">support forums</a>. But by asking on WP Questions, you have a higher chance of getting a timely answer from one or more knowledgeable people, whereas in the WP.org forums your question could simply be overlooked or be given a half-baked answer.</p>
<p>I really think this could work. With the ever-growing user base of WordPress, a need for reliable, high-quality support is starting to appear. See <a href="http://wphelpcenter.com/">WP Help Center</a> for instance.</p>
<p>So what do you think? Will WP Questions still be here next year?</p>
<p>____</p>
<p>* &#8230;at least until an answer is approved. There&#8217;s a search field, but it would be nice if the site had a public archive of questions answered in the past.</p>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/idea-behind-wp-questions.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Front-end Editor: Developer Guide</title>
		<link>http://scribu.net/wordpress/front-end-editor/developer-guide.html</link>
		<comments>http://scribu.net/wordpress/front-end-editor/developer-guide.html#comments</comments>
		<pubDate>Sun, 20 Dec 2009 16:05:01 +0000</pubDate>
		<dc:creator>scribu</dc:creator>
				<category><![CDATA[Front-end Editor]]></category>

		<guid isPermaLink="false">http://scribu.net/?p=467</guid>
		<description><![CDATA[This post contains technical information for developers who want to create their own editable fields.]]></description>
			<content:encoded><![CDATA[<div class="notice">editable_option() has been integrated into version 1.7</div>
<p>This post contains technical information for developers who want to add their own editable fields.</p>
<p>We&#8217;re going to enable any option to be editable from the front-end.</p>
<h4>The filter</h4>
<p>The essential element of each editable field is a WordPress filter. You can use either an <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference">existing filter</a>, or a custom one.</p>
<p>We&#8217;re going to use a new one:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> editable_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'editable_option'</span><span style="color: #339933;">,</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, <code>editable_option()</code> simply wraps the value returned by get_option() in a filter.</p>
<p>In your theme, you can now write:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> editable_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_option'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> editable_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_other_option'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;</pre></div></div>

<p><span id="more-467"></span></p>
<h4>The class</h4>
<p>Each editable field needs a class to handle retrieving and saving the edited content.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> My_Editable_Option <span style="color: #000000; font-weight: bold;">extends</span> FEE_Field_Base <span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * The type of object we're editing
	 * @return string
	 */</span>
	static <span style="color: #000000; font-weight: bold;">function</span> get_object_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'option'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called when generating the HTML on the front-end
	 * Wraps the $content in special markup, if the user has the right permissions
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> wrap<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">wrap</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called when a user double-clicks on an editable field
	 * Fetches the content to be edited
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called when a user clicks the &quot;Save&quot; button
	 * Saves the modified content and then returns it
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		update_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called at each step
	 * Confirms that the current user has the right permissions to edit the field
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> check<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> current_user_can<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manage_options'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, it&#8217;s pretty easy. There are a few other aspects that you can learn by looking at the built-in classes as reference. They can be found in the <a href="http://plugins.trac.wordpress.org/browser/front-end-editor/trunk/fields/">fields folder</a>.</p>
<h4>Connecting the dots</h4>
<p>Now all we need to do is to connect the class to the filter. Here&#8217;s how you do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> register_my_field<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_fronted_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'editable_option'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My_Editable_Option'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My Option'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'input'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'argc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'front_end_editor_fields'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'register_my_field'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here are the arguments you can set for <code>register_fronted_field()</code>:</p>
<ul>
<li><strong>class</strong> &#8211; the class which will handle the editing (mandatory)</li>
<li><strong>title</strong> &#8211; the field title (mandatory)</li>
<li><strong>type</strong> &#8211; input | textarea | rich (default: input)</li>
<li><strong>priority</strong> &#8211; the filter priority (default: 11)</li>
<li><strong>argc</strong> &#8211; number of args the filter accepts (default: 1)</li>
</ul>
<h4>Putting it all together</h4>
<p>Here&#8217;s all the code put together. Add it to your theme&#8217;s <code>functions.php</code> and &#8216;My Option&#8217; should appear in the list of fields on the plugin settings page:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> editable_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'editable_option'</span><span style="color: #339933;">,</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> My_Editable_Option <span style="color: #000000; font-weight: bold;">extends</span> FEE_Field_Base <span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * The type of object we're editing
	 * @return string
	 */</span>
	static <span style="color: #000000; font-weight: bold;">function</span> get_object_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'option'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called when generating the HTML on the front-end
	 * Wraps the $content in special markup, if the user has the right permissions
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> wrap<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">wrap</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called when a user double-clicks on an editable field
	 * Fetches the content to be edited
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called when a user clicks the &quot;Save&quot; button
	 * Saves the modified content and then returns it
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		update_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Called at each step
	 * Confirms that the current user has the right permissions to edit the field
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> check<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> current_user_can<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manage_options'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> register_my_field<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_fronted_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'editable_option'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My_Editable_Option'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My Option'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'input'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'argc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'front_ed_fields'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'register_my_field'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Giving back</h4>
<p>If you write a new editable field that you think will be useful for other users, post it in the support forum. I might include it in a future release of the plugin, giving you credit for it, of course.</p>
]]></content:encoded>
			<wfw:commentRss>http://scribu.net/wordpress/front-end-editor/developer-guide.html/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
