Created
December 2, 2011 19:30
-
-
Save ivuorinen/1424515 to your computer and use it in GitHub Desktop.
Email Obfuscation Shortcode for WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 protected]" 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