Skip to content

Instantly share code, notes, and snippets.

@dfadler
Forked from ivuorinen/email_obfuscation.php
Created May 16, 2012 15:42
Show Gist options
  • Save dfadler/2711431 to your computer and use it in GitHub Desktop.
Save dfadler/2711431 to your computer and use it in GitHub Desktop.
Email Obfuscation Shortcode for WordPress
<?php
/*
Plugin Name: Email Obfuscation Shortcode
Plugin URI: https://gist.github.com/1424515
Description: Shortcode for including emails into content and keeping spambots clueless. [obf email="email@example.com" noscript="what's shown to bots/people without javascript"]
Version: 0.1
Author: Ismo Vuorinen
Author URI: http://github.com/ivuorinen
*/
/**
* emailobfusction_func
*
* @param string $atts attributes
* @return string obfuscated email with javascript clarifying
*/
function emailobfusction_func( $atts )
{
extract( shortcode_atts( array(
'email' => get_settings('admin_email'), // Defaulting to admin email
'noscript' => 'myname at thisdomain.com',
), $atts ) );
// JavaScript by Allan Odgaard
// http://pastie.textmate.org/101495 (line 116)
$javascript = '.replace(/[a-zA-Z]/g, function(c){ return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26 );})';
return '<script type="text/javascript">'
. 'document.write("'
. str_rot13( "<a class='rot13' href='mailto:" . $email . "'>" . $email . '</a>' )
. '"' . $javascript . ');</script>'
. '<noscript>' . $noscript . '</noscript>';
}
add_shortcode( 'obf', 'emailobfusction_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment