<?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>Viper007Bond.com &#187; Coding</title>
	<atom:link href="http://www.viper007bond.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.viper007bond.com</link>
	<description>Random stuff written by Alex Mills</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:44:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
	<atom:link rel='hub' href='http://www.viper007bond.com/?pushpress=hub'/>
		<item>
		<title>How To Remove (Or Change) &#8220;Private&#8221; Or &#8220;Protected&#8221; From WordPress Post&#160;Titles</title>
		<link>http://www.viper007bond.com/2011/12/20/how-to-remove-or-change-private-or-protected-from-wordpress-post-titles/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-remove-or-change-private-or-protected-from-wordpress-post-titles</link>
		<comments>http://www.viper007bond.com/2011/12/20/how-to-remove-or-change-private-or-protected-from-wordpress-post-titles/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 00:32:44 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3569</guid>
		<description><![CDATA[If you make a post private in WordPress, the post&#8217;s title with be prefixed with &#8220;Private&#8221;. The same will happen if you password protect the post, although it will be prefixed with &#8220;Protected&#8221;. If you&#8217;d like to remove these, just add the following code to your theme&#8217;s functions.php file: The above code will remove the [...]]]></description>
			<content:encoded><![CDATA[<p>If you make a post private in WordPress, the post&#8217;s title with be prefixed with &#8220;Private&#8221;. The same will happen if you password protect the post, although it will be prefixed with &#8220;Protected&#8221;. If you&#8217;d like to remove these, just add the following code to your theme&#8217;s <code>functions.php</code> file:</p>
<pre class="brush: php; title: ; notranslate">add_filter( 'private_title_format', 'yourprefix_private_title_format' );
add_filter( 'protected_title_format', 'yourprefix_private_title_format' );

function yourprefix_private_title_format( $format ) {
	return '%s';
}</pre>
<p>The above code will remove the prefix by changing the format from <code>Private: %s</code> and <code>Protected: %s</code> to just <code>%s</code> where <code>%s</code> is the existing post title.</p>
<p>If you&#8217;d like to change it to something else, you can just change what the function in my example returns. If you want to change them independently of each other, then you&#8217;ll need to use two separate callback functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/12/20/how-to-remove-or-change-private-or-protected-from-wordpress-post-titles/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How To Create Custom WordPress Cron&#160;Intervals</title>
		<link>http://www.viper007bond.com/2011/12/14/how-to-create-custom-wordpress-cron-intervals/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-create-custom-wordpress-cron-intervals</link>
		<comments>http://www.viper007bond.com/2011/12/14/how-to-create-custom-wordpress-cron-intervals/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 01:02:11 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cron_schedules]]></category>
		<category><![CDATA[wp_next_scheduled]]></category>
		<category><![CDATA[wp_schedule_event]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3550</guid>
		<description><![CDATA[This is mostly a reminder for myself so I can stop tracking it down every time I forget, but here&#8217;s how to have WordPress code execute on a different schedule than the default intervals of hourly, twicedaily, and daily. This specific example is for weekly execution. On a side note, I believe this must go [...]]]></description>
			<content:encoded><![CDATA[<p>This is mostly a reminder for myself so I can stop tracking it down every time I forget, but here&#8217;s how to have WordPress code execute on a different schedule than the default intervals of <code>hourly</code>, <code>twicedaily</code>, and <code>daily</code>. This specific example is for weekly execution.</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

// Add a new interval of a week
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'myprefix_add_weekly_cron_schedule' );
function myprefix_add_weekly_cron_schedule( $schedules ) {
	$schedules['weekly'] = array(
		'interval' =&gt; 604800, // 1 week in seconds
		'display'  =&gt; __( 'Once Weekly' ),
	);

	return $schedules;
}

// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_my_cron_action' ) ) {
	wp_schedule_event( time(), 'weekly', 'myprefix_my_cron_action' );
}

// Hook into that action that'll fire weekly
add_action( 'myprefix_my_cron_action', 'myprefix_function_to_run' );
function myprefix_function_to_run() {
	// Add some code here
}

?&gt;</pre>
<p>On a side note, I believe this must go in a plugin and not your theme&#8217;s <code>functions.php</code> which I hear loads too late.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/12/14/how-to-create-custom-wordpress-cron-intervals/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Two Handy Sublime Text 2&#160;Plugins</title>
		<link>http://www.viper007bond.com/2011/11/30/two-handy-sublime-text-2-plugins/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=two-handy-sublime-text-2-plugins</link>
		<comments>http://www.viper007bond.com/2011/11/30/two-handy-sublime-text-2-plugins/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 03:57:47 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Sublime Text 2]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3517</guid>
		<description><![CDATA[After using EditPlus for the better part of a decade, I made the switch to the totally awesome Sublime Text 2 text editor a few weeks back. One of the great things about Sublime is it&#8217;s support for plugins. Two such plugins I&#8217;d like to recommend are SublimeBrackets and SublimeTagmatcher. Both improve how the highlighting [...]]]></description>
			<content:encoded><![CDATA[<p>After using <a href="http://www.editplus.com/">EditPlus</a> for the better part of a decade, I made the switch to the totally awesome <a href="http://www.sublimetext.com/blog/articles/sublime-text-2-beta">Sublime Text 2</a> text editor a few weeks back. One of the great things about Sublime is it&#8217;s support for plugins.</p>
<p>Two such plugins I&#8217;d like to recommend are <a href="https://github.com/pyparadigm/SublimeBrackets">SublimeBrackets</a> and <a href="https://github.com/pyparadigm/SublimeTagmatcher">SublimeTagmatcher</a>. Both improve how the highlighting of opening and closing items are handled.</p>
<p>By default, Sublime just underlines paired brackets. When you have a ton of code, this can be really hard to see. SublimeBrackets changes this to something more apparent:</p>
<p><img src="http://www.viper007bond.com/wordpress/wp-content/uploads/2011/11/ssexample.png" alt="" title="SublimeBrackets" width="424" height="320" class="aligncenter size-full wp-image-3518" /></p>
<p>Much better, right? I personally use the solid background green style.</p>
<p>SublimeTagmatcher does something similar but for HTML tags. When you have your cursor inside of an HTML tag, it will highlight both the current tag and it&#8217;s opening or closing counterpart. This is helpful for making sure you have the correct number of opening and closing tags.</p>
<p><img src="http://www.viper007bond.com/wordpress/wp-content/uploads/2011/11/ssexample1.png" alt="" title="SublimeTagmatcher" width="512" height="336" class="aligncenter size-full wp-image-3519" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/11/30/two-handy-sublime-text-2-plugins/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Translating Strings In WordPress Containing Multiple&#160;Placerholders</title>
		<link>http://www.viper007bond.com/2011/11/02/translating-strings-in-wordpress-containing-multiple-placerholders/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=translating-strings-in-wordpress-containing-multiple-placerholders</link>
		<comments>http://www.viper007bond.com/2011/11/02/translating-strings-in-wordpress-containing-multiple-placerholders/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 19:35:29 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[translating]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3484</guid>
		<description><![CDATA[I really often see a common mistake made when translating strings in WordPress so I thought I&#8217;d write a blog post in order to shed more light on the issue. But first, here&#8217;s a quick refresher on how to internationalize code in WordPress: For dynamic strings, it&#8217;d be something like this: But what about when [...]]]></description>
			<content:encoded><![CDATA[<p>I really often see a common mistake made when translating strings in WordPress so I thought I&#8217;d write a blog post in order to shed more light on the issue.</p>
<p>But first, here&#8217;s a quick refresher on how to <a href="http://codex.wordpress.org/I18n_for_WordPress_Developers">internationalize code in WordPress</a>:</p>
<pre class="brush: php; light: true; title: ; notranslate">&lt;?php _e( 'Welcome to my blog!', 'my-plugin-text-domain' ); ?&gt;</pre>
<p>For dynamic strings, it&#8217;d be something like this:</p>
<pre class="brush: php; light: true; title: ; notranslate">&lt;?php printf(
	__( 'Welcome to my blog, %s!', 'my-plugin-text-domain' ),
	$name
); ?&gt;</pre>
<p>But what about when you have multiple variables to use in your string? A common mistake is to do something like this:</p>
<pre class="brush: php; light: true; title: ; notranslate">&lt;?php printf(
	__( 'Welcome to my blog, %s! Today\'s date is %s.', 'my-plugin-text-domain' ),
	$name,
	$date
); ?&gt;</pre>
<p>The issue with this is that you&#8217;re requiring the person&#8217;s name to always come before the date. If for internationalization reasons it needs to be in a different order, then it won&#8217;t work. You&#8217;ll end up with something like <code>Today's date is Alex. Welcome to my blog, November 2nd!</code>.</p>
<p>The solution is to use standard <a href="http://www.php.net/manual/en/function.sprintf.php#example-4273"><code>sprintf()</code> argument swapping</a> parameters:</p>
<pre class="brush: php; light: true; title: ; notranslate">&lt;?php printf(
	__( 'Welcome to my blog, %1$s! Today\'s date is %2$s.', 'my-plugin-text-domain' ),
	$name,
	$date
); ?&gt;</pre>
<p>Now translators are free to re-order the string to whatever makes the most sense for the language in question without having to worry the order of the variables.</p>
<p>For a more in-depth review of this, check out the <a href="http://codex.wordpress.org/I18n_for_WordPress_Developers#Placeholders">WordPress Codex</a> where many real world examples can be found.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/11/02/translating-strings-in-wordpress-containing-multiple-placerholders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Generate A Plaintext Data&#160;Table</title>
		<link>http://www.viper007bond.com/2011/10/11/code-snippet-generate-a-plaintext-data-table/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-snippet-generate-a-plaintext-data-table</link>
		<comments>http://www.viper007bond.com/2011/10/11/code-snippet-generate-a-plaintext-data-table/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 01:08:42 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Mike Adams]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3432</guid>
		<description><![CDATA[Inspired by some awesome-as-always code written by my co-worker Mike Adams, here&#8217;s a helper function to help create plaintext data tables in PHP. This is particularly useful for PHP-based CLI scripts (we use quite a few at Automattic) or for plaintext e-mails. But first, here&#8217;s an example output with the optional dividers enabled: ID &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by some awesome-as-always code written by my co-worker <a href="http://blogwaffe.com/">Mike Adams</a>, here&#8217;s a helper function to help create plaintext data tables in PHP. This is particularly useful for PHP-based CLI scripts (we use quite a few at Automattic) or for plaintext e-mails.</p>
<p>But first, here&#8217;s an example output with the optional dividers enabled:</p>
<pre>   ID | First Name     | Last Name
-------------------------------------
    1 | Alex           | Mills
    2 | John           | Smith
    3 | Barack         | Obama
    4 | Fred           | Flinstone
12345 | ReallyLongName | IsReallyLong</pre>
<p></p>
<p>This is the code I used to create the above example:</p>
<pre class="brush: php; title: ; notranslate">$data = array(
	'labels' =&gt; array(
		'ID' =&gt; 'ID',
		'firstname' =&gt; 'First Name',
		'lastname' =&gt; 'Last Name',
	),
	'align' =&gt; array(
		'ID' =&gt; 'right',
	),
	array(
		'ID' =&gt; 1,
		'firstname' =&gt; 'Alex',
		'lastname' =&gt; 'Mills',
	),
	array(
		'ID' =&gt; 2,
		'firstname' =&gt; 'John',
		'lastname' =&gt; 'Smith',
	),
	array(
		'ID' =&gt; 3,
		'firstname' =&gt; 'Barack',
		'lastname' =&gt; 'Obama',
	),
	// Array order doesn't matter as it's associative
	array(
		'ID' =&gt; 4,
		'lastname' =&gt; 'Flinstone',
		'firstname' =&gt; 'Fred',
	),
	array(
		'lastname' =&gt; 'IsReallyLong',
		'firstname' =&gt; 'ReallyLongName',
		'ID' =&gt; 12345,
	),
);

echo '&lt;pre&gt;';
table_output( $data );
echo '&lt;/pre&gt;';</pre>
<p>You can easily loop through your data and generate an array in that format. The arrays are associative so order doesn&#8217;t matter.</p>
<p>The <code>labels</code> array is optional and just allows you assign pretty labels for the columns. If this array is missing, then the data keys will be used.</p>
<p>The <code>align</code> array is also optional and allows you to pass a value of <code>right</code> in order to right-align the data in a column. Defaults to left align.</p>
<p>Now, to the functions that generate the table!</p>
<pre class="brush: php; title: ; notranslate">// Output a formatted table
function table_output( $data, $dividers = true ) {
	$rows = table_get_rows( $data, $dividers );

	echo implode( &quot;\n&quot;, $rows );
}

// Return an array of table rows
function table_get_rows( $data, $dividers = true ) {
	// Find the column keys to use (use the first data row)
	$columns = array_keys( $data[0] );

	// Create the labels if they're missing
	if ( empty( $data['labels'] ) )
		$data['labels'] = array_combine( $columns, $columns );

	// Calculate column widths
	foreach ( $data as $key =&gt; $item ) {
		if ( 'align' === $key )
			continue;

		foreach ( $item as $column =&gt; $value ) {
			$length = strlen( $value );

			if ( empty( $widths[$column] ) || $widths[$column] &lt; $length )
				$widths[$column] = $length;
		}
	}

	// Create the row sprintf() format
	foreach ( $columns as $column ) {
		$align = ( isset( $data['align'] ) &amp;&amp; isset( $data['align'][$column] ) &amp;&amp; 'right' == $data['align'][$column] ) ? '' : '-';
		$formats[] = '%' . $align . $widths[$column] . 's';
	}
	$divider = ( $dividers ) ? ' | ' : ' ';
	$format = implode( $divider, $formats );

	// Generate the label row
	$rows['labels'] = vsprintf( $format, _table_get_line_data( $columns, $data['labels'] ) );

	// Should there be a divider row?
	if ( $dividers )
		$rows['divider'] = str_repeat( '-', strlen( $rows['labels'] ) );

	// Generate the data rows
	foreach ( $data as $key =&gt; $values ) {
		if ( 'labels' === $key || 'align' === $key )
			continue;

		$rows[$key] = vsprintf( $format, _table_get_line_data( $columns, $values ) );
	}

	return $rows;
}

// Helper function to get the array of data for a table row in the correct order
function _table_get_line_data( $columns, $item ) {
	foreach ( $columns as $column ) {
		$data[$column] = ( isset( $item[$column] ) ) ? $item[$column] : '';
	}

	return $data;
}</pre>
<p>Hope you find it useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/10/11/code-snippet-generate-a-plaintext-data-table/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Helper Class To Add Custom Taxonomy To Post&#160;Permalinks</title>
		<link>http://www.viper007bond.com/2011/10/07/code-snippet-helper-class-to-add-custom-taxonomy-to-post-permalinks/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-snippet-helper-class-to-add-custom-taxonomy-to-post-permalinks</link>
		<comments>http://www.viper007bond.com/2011/10/07/code-snippet-helper-class-to-add-custom-taxonomy-to-post-permalinks/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 02:24:52 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[permalinks]]></category>
		<category><![CDATA[register_taxonomy]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3423</guid>
		<description><![CDATA[Say you have a custom taxonomy called &#8220;sport&#8221; and you wanted to inject &#8220;football&#8221; into the permalink of posts that have the &#8220;football&#8221; term assigned to it. How would you go about doing that? Well below is a helper class that will make it easy to accomplish exactly that. As a reminder, here&#8217;s how you [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have a custom taxonomy called &#8220;sport&#8221; and you wanted to inject &#8220;football&#8221; into the permalink of posts that have the &#8220;football&#8221; term assigned to it. How would you go about doing that? Well below is a helper class that will make it easy to accomplish exactly that.</p>
<p></p>
<p>As a reminder, here&#8217;s how you go about registering a custom taxonomy using the <a href="http://codex.wordpress.org/Function_Reference/register_taxonomy"><code>register_taxonomy()</code></a> function:</p>
<pre class="brush: php; title: ; notranslate">add_action( 'init', 'register_sport_taxonomy' );

function register_sport_taxonomy() {
	register_taxonomy( 'sport', 'post', array(
		'labels' =&gt; array(
			'name' =&gt; 'Sports',
		),
		'hierarchical' =&gt; true, // Makes for a better selection box on write screen
	) );
}</pre>
<p>And now, for my helper class:</p>
<p>(feel free to highlight and then copy/paste this code into your favorite text editor to make it easier to read)</p>
<pre class="brush: php; title: ; notranslate">/**
 * A helper class for registering and handling a custom rewrite tag for a custom taxonomy.
 *
 * @version 1.0.0
 */
class Add_Taxonomy_To_Post_Permalinks {

	/**
	 * Stores the taxonomy slug that this class will be handling. Don't edit this.
	 *
	 * @since 1.0.0
	 * @var string
	 */
	public $taxonomy;

	/**
	 * Stores the rewrite tag complete with percentage signs. Don't edit this.
	 *
	 * @since 1.0.0
	 * @var string
	 */
	public $rewrite_tag;

	/**
	 * Initializes the class by calling Add_Taxonomy_To_Post_Permalinks::register()
	 * as well as registering a filter that runs in get_permalink().
	 *
	 * @since 1.0.0
	 *
	 * @param string $taxonomy A taxonomy slug. Use the same one that you used with register_taxonomy().
	 * @return array $optional_args Optional configuration parameters. See Add_Taxonomy_To_Post_Permalinks::register().
	 */
	function __construct( $taxonomy, $optional_args = array() ) {
		if ( ! $this-&gt;register( $taxonomy, $optional_args ) )
			return;

		add_filter( 'post_link', array( &amp;$this, 'filter_post_link' ), 10, 2 );
	}

	/**
	 * Registers the rewrite tag using add_rewrite_tag().
	 *
	 * Can accept an array of optional parameters:
	 *
	 * * tagname: The rewrite tag to use (no percentage signs). Defaults to the taxonomy slug.
	 * * regex: What regex to use to validate the value of the tag. Defaults to anything but a forward slash.
	 *
	 * @since 1.0.0
	 *
	 * @param string $taxonomy A taxonomy slug. Use the same one that you used with register_taxonomy().
	 * @return array $optional_args Optional configuration parameters. See function description.
	 */
	public function register( $taxonomy, $optional_args = array() ) {
		if ( ! taxonomy_exists( $taxonomy ) )
			return false;

		$this-&gt;taxonomy = $taxonomy;

		$this-&gt;rewrite_tag = ( ! empty( $optional_args['tagname'] ) ) ? $optional_args['tagname'] : $this-&gt;taxonomy;
		$this-&gt;rewrite_tag = '%' . $this-&gt;rewrite_tag . '%';

		$rewrite_tag_regex = ( ! empty( $optional_args['regex'] ) ) ? $optional_args['regex'] : '([^/]+)';

		// See http://codex.wordpress.org/Rewrite_API/add_rewrite_tag
		add_rewrite_tag( $this-&gt;rewrite_tag, $rewrite_tag_regex );

		return true;
	}

	/**
	 * Filters a post permalink to replace the tag placeholder with the first
	 * used term from the taxonomy in question.
	 *
	 * @since 1.0.0
	 *
	 * @param string $permalink The existing permalink URL.
	 * @return object $post The post object that this permalink belongs to.
	 */
	public function filter_post_link( $permalink, $post ) {
		// Abort early if the placeholder rewrite tag isn't in the generated URL
		if ( false === strpos( $permalink, $this-&gt;rewrite_tag ) )
			return $permalink;

		// Get the custom taxonomy terms in use by this post
		$terms = get_the_terms( $post-&gt;ID, $this-&gt;taxonomy );

		// If no terms are assigned to this post, use the taxonomy slug instead (can't leave the placeholder there)
		if ( empty( $terms ) ) {
			$permalink = str_replace( $this-&gt;rewrite_tag, $this-&gt;taxonomy, $permalink );
		}

		// Replace the placeholder rewrite tag with the first term's slug
		else {
			$first_term = array_shift( $terms );
			$permalink = str_replace( $this-&gt;rewrite_tag, $first_term-&gt;slug, $permalink );
		}

		return $permalink;
	}
}</pre>
<p>To use the class, simply initiate a new instance of it and pass the taxonomy slug to it while doing so:</p>
<pre class="brush: php; highlight: [11,12]; title: ; notranslate">add_action( 'init', 'register_sport_taxonomy' );

function register_sport_taxonomy() {
	register_taxonomy( 'sport', 'post', array(
		'labels' =&gt; array(
			'name' =&gt; 'Sports',
		),
		'hierarchical' =&gt; true, // Makes for a better selection box on write screen
	) );

	$sport_taxonomy_permalinks
		= new Add_Taxonomy_To_Post_Permalinks( 'sport' );
}</pre>
<p>Then go to Settings &rarr; Permalinks and add <code>%taxonomy%</code> to your structure, such as <code>/%sport%/%year%/%monthnum%/%day%/%postname%/</code>. It will then be replaced by the first term (sorted by term ID) of your custom taxonomy.</p>
<p>More complicated solutions are of course possible, such as picking which of multiple terms you want injected into the URL or multiple terms in the URL, but my class should give you a good starting point to work off of. <img src='http://www.viper007bond.com/wordpress/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/10/07/code-snippet-helper-class-to-add-custom-taxonomy-to-post-permalinks/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Add A Link To Latest Post To WordPress Nav&#160;Menu</title>
		<link>http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu</link>
		<comments>http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 01:52:19 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[nav menu]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3389</guid>
		<description><![CDATA[Someone on #wordpress IRC support channel was trying to add link to their latest blog post to their WordPress navigation menu, so I threw together a few lines of code to help them accomplish this. Place the above code in a plugin or just in your theme&#8217;s functions.php file. Create a new &#8220;Custom Link&#8221; menu [...]]]></description>
			<content:encoded><![CDATA[<p>Someone on <a href="http://codex.wordpress.org/IRC">#wordpress IRC support channel</a> was trying to add link to their latest blog post to their <a href="http://codex.wordpress.org/Appearance_Menus_SubPanel">WordPress navigation menu</a>, so I threw together a few lines of code to help them accomplish this.</p>
<pre class="brush: php; title: ; notranslate">// Front end only, don't hack on the settings page
if ( ! is_admin() ) {
	// Hook in early to modify the menu
	// This is before the CSS &quot;selected&quot; classes are calculated
	add_filter( 'wp_get_nav_menu_items', 'replace_placeholder_nav_menu_item_with_latest_post', 10, 3 );
}

// Replaces a custom URL placeholder with the URL to the latest post
function replace_placeholder_nav_menu_item_with_latest_post( $items, $menu, $args ) {

	// Loop through the menu items looking for placeholder(s)
	foreach ( $items as $item ) {

		// Is this the placeholder we're looking for?
		if ( '#latestpost' != $item-&gt;url )
			continue;

		// Get the latest post
		$latestpost = get_posts( array(
			'numberposts' =&gt; 1,
		) );

		if ( empty( $latestpost ) )
			continue;

		// Replace the placeholder with the real URL
		$item-&gt;url = get_permalink( $latestpost[0]-&gt;ID );
	}

	// Return the modified (or maybe unmodified) menu items array
	return $items;
}</pre>
<p>Place the above code in a plugin or just in your theme&#8217;s <code>functions.php</code> file.</p>
<p>Create a new &#8220;Custom Link&#8221; menu item where the URL is <code>#latestpost</code> (which will act as a placeholder and target for the code). You can title the item whatever you please. This code will then find that menu item (by looking for the placeholder URL) and then replace it&#8217;s URL with that of the latest post&#8217;s URL. Since the filter is before the code that adds the selected CSS classes runs, the menu highlighting will even work. When you visit the latest post on your blog, this menu item will light up.</p>
<p>Rather simple and elegant. You gotta love WordPress hooks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Translating WordPress Plugin&#160;Details</title>
		<link>http://www.viper007bond.com/2011/09/11/translating-wordpress-plugin-details/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=translating-wordpress-plugin-details</link>
		<comments>http://www.viper007bond.com/2011/09/11/translating-wordpress-plugin-details/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 00:09:04 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[translating]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3352</guid>
		<description><![CDATA[Plugin authors: did you know that you can allow translators to localize the plugin details that show up in the plugins list in the WordPress administration area? Your plugin&#8217;s name, description, and so forth? Well you can! It&#8217;s actually really simple to do and all you need to do is add one or two additional [...]]]></description>
			<content:encoded><![CDATA[<p>Plugin authors: did you know that you can allow translators to localize the plugin details that show up in the plugins list in the WordPress administration area? Your plugin&#8217;s name, description, and so forth? Well you can! It&#8217;s actually really simple to do and all you need to do is add one or two additional plugin headers to your file.</p>
<p>The first is <code>Text Domain</code> and this is the text domain for your plugin, i.e. the first argument that you are passing to <a href="http://codex.wordpress.org/Function_Reference/load_plugin_textdomain"><code>load_plugin_textdomain()</code></a>.</p>
<p>The second one is <code>Domain Path</code> and is optional. It&#8217;s only needed if you store your translation files in a subfolder inside of your plugin&#8217;s folder.</p>
<p>Here&#8217;s an example <code>load_plugin_textdomain()</code> call from one of <a href="http://www.viper007bond.com/wordpress-plugins/add-descendants-as-submenu-items/">my newest plugins</a>:</p>
<pre class="brush: php; light: true; title: ; notranslate">load_plugin_textdomain(
	'add-descendants-as-submenu-items',
	false,
	dirname( plugin_basename( __FILE__ ) ) . '/localization/'
);</pre>
<p>That loads translation files from a subfolder called &#8220;localization&#8221; inside of my plugin&#8217;s folder. This turns into the following plugin header:</p>
<pre class="brush: plain; highlight: [8,9]; title: ; notranslate">Plugin Name:   Add Descendants As Submenu Items
Plugin URI:    http://www.viper007bond.com/wordpress-plugins/add-descendants-as-submenu-items/
Description:   Automatically all of a nav menu item's descendants as submenu items. Designed for pages but will work with any hierarchical post type or taxonomy.
Version:       1.1.0
Author:        Alex Mills (Viper007Bond)
Author URI:    http://www.viper007bond.com/

Text Domain:   add-descendants-as-submenu-items
Domain Path:   /localization/</pre>
<p>An extra line break isn&#8217;t needed nor is the extra spacing but I added both just for aesthetic reasons.</p>
<p>And that&#8217;s it! WordPress will then attempt to translate the plugin&#8217;s name, URI, description, author, author URI, and version fields. I personally only include the plugin&#8217;s name and description in my translation template files though as I don&#8217;t feel translators need to localize the other fields.</p>
<p>If you need help generating a translation template file for your plugin, log into WordPress.org and then visit the &#8220;Admin&#8221; tab on your plugin&#8217;s page on WordPress.org. You can generate a POT file for your plugin there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/09/11/translating-wordpress-plugin-details/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Editing Your Hosts File In&#160;Windows</title>
		<link>http://www.viper007bond.com/2011/08/13/editing-your-hosts-file-in-windows/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=editing-your-hosts-file-in-windows</link>
		<comments>http://www.viper007bond.com/2011/08/13/editing-your-hosts-file-in-windows/#comments</comments>
		<pubDate>Sat, 13 Aug 2011 17:02:43 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hosts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3231</guid>
		<description><![CDATA[Andrew Nacin mentioned here at WordCamp San Francisco where your hosts file is on Mac (and Linux), but I thought I&#8217;d point out where your hosts file is on Windows and how to change it so that you can point domain names to your local computer. The easiest solution is to create a shortcut that [...]]]></description>
			<content:encoded><![CDATA[<p>Andrew Nacin mentioned here at <a href="http://2011.sf.wordcamp.org/">WordCamp San Francisco</a> where your <a href="http://en.wikipedia.org/wiki/Hosts_%28file%29"><code>hosts</code> file</a> is on Mac (and Linux), but I thought I&#8217;d point out where your <code>hosts</code> file is on Windows and how to change it so that you can point domain names to your local computer.</p>
<p>The easiest solution is to create a shortcut that will open Notepad and then tell it to open your <code>hosts</code> file. Right-click your desktop and select New &rarr; Shortcut. Paste the following into the field that pops up:</p>
<pre class="brush: plain; light: true; title: ; notranslate">%windir%\system32\notepad.exe %windir%\System32\drivers\etc\hosts</pre>
<p>Once you&#8217;re done creating the shortcut, right-click it and select &#8220;Properties&#8221;. Under the &#8220;Shortcut&#8221; tab is an &#8220;Advanced&#8221; button. Clicking it will show a checkbox for &#8220;Run as administrator&#8221;.</p>
<p><del datetime="2011-08-13T18:15:43+00:00">Start by opening Notepad in Administrator mode. Type &#8220;Notepad&#8221; into your Start Menu search box and then <strong>right-click it</strong> and select &#8220;Run as administrator&#8221;.</del> This is important because otherwise you won&#8217;t be able to save your changes as the file is a protected one.</p>
<p><del datetime="2011-08-13T18:15:43+00:00">Now that you have Notepad open, do File -> Open and browse to <code>C:\Windows\System32\drivers\etc</code>. You won&#8217;t see any files because by default Notepad will only show <code>*.txt</code> files. To change this, click on the dropdown that is currently showing &#8220;Text Documents (*.txt)&#8221; and change it to &#8220;All Files (*.*)&#8221;. Now you&#8217;ll be able to see your <code>hosts</code> file.</del></p>
<p>Opening it will show a little documentation and some examples. If you want to add your own, just add it to the bottom in this format:</p>
<pre class="brush: plain; light: true; title: ; notranslate">	127.0.0.1	yourdomain.com</pre>
<p>Saving the file and then visiting the domain in your browser will now show you files served by your local development environment. Note: a hard refresh may be required to due to your browser&#8217;s DNS cache. This can be accomplished by pressing control and F5.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/08/13/editing-your-hosts-file-in-windows/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Accessing Other Databases/Servers From Within&#160;WordPress</title>
		<link>http://www.viper007bond.com/2011/08/12/accessing-other-databasesservers-from-within-wordpress/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=accessing-other-databasesservers-from-within-wordpress</link>
		<comments>http://www.viper007bond.com/2011/08/12/accessing-other-databasesservers-from-within-wordpress/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 23:59:15 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[DD32]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[wpdb]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3227</guid>
		<description><![CDATA[Say you have a WordPress install where you need to pull in data from a separate database or server. The normal $wpdb instance of the wpdb class is limited to the database that your WordPress tables are located in. Yes, you could use mysql_connect() and the other standard PHP database functions, but then you don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have a WordPress install where you need to pull in data from a separate database or server. The normal <code>$wpdb</code> instance of the <a href="http://codex.wordpress.org/Function_Reference/wpdb_Class"><code>wpdb</code> class</a> is limited to the database that your WordPress tables are located in. Yes, you could use <a href="http://php.net/mysql_connect"><code>mysql_connect()</code></a> and the other standard PHP database functions, but then you don&#8217;t get all of the WordPress magic. So what to do?</p>
<p>The answer is surprisingly simple: make a new instance of the <code>wpdb</code> class! <a href="http://dd32.id.au/">Dion Hulse (DD32)</a> was kind enough to point out this great solution to me a few weeks back and I thought it was worth sharing with you all.</p>
<pre class="brush: php; title: ; notranslate">$myotherdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );

$myotherdb-&gt;get_results( &quot;SELECT id, name FROM mytable&quot; );</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/08/12/accessing-other-databasesservers-from-within-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Changing Core WordPress&#160;Strings</title>
		<link>http://www.viper007bond.com/2011/07/13/changing-core-wordpress-strings/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=changing-core-wordpress-strings</link>
		<comments>http://www.viper007bond.com/2011/07/13/changing-core-wordpress-strings/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 23:59:54 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress Code & Hacks]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[Peter Westwood]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[westi]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3173</guid>
		<description><![CDATA[One of the lesser known filters in WordPress is gettext. All strings that are run through the WordPress translation functions are also run through this filter after being translated thanks to a ticket I opened way back in 2008. That means you can actually use it to change pretty much any string in WordPress, namely [...]]]></description>
			<content:encoded><![CDATA[<p>One of the lesser known <a href="http://codex.wordpress.org/Plugin_API">filters</a> in WordPress is <code>gettext</code>. All strings that are run through the <a href="http://codex.wordpress.org/I18n_for_WordPress_Developers">WordPress translation functions</a> are also run through this filter after being translated thanks to <a href="https://core.trac.wordpress.org/ticket/6742">a ticket</a> I opened way back in 2008. That means you can actually use it to change pretty much any string in WordPress, namely in the admin area.</p>
<p>I&#8217;ve used this in some plugins I&#8217;ve written in the past and it works incredibly well.</p>
<p>My co-worker and one of the lead developers of WordPress <a href="http://blog.ftwr.co.uk/">Peter Westwood (westi)</a> wrote a <a href="http://blog.ftwr.co.uk/archives/2010/01/02/mangling-strings-for-fun-and-profit/">really good blog post</a> about this, however I wasn&#8217;t completely happy with his code so I&#8217;m writing this blog post to share how I would write some code to take advantage of this versatile filter. Don&#8217;t get me wrong &#8212; he wrote good and valid code, but it&#8217;s not exactly the easiest thing for a novice to extend for their own uses.</p>
<pre class="brush: php; title: ; notranslate">function youruniqueprefix_filter_gettext( $translated, $original, $domain ) {

	// This is an array of original strings
	// and what they should be replaced with
	$strings = array(
		'View all posts filed under %s' =&gt; 'See all articles filed under %s',
		'Howdy, %1$s' =&gt; 'Greetings, %1$s!',
		// Add some more strings here
	);

	// See if the current string is in the $strings array
	// If so, replace it's translation
	if ( isset( $strings[$original] ) ) {
		// This accomplishes the same thing as __()
		// but without running it through the filter again
		$translations = &amp;get_translations_for_domain( $domain );
		$translated = $translations-&gt;translate( $strings[$original] );
	}

	return $translated;
}

add_filter( 'gettext', 'youruniqueprefix_filter_gettext', 10, 3 );</pre>
<p>So as you can see at it&#8217;s core it accomplishes the same thing as Peter&#8217;s code however my code should be a bit more clear on how to make it translate multiple strings.</p>
<p>Hope someone finds this helpful! <img src='http://www.viper007bond.com/wordpress/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/07/13/changing-core-wordpress-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily Create XML In PHP Using A Data&#160;Array</title>
		<link>http://www.viper007bond.com/2011/06/29/easily-create-xml-in-php-using-a-data-array/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=easily-create-xml-in-php-using-a-data-array</link>
		<comments>http://www.viper007bond.com/2011/06/29/easily-create-xml-in-php-using-a-data-array/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 04:26:46 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[DOMDocument]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3155</guid>
		<description><![CDATA[I&#8217;ve been working with the Google Contacts API lately and needed to construct some XML as a part of that. PHP&#8217;s DOMDocument works really great for this, but it can get complicated fast as you need to create lots of variables for all of your elements, children, etc. It can make it quite hard to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with the <a href="http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html">Google Contacts API</a> lately and needed to construct some XML as a part of that. PHP&#8217;s <a href="http://www.php.net/manual/en/class.domdocument.php"><code>DOMDocument</code></a> works really great for this, but it can get complicated fast as you need to create lots of variables for all of your elements, children, etc. It can make it quite hard to do dynamically.</p>
<p>An easier method would be to just convert an array into XML, the opposite of <a href="http://www.php.net/manual/en/function.simplexml-load-string.php"><code>simplexml_load_string()</code></a> if you will. So I wrote some code that does exactly that and I thought I&#8217;d share it incase anyone else would find it helpful. <img src='http://www.viper007bond.com/wordpress/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
<p>Start by creating your array of data. I used a numeric array instead of an associative array because you can have duplicate elements in XML while you cannot have duplicate array keys.</p>
<pre class="brush: php; title: ; notranslate">$data = array(
	'name' =&gt; 'toplevelelement', // &quot;name&quot; required, all else optional
	'attributes' =&gt; array(
		'foo' =&gt; 'bar',
		'fruit' =&gt; 'apple',
	),
	'value' =&gt; 'Some random value.',
	array(
		'name' =&gt; 'achildelement',
		'value'=&gt; 'Value',
	),
	array(
		'name' =&gt; 'anotherchildelement',
		'attributes' =&gt; array(
			'some' =&gt; 'attr',
		),
		array(
			'name' =&gt; 'grandchildelement',
		),
	),
);</pre>
<p>An array such as that is easy to dynamically create based on your source data, it&#8217;s easy to read, and can be fairly easily manipulated.</p>
<p><code>name</code> is the only required item of each array and it&#8217;s the tag name of the element. <code>attributes</code> is an array of attributes for the element and <code>value</code> is the value. Both of these are optional. Any children arrays are children elements and their structures should be the same.</p>
<p>Now here&#8217;s the code I wrote that converts the above array into some XML:</p>
<pre class="brush: php; title: ; notranslate">function generate_xml_element( $dom, $data ) {
	if ( empty( $data['name'] ) )
		return false;

	// Create the element
	$element_value = ( ! empty( $data['value'] ) ) ? $data['value'] : null;
	$element = $dom-&gt;createElement( $data['name'], $element_value );

	// Add any attributes
	if ( ! empty( $data['attributes'] ) &amp;&amp; is_array( $data['attributes'] ) ) {
		foreach ( $data['attributes'] as $attribute_key =&gt; $attribute_value ) {
			$element-&gt;setAttribute( $attribute_key, $attribute_value );
		}
	}

	// Any other items in the data array should be child elements
	foreach ( $data as $data_key =&gt; $child_data ) {
		if ( ! is_numeric( $data_key ) )
			continue;

		$child = generate_xml_element( $dom, $child_data );
		if ( $child )
			$element-&gt;appendChild( $child );
	}

	return $element;
}

$doc = new DOMDocument();
$child = generate_xml_element( $doc, $data );
if ( $child )
	$doc-&gt;appendChild( $child );
$doc-&gt;formatOutput = true; // Add whitespace to make easier to read XML
$xml = $doc-&gt;saveXML();</pre>
<p>You first create a blank canvas by creating a new instance of the <code>DOMDocument</code> class and then you pass the class instance (needed for creating elements in the correct character set and such) and the data array to the <code>generate_xml_element()</code> function. This function will create the top level element and then recursively call itself on any child elements until it&#8217;s gone through the whole array.</p>
<p>Once it&#8217;s done, you&#8217;ll need to append the element to the DOM using the inherited <a href="http://www.php.net/manual/en/domnode.appendchild.php"><code>appendChild()</code> function</a>. Then calling <a href="http://www.php.net/manual/en/domdocument.savexml.php"><code>saveXML</code></a> will give you the XML output. The above example data array will give you something like this (maybe or maybe not nicely formatted with whitespace depending on what mood <code>DOMDocument</code> is in):</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;toplevelelement foo=&quot;bar&quot; fruit=&quot;apple&quot;&gt;
	Some random value.
	&lt;achildelement&gt;Value&lt;/achildelement&gt;
	&lt;anotherchildelement some=&quot;attr&quot;&gt;
		&lt;grandchildelement&gt;&lt;/grandchildelement&gt;
	&lt;/anotherchildelement&gt;
&lt;/toplevelelement&gt;</pre>
<p>And there you have it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/06/29/easily-create-xml-in-php-using-a-data-array/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The Proper Way To Review&#160;Code</title>
		<link>http://www.viper007bond.com/2011/04/20/the-proper-way-to-review-code/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-proper-way-to-review-code</link>
		<comments>http://www.viper007bond.com/2011/04/20/the-proper-way-to-review-code/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 21:30:43 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[code review]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[John James Jacoby]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=3094</guid>
		<description><![CDATA[Before committing code, I explain it to Donkey Kong first to make sure it makes sense #codereview /cc @iamjohnford http://t.co/0dtFTYY April 20th, 2011 1:12 PM via Twitter for MacReplyRetweetFavorite @JohnJamesJacoby John James Jacoby (Also known as rubber duck debugging)]]></description>
			<content:encoded><![CDATA[<p><!-- tweet id : 60813105013329920 --><br />
<style type='text/css'>#bbpBox_60813105013329920 a { text-decoration:none; color:#b38752; }#bbpBox_60813105013329920 a:hover { text-decoration:underline; }</style>
<div id='bbpBox_60813105013329920' class='bbpBox' style='padding:20px; margin:5px 0; background-color:#382a19; background-image:url(http://a0.twimg.com/profile_background_images/220152554/x18407f124a1589d4f178c6abad73a7e.jpg); background-repeat:no-repeat'>
<div style='background:#fff; padding:10px; margin:0; min-height:48px; color:#875b2b; -moz-border-radius:5px; -webkit-border-radius:5px;'><span style='width:100%; font-size:18px; line-height:22px;'>Before committing code, I explain it to Donkey Kong first to make sure it makes sense <a href="http://twitter.com/search?q=%23codereview" title="#codereview">#codereview</a> /cc @<a href="http://twitter.com/intent/user?screen_name=iamjohnford" class="twitter-action">iamjohnford</a> <a href="http://t.co/0dtFTYY" rel="nofollow">http://t.co/0dtFTYY</a></span>
<div class='bbp-actions' style='font-size:12px; width:100%; padding:5px 0; margin:0 0 10px 0; border-bottom:1px solid #e6e6e6;'><img align='middle' src='http://www.viper007bond.com/wordpress/wp-content/plugins/twitter-blackbird-pie//images/bird.png' /><a title='tweeted on April 20th, 2011 1:12 PM' href='http://twitter.com/#!/JohnJamesJacoby/status/60813105013329920' target='_blank'>April 20th, 2011 1:12 PM</a> via <a href="http://itunes.apple.com/us/app/twitter/id409789998?mt=12" rel="nofollow" target="blank">Twitter for Mac</a><a href='https://twitter.com/intent/tweet?in_reply_to=60813105013329920' class='bbp-action bbp-reply-action' title='Reply'><span><em style='margin-left: 1em;'></em><strong>Reply</strong></span></a><a href='https://twitter.com/intent/retweet?tweet_id=60813105013329920' class='bbp-action bbp-retweet-action' title='Retweet'><span><em style='margin-left: 1em;'></em><strong>Retweet</strong></span></a><a href='https://twitter.com/intent/favorite?tweet_id=60813105013329920' class='bbp-action bbp-favorite-action' title='Favorite'><span><em style='margin-left: 1em;'></em><strong>Favorite</strong></span></a></div>
<div style='float:left; padding:0; margin:0'><a href='http://twitter.com/intent/user?screen_name=JohnJamesJacoby'><img style='width:48px; height:48px; padding-right:7px; border:none; background:none; margin:0' src='http://a2.twimg.com/profile_images/1293889061/me2_normal.jpg' /></a></div>
<div style='float:left; padding:0; margin:0'><a style='font-weight:bold' href='http://twitter.com/intent/user?screen_name=JohnJamesJacoby'>@JohnJamesJacoby</a>
<div style='margin:0; padding-top:2px'>John James Jacoby</div>
</div>
<div style='clear:both'></div>
</div>
</div>
<p><!-- end of tweet --></p>
<p>(Also known as <a href="http://en.wikipedia.org/wiki/Rubber_duck_debugging">rubber duck debugging</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2011/04/20/the-proper-way-to-review-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Simple oEmbed-Based WordPress&#160;Shortcodes</title>
		<link>http://www.viper007bond.com/2010/06/23/creating-simple-oembed-based-wordpress-shortcodes/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-simple-oembed-based-wordpress-shortcodes</link>
		<comments>http://www.viper007bond.com/2010/06/23/creating-simple-oembed-based-wordpress-shortcodes/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 00:12:03 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[oEmbed]]></category>
		<category><![CDATA[shortcodes]]></category>
		<category><![CDATA[WP_Embed]]></category>
		<category><![CDATA[wp_oembed_add_provider()]]></category>
		<category><![CDATA[wp_oembed_get()]]></category>
		<category><![CDATA[YouTube]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=1815</guid>
		<description><![CDATA[Say you wanted to create a shortcode like this: [youtube id="991WcoEPwb8"] And instead of manually creating the HTML yourself, you wanted to use YouTube&#8217;s oEmbed provider to get the HTML. While that&#8217;s easy to do using WordPress&#8217; existing functions (wp_oembed_get() for example), you must implement your own caching of the result as WordPress&#8217; oEmbed class [...]]]></description>
			<content:encoded><![CDATA[<p>Say you wanted to create a shortcode like this: <code>[<strong></strong>youtube id="991WcoEPwb8"]</code></p>
<p>And instead of manually creating the HTML yourself, you wanted to use YouTube&#8217;s <a href="http://oembed.com/">oEmbed</a> provider to get the HTML. While that&#8217;s easy to do using WordPress&#8217; existing functions (<code>wp_oembed_get()</code> for example), you must implement your own caching of the result as WordPress&#8217; oEmbed class does not include any caching of it&#8217;s own.</p>
<p>However, WordPress comes with an <code>[<strong></strong>embed]</code> shortcode that&#8217;s also secretly used for the <a href="http://codex.wordpress.org/Embeds">shortcode-less embeds</a>. A cool trick is to make that shortcode&#8217;s existing code (complete with caching) work for you! This post explains how to do it.</p>
<p>First, the code:</p>
<pre class="brush: php; title: ; notranslate">add_shortcode( 'youtube', 'my_youtube_shortcode' );

function my_youtube_shortcode( $atts ) {

	// We need to use the WP_Embed class instance
	global $wp_embed;

	// The &quot;id&quot; parameter is required
	if ( empty($atts['id']) )
		return '';

	// Construct the YouTube URL
	$url = 'http://www.youtube.com/watch?v=' . $atts['id'];

	// Run the URL through the  handler.
	// This handler handles calling the oEmbed class
	// and more importantly will also do the caching!
	return $wp_embed-&gt;shortcode( $atts, $url );
}</pre>
<p>We start by gaining access to the WP_Embed instance that we&#8217;ll be making use of and then making sure we have the required video ID (you can do whatever you want here). We then create the full URL to the video that oEmbed will need. Lastly the real time saver &#8212; we pass the attributes (&#8220;id&#8221; will be ignored) and the constructed URL to the <code>[<strong></strong>embed]</code> shortcode handler which will fetch the result and cache it.</p>
<p>Simple, huh?</p>
<p>One thing to note though: if you&#8217;re using this along with a non-default oEmbed provider, you&#8217;ll also need to whitelist it using <a href="http://codex.wordpress.org/Function_Reference/wp_oembed_add_provider"><code>wp_oembed_add_provider()</code></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2010/06/23/creating-simple-oembed-based-wordpress-shortcodes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Twitter Followers Count Snippet for&#160;WordPress</title>
		<link>http://www.viper007bond.com/2010/05/15/twitter-followers-count-snippet-for-wordpress/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=twitter-followers-count-snippet-for-wordpress</link>
		<comments>http://www.viper007bond.com/2010/05/15/twitter-followers-count-snippet-for-wordpress/#comments</comments>
		<pubDate>Sat, 15 May 2010 09:31:30 +0000</pubDate>
		<dc:creator>Alex (Viper007Bond)</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[HTTP API]]></category>
		<category><![CDATA[transient]]></category>
		<category><![CDATA[transients]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.viper007bond.com/?p=1664</guid>
		<description><![CDATA[Konstantin Kovshenin posted some code on his blog for how to display how many Twitter followers someone has. While the idea was good, I think he went about the implementation in the non-best method. So, for fun and because I don&#8217;t post enough code snippets here on this blog, I thought I&#8217;d post how I [...]]]></description>
			<content:encoded><![CDATA[<p>Konstantin Kovshenin posted <a href="http://kovshenin.com/archives/twitter-followers-count-snippet-for-wordpress/">some code on his blog</a> for how to display how many Twitter followers someone has. While the idea was good, I think he went about the implementation in the non-best method. So, for fun and because I don&#8217;t post enough code snippets here on this blog, I thought I&#8217;d post how I would display how many followers someone has on Twitter. <img src='http://www.viper007bond.com/wordpress/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: php; title: ; notranslate">function viper_twitter_followers( $username = 'Viper007Bond' ) {

	// Just to keep the code below cleaner, create the cache key now
	$cache_key = &quot;viper_twitter_followers_{$username}&quot;;

	// First we look for a cached result
	if ( false !== $followers = get_transient( $cache_key ) )
		return $followers;

	// Okay, no cache, so let's fetch it
	$result = wp_remote_retrieve_body( wp_remote_get( 'http://api.twitter.com/1/users/show.json?screen_name=' . urlencode($username) ) );

	// Check to make sure we got some data to work with
	if ( empty($result) ) {
		// Cache the failure for 1 min to avoid hammering Twitter
		set_transient( $cache_key, 0, 60 );
	}

	// Parse the data
	$data = json_decode( $result );

	// Make sure we were able to parse it
	// If not, cache the failure (like above)
	if ( !isset( $data-&gt;followers_count ) )
		set_transient( $cache_key , 0, 60 );

	// Success! Cache the result for an hour.
	$followers = (int) $data-&gt;followers_count;
	set_transient( $cache_key, $followers, 3600 );

	return $followers;
}

echo 'I have ' . viper_twitter_followers( 'Viper007Bond' ) . ' followers on Twitter!';</pre>
<p><strong>Reading Material:</strong></p>
<ul>
<li>HTTP API: <a href="http://codex.wordpress.org/HTTP_API">http://codex.wordpress.org/HTTP_API</a></li>
<li>Transient API: <a href="http://codex.wordpress.org/Transients_API">http://codex.wordpress.org/Transients_API</a> (expiring options basically)</li>
</ul>
<p>If you have any questions about the above code, let me know and I&#8217;ll do my best to answer them. <img src='http://www.viper007bond.com/wordpress/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.viper007bond.com/2010/05/15/twitter-followers-count-snippet-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.364 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-01-17 10:11:41 -->
<!-- Compression = gzip -->
