Skip to content

Instantly share code, notes, and snippets.

@pcaWeb
Forked from aldolat/wp-antispambot.php
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcaWeb/c86dc77099bc47b74474 to your computer and use it in GitHub Desktop.
Save pcaWeb/c86dc77099bc47b74474 to your computer and use it in GitHub Desktop.
WordPress: Obfuscates email addresses from spam bot.
/**
* Hides email addresses from spam bot.
*
* @param array $atts The various options. The only required option is "address".
* @example [email address="name@example.com"]
*/
function ubnsc_email( $atts ) {
extract( shortcode_atts( array(
'type' => 'email',
'address' => '',
'class' => '',
'subject' => '',
'text' => '',
), $atts ) );
switch ( $type ) {
case 'email' : $protocol = 'mailto:'; break;
case 'jabber' : $protocol = 'xmpp:'; break;
}
if ( $class ) $css = 'class="' . esc_attr( $class ) . '" ';
if ( $subject ) $subject = '?subject=' . esc_attr( $subject );
if ( $text == '' ) $text = antispambot( $address );
$output = '<a ' . $css . 'href="' . $protocol . antispambot( $address, 1 ) . $subject . '">' . $text . '</a>';
return $output;
}
add_shortcode('email', 'ubnsc_email');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment