Защита Email (PHP)

Шорткод:

[email address="name@example.com"]

functions.php:

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');

Автоматически:

function security_remove_emails($content) {
    $pattern = '/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})/i';
    $fix = preg_replace_callback($pattern,"security_remove_emails_logic", $content);

    return $fix;
}
function security_remove_emails_logic($result) {
    return antispambot($result[1]);
}
add_filter( 'the_content', 'security_remove_emails', 20 );
add_filter( 'widget_text', 'security_remove_emails', 20 );