Encoding all email addresses

This guide will help you encode all email addresses that aren’t caught by the free, open source version of this plugin.

Using the shortcode

You can use the [encode] shortcode to encode phone numbers, email addresses or other sensitive content:

[encode]+1 (555) 123-4567[/encode]

Keep in mind that WordPress only parses shortcodes in certain areas such as posts, pages, widgets, etc. The Premium version works around this limitation with it’s full-page scanner.

By default the [encode] shortcode will always use the encoding technique you set in the plugin’s settings. You may however specify the technique attribute for each individual shortcode:

[encode technique="js"][email protected][/encode]
[encode technique="css"]+1 (555) 123-4567[/encode]
[encode technique="html"]decimal and hexadecimal entities[/encode]

To create an encoded link, you may use the link shortcode attribute:

[encode link="tel:+15551234567"]Call (555) 123-4567[/encode]
[encode link="mailto:[email protected]"]Email: [email protected][/encode]

You can of course combine the shortcode attributes:

[encode technique="js" link="https://apple.com/titan"]Project Titan[/encode]

How email addresses are found

The free version of this plugin only searches for plain text email addresses in content that’s passed through these primary WordPress filters:

the_content
the_excerpt
widget_text
comment_text
comment_excerpt

The Premium version scans the entire page, not just WordPress filters.

Filtering more content

You can filter additional parts of your site by applying the eae_encode_emails callback to any filter:

<?php

add_filter( '%filter-name%', 'eae_encode_emails' );

For example, to filter all Advanced Custom Fields values, you could use the acf/load_value filter:

<?php

if ( function_exists( 'eae_encode_emails' ) )  {
    add_filter( 'acf/load_value', 'eae_encode_emails' );
}

The Premium version comes with built-in support for various 3rd party plugins and themes such as Advanced Custom Fields, WooCommerce, Jetpack and many others.

Encoding non-filtered content

Sometimes you may want to obfuscate email addresses in your footer, or other parts of your theme that aren’t filtered. You can do so by using the eae_encode_emails() helper and changing theme code like this:

<div class="theme-footer">
    <?php echo my_theme_get( 'copyright-text' ); ?>
</div>

To something like this:

<div class="theme-footer">
    <?php echo eae_encode_emails( my_theme_get( 'copyright-text' ) ); ?>
</div>

Encoding other content

In some cases you might want to obfuscate something specific, you can do that using the eae_encode_str() helper.

<p class="sidebar-widget">
   Hello my name is Steve! You can reach me at:
   <?php echo eae_encode_str( '[email protected]' ); ?>
</p>

Excluding email addresses

In some cases you might want to ignore a specific email address, you can do so with the eae_email_callback filter. This filter is quite versatile and can be used for many other things, for example you could use it to disable email addresses obfuscation on certain pages.

<?php

add_filter( 'eae_email_callback', function ( $callback ) {
    return function ( $email ) use ( $callback, $ignored_emails ) {
        if ( $email[ 0 ] === '[email protected]' ) ) {
            return $email[ 0 ]; // return plain email address
        }

        return $callback( $email ); // return obfuscated email address
    };
} );

Changing the filter priority

The default filter priority is 1000 and you can adjust it by defining the EAE_FILTER_PRIORITY constant. The constant has to be defined before this plugin is loaded, e.g. in your wp-config.php or in Must-use plugin.

<?php

define( 'EAE_FILTER_PRIORITY', 100 );

Changing the regular expression pattern

You can override the pattern that's used to find email addresses using the eae_regexp filter:

<?php

add_filter( 'eae_regexp', function () {
    return '/^[a-z0-9_.+-]+@[a-z0-9-]+\.[a-z0-9-.]+$/i';
} );