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 or other sensitive content:

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

Keep in mind that WordPress shortcodes are limited to certain areas such as posts, pages, widgets, etc.

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 ( method_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 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>

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

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_.+-][email protected][a-z0-9-]+\.[a-z0-9-.]+$/i';
} );