<?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>Hugh Fletcher &#187; Wordpress</title>
	<atom:link href="http://hughfletcher.com/blog/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://hughfletcher.com</link>
	<description>What Can The Web Do For You?</description>
	<lastBuildDate>Sun, 07 Feb 2010 04:13:02 +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>Safe mailto links in Wordpress using CodeIgniter</title>
		<link>http://hughfletcher.com/blog/safe-mailto-links-in-wordpress-using-codeigniter/</link>
		<comments>http://hughfletcher.com/blog/safe-mailto-links-in-wordpress-using-codeigniter/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 20:19:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://hughfletcher.com/?p=48</guid>
		<description><![CDATA[Recently I did a half-way makeover of my site/blog that included removing the contact page that only one, count them, one person ever used.  Now granted it was a guy from Microsoft I had recently met and contacted me about a job opportunity, I never the less decided to get rid of the whole [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I did a half-way makeover of my site/blog that included removing the contact page that only one, count them, one person ever used.  Now granted it was a guy from Microsoft I had recently met and contacted me about a job opportunity, I never the less decided to get rid of the whole contact page thing and simply put an email link in my <a href="about">about page</a>.  Wanting to obfuscate it from evil email harvesters, Wordpress by default doesn&#8217;t offer a easy way of doing this within a post.  That&#8217;s where the Wordpress shortcode API and CodeIgniter come in.</p>
<p><span id="more-48"></span></p>
<p>Wordpress has a cool feature that allows you to create shortcodes to put in your posts like <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">[bartag foo="foo-value"]</span> and then process it using a PHP function.   Go <a title="Wordpress Shortcode API" href="http://codex.wordpress.org/Shortcode_API">to the codex page</a> and check it out, it&#8217;s pretty straight forward.  Next go grab you a copy of CodeIgniter, crack it open and go to system/helpers/url_helper.php.  Snatch the safe_mailto() function and paste it in your code.  I put mine in the functions page in the theme for quickness but you can put it in a plug in if your up for all that.  Now underneath the CI function ,  write you a function that takes the attributes and content from the shortcode and then call the safe_mailto() function.  You should end up with something like below. That&#8217;s it! Now you can have protected and obfuscated email links in your posts! </p>
<pre class="brush: php;">
//The CodeIgniter function
if ( ! function_exists('safe_mailto'))
{
	function safe_mailto($email, $title = '', $attributes = '')
	{
		// The actual function. You get the drift...
	}
}

// The function to process the shortcode
function maillink_func($atts, $content = null) {
	extract(shortcode_atts(array(
		'email' =&gt; get_bloginfo ( 'admin_email' ),
                'title' =&gt; null,
                'class' =&gt; null,
                'id'    =&gt; null,
                'style' =&gt; null
                //add more attributes if you want them, but add below too!
	), $atts));

        return safe_mailto($email, $content, array(
                'class' =&gt; $class,
                'id' =&gt; $id,
                'style' =&gt; $style
            ));
}

//Register the shortcode with Wordpress
add_shortcode('maillink', 'maillink_func');

// Usage
// [maillink email=&quot;someone@somewhere.com&quot;]
// [maillink email=&quot;someone@somewhere.com&quot; class=&quot;link&quot;]Email Me![/maillink]</pre>
]]></content:encoded>
			<wfw:commentRss>http://hughfletcher.com/blog/safe-mailto-links-in-wordpress-using-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
