Obfuscate E-mail

Author:Scott Reilly
Version:3.6
First released:2005-04-14
Last update:2019-04-24
Compatibility:WP 4.7 – 5.1.2
Download:[ zip ]
Description:

Obfuscate email addresses to deter email-harvesting spammers.

Extended Description

Obfuscate email addresses to deter email-harvesting spammers, with a focus on retaining the appearance and functionality of email hyperlinks.

“Obfuscation” simply means that techniques are employed to modify email address strings that appear on your site in such a way that bots scraping your site are unable to identify those addresses; however, at the same time those emails addresses should still look and work correctly for visitors, as much as possible.

The plugin allows for use of one or more (or all!) of three techniques for email protection that have proven themselves in the past. While techniques abound for email obfuscation, the three techniques included provide the best balance of email address protection with minimal impact on visitors. You can decide on a technique by technique basis which ones you’d like to employ as some have potential drawbacks. The plugin’s settings page allows you select which techniques to use.

Ultimately, your best bet would be to not publicly expose an email address and to offer a contact form as an alternative means of contact. Or you can just accept that email addresses will get scraped and spammed, and rely on an email service that is good at filtering out spam. But this plugin is here for you if you want to employ the most reasonable means of making email harvesting difficult for your site.

See Filters section for c2c_obfuscate_email_filters for complete list of filters that are processed.

Please read the Details section of this documentation to learn more about the techniques employed.

Details

The email obfuscation techniques included in this plugin were chosen for their effectiveness and general applicability with minimal impact on users. I urge you to read about an experiment performed by Silvan Mühlemann in which he protected email addresses using nine different techniques. He ensured the page containing those email addresses got indexed by Google and then waited 1.5 years. During that time he measured the amount of spam received to each of the email addresses. (Note: this experiment came out a few years after this plugin was originally created, but at this point was conducted over 10 years ago. Its conclusions may not apply as strongly today.)

Three techniques stood out as having received zero spam emails during that time. Two of those three techniques are included in this plugin. The fourth of his techniques is also included even though it did get a very small amount of spam — the technique was still very effective and more importantly does not rely on users to have CSS or JavaScript enabled.

The techniques are as follows. Two are enabled by default. Weigh the requirements against what you’re comfortable requiring of visitors in order for them to see and make use of email addresses you post on your site.

(For all the examples below, assume you have the link <a href="mailto:moc.elpmaxenull@nosrep">moc.elpmaxenull@nosrep</a> in your post.)

Using CSS display:none

  • How does it work? Garbage text, wrapped in span tags, is inserted into any displayed email addresses. Using CSS, the text gets hidden so that visitors see the email addresses as intended. Email scrapers don’t typically utilize a CSS engine to help determine how text would look onscreen.

  • Uses CSS? Yes, which means if a visitor does not have CSS enabled, the emails will appear with extra text in them.

  • Uses JavasScript? No.

  • Can visitor copy-n-paste the link from onscreen text without needing to make modifications? Yes (unless they have CSS disabled).

  • Does this protect email addresses appearing in mailto: links and within HTML tag attributes? No.

  • How effective is this? In the aforementioned experiment, no spam emails were received when using just this technique.

  • Example

    <a href="mailto:moc.elpmaxenull@nosrep">[email protected]<span class="displaynone">null</span>example.com</a>
    

Replacing the `@` and `.` characters

  • How does it work? The @ and . characters are replaced with alternative strings, such as AT and DOT, respectively. The exact replacements are configurable on the plugin’s settings page. By default, if you don’t specify custom replacements, the plugin will use entity substitution (@ becomes @ and . becomes .).

  • Uses CSS? No.

  • Uses JavasScript? No.

  • Can visitor copy-n-paste the link from onscreen text without needing to make modifications? No, though it should (hopefully) be clear to the user what they need to replace.

  • Does this protect emails appearing in mailto: links and within HTML tag attributes? Yes, though if you specify custom replacement strings visitors clicking on a mailto link will have to modify the email address that shows up in their mail program.

  • How effective is this? In the aforementioned experiment, almost no spam emails were received when using just this technique. As a bonus, this technique does not require the support of any particular client-side techniques (CSS or JavaScript).

  • Examples

    • Custom AT and DOT replacements
      • <a href="mailto:personATexampleDOTcom">personATexampleDOTcom</a>
      • <a href="mailto:moc.elpmaxeSIHTETELEDnull@nosrep">moc.elpmaxeSIHTETELEDnull@nosrep</a>
    • Everything encoded (aka hexadecimal HTML entity substitution)
      person@example.com

Changing text direction with CSS (not enabled by default)

  • How does it work? The email addresses are sent reversed in the markup. Using CSS, the text gets reversed so that visitors see the email addresses as intended. Email scrapers don’t recognize the emails in their reversed form and don’t typically utilize a CSS engine to help determine how text would look onscreen.

  • Uses CSS? Yes, which means if a visitor does not have CSS enabled, the emails will appear backwards to them.

  • Uses JavasScript? No.

  • Can visitor copy-n-paste the link from onscreen text without needing to make modifications? No, text copied in such a manner will be reversed. However, a right-click -> “copy link/email address” will work properly for linked email addresses.

  • Does this protect emails appearing in mailto: links and within HTML tag attributes? No.

  • How effective is this? In the aforementioned experiment, no spam emails were received when using just this technique.

  • Example:

    <a href="mailto:moc.elpmaxenull@nosrep"><span class="codedirection">[email protected]</span></a>
    

How it looks

If all techniques are enabled at once, the resulting obfuscation of the example link above is (for the full effect, view this in the page’s source or the readme.txt file directly):

<a href="mailto:person@example.com"><span class="codedirection">moc.elpmaxe<span class="displaynone">null</span>@nosrep</span></a>

However, in your browser it would appear to you as it does prior to obfuscation, and the link for the email would still work. Theoretically, however, spammers would have a somewhat more difficult time harvesting the emails you display or link to in your posts.

NOTE: (Only when using the custom replacement feature will visitors need to modify the email address for use in their email program.)

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Template Tags

The plugin provides one optional template tag for use in your theme templates.

Functions

  • function c2c_obfuscate_email( $text, $args = array() )

Arguments

  • $text
    Required argument. The text and/or HTML that contains email addresses that you want to be obfuscated.

  • $args
    Optional argument. An array of configuration options, each element of which will override the plugin’s corresponding default setting.

    • encode_everything (boolean) : Encode all characters in the email address using hexadecimal HTML entity substitution?
    • use_text_direction (boolean) : Utilize CSS text direction technique?
    • use_display_none (boolean) : Utilize CSS display:none technique?
    • at_replace (string) : String to use in place of @ in email addresses (used only if encode_everything is false)
    • dot_replace (string) : String to use in place of . in email addresses (used only if encode_everything is false)

Examples

  • Basic usage. Obfuscate email addresses in $text according to current plugin settings.

  • Override all plugin default settings when obfuscating email addresses in $text and just use text direction technique.

    true, ‘use_display_none’ => false, ‘encode_everything’ => false, ‘at_replace’ => ”, ‘dot_replace’ => ”)
    ) ); ?>

    Hooks

    The plugin exposes one filter for hooking. Typically, code making use of filters should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain).

c2c_obfuscate_email_filters (filter)

The ‘c2c_obfuscate_email_filters’ filter allows you to customize what filters get processed for email obfuscation. The following filters are all filtered by default:

  • link_description
  • link_notes
  • bloginfo
  • nav_menu_description
  • term_description
  • the_title
  • the_content
  • get_the_excerpt
  • comment_text
  • list_cats
  • widget_text
  • the_author_email
  • get_comment_author_email

Arguments:

  • array $filters : the default array of filters

Example:

/**
 * Also obfuscate emails appearing in custom field values.
 *
 * @param array $filters Filters that get filtered to obfuscate email addresses.
 * @return array
 */
function change_c2c_obfuscate_email_filters( $filters ) {
    $filters[] = 'the_meta';
    return $filters;
}
add_filter( 'c2c_obfuscate_email_filters', 'change_c2c_obfuscate_email_filters' );

Find out more at the plugin’s WordPress Plugin Repository page.

Screenshots

Click to see full-size image.

  1. A screenshot of the plugin's admin options page.

    A screenshot of the plugin’s admin options page.

Installation

  1. Whether installing or updating, whether this plugin or any other, it is always advisable to back-up your data before starting
  2. Install via the built-in WordPress plugin installer. Or download and unzip obfuscate-email.zip inside the plugins directory for your site (typically wp-content/plugins/)
  3. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  4. Go to Settings -> Obfuscate Email admin options page (which you can also get to via the Settings link next to the plugin on the Manage Plugins page) and optionally customize the settings.

Frequently Asked Questions

Q. So it’ll be impossible for spammers to harvest my site for email addresses?
A. Of course nothing is guaranteed. By its very definition, “obfuscate” means “to make obscure or unclear”, and that’s all it’s really doing. It’s some degree of basic protection, which is oftentimes better than nothing. Similarly, a locked door is only some measure of deterrent for a would-be intruder and not absolute security.
Your best bet would be to not publicly expose an email address. You could provide a contact form as an alternative means of contact. Or you can just accept that email addresses will get scraped and spammed, and rely on an email service that is good at filtering out spam. But this plugin is here for you if you want to employ the most reasonable means of making email harvesting difficult for your site.

Q. Aren’t there better methods of email obfuscation?
A. Nothing short of not actually displaying email addresses can guarantee that email addresses can’t get harvested. Some methods are more aggressive and therefore have compatibility and/or usability issues. This plugin can be very compatible and usable by most visitors to your site, but also has allowances for greater protection with minimal impact (though how minimal is for you to judge).

Q. Does this plugin make use of JavaScript as other email obfuscators do?
A. No. This makes this plugin’s implementation of obfuscation more compatible and usable by more visitors. This choice does leave out JavaScript-based approaches that some argue are effective in their own way (techniques such as ROT13 transformation, JS insertion/contruction of the email address, among others).

Q. Can I apply more than one of the available techniques at the same time for even greater protection?
A. Yes, all techniques can be activated at once (and multiple ones are by default).

Q. Will obfuscated links meet WCAG/508 or other accessibility standards?
A. No. Any technique used to obfuscate email address has some measure of drawbacks in terms of accessibility and/or usability. The documentation for the techniques provided by the plugin are clear about the nature of their individual drawbacks.

Q. Does this plugin modify the post content in the database?
A. No. The plugin filters post content on-the-fly. Emails will remain unchanged in the database.

Q. Why don’t I see any obfuscation when viewing the source for the page (or a selection) via my browser’s inspector?
A. The web browser’s inspector tool will process certain techniques (such as HTML hexadecimal substitution) before showing the source in the inspector. You should “View Source” to see the raw markup sent to the browser.

Q. Does this plugin include unit tests?
A. Yes.

Release Log

3.6 (2019-04-22)

  • This release is a minor update that verifies compatibility through WordPress 5.1+, drops compatibility with versions of WordPress older than 4.7, and makes minor behind-the-scenes improvements.

Details:

  • Change: Initialize plugin on plugins_loaded action instead of on load
  • Change: Update plugin framework to 049
    • 049:
    • Correct last arg in call to add_settings_field() to be an array
    • Wrap help text for settings in label instead of p
    • Only use label for help text for checkboxes, otherwise use p
    • Ensure a textarea displays as a block to prevent orphaning of subsequent help text
    • Note compatibility through WP 5.1+
    • Update copyright date (2019)
    • 048:
    • When resetting options, delete the option rather than setting it with default values
    • Prevent double “Settings reset” admin notice upon settings reset
    • 047:
    • Don’t save default setting values to database on install
    • Change “Cheatin’, huh?” error messages to “Something went wrong.”, consistent with WP core
    • Note compatibility through WP 4.9+
    • Drop compatibility with version of WP older than 4.7
    • 046:
    • Fix reset_options() to reference instance variable $options.
    • Note compatibility through WP 4.7+.
    • Update copyright date (2017)
    • 045:
    • Ensure reset_options() resets values saved in the database.
  • New: Add README.md file
  • New: Add CHANGELOG.md file and move all but most recent changelog entries into it
  • New: Add inline documentation for hook
  • New: Add GitHub link to readme
  • Unit tests:
    • New: Add unit test for defaults for settings
    • Change: Improve tests for settings handling
    • Change: Default WP_TESTS_DIR to /tmp/wordpress-tests-lib rather than erroring out if not defined via environment variable
    • Change: Enable more error output for unit tests
  • Change: Store setting name in constant
  • Change: Downplay modern-day effectiveness of the techniques and improve overall explanations
  • Change: Improve documentation for hook within readme.txt
  • Change: Note compatibility through WP 5.1+
  • Change: Drop compatibility with version of WP older than 4.7
  • Change: Convert last remaing instances of “e-mail” to “email”
  • Change: Rename readme.txt section from ‘Filters’ to ‘Hooks’ and provide a better section intro
  • Change: Modify formatting of hook name in readme to prevent being uppercased when shown in the Plugin Directory
  • Change: Update installation instruction to prefer built-in installer over .zip file
  • Change: Update copyright date (2019)
  • Change: Update License URI to be HTTPS

3.5.1 (2016-06-13)

  • Change: Update plugin framework to 044:
    • 044
    • Add reset_caches() to clear caches and memoized data. Use it in reset_options() and verify_config().
    • Add verify_options() with logic extracted from verify_config() for initializing default option attributes.
    • Add add_option() to add a new option to the plugin’s configuration.
    • Add filter ‘sanitized_option_names’ to allow modifying the list of whitelisted option names.
    • Change: Refactor get_option_names().
    • 043
    • Disregard invalid lines supplied as part of hash option value.
    • 042
    • Update disable_update_check() to check for HTTP and HTTPS for plugin update check API URL.
    • Translate “Donate” in footer message.
    • Note compatibility through WP 4.5.
  • Change: Use “email” instead of “e-mail” in plugin’s name, description, and documentation.
  • Bugfix: Add appropriate spacing so v3.5’s changelog entry gets properly parsed. Props szepeviktor.

3.5 (2016-04-04)

  • This release adds support for language packs and has some minor behind-the-scenes changes.

Details:

  • Change: Update plugin framework to 041:
    • Change class name to c2c_ObfuscateEmail_Plugin_041 to be plugin-specific.
    • Set textdomain using a string instead of a variable.
    • Don’t load textdomain from file.
    • Change admin page header from ‘h2’ to ‘h1’ tag.
    • Add c2c_plugin_version().
    • Formatting improvements to inline docs.
  • Change: Add support for language packs:
    • Set textdomain using a string instead of a variable.
    • Remove .pot file and /lang subdirectory.
    • Remove ‘Domain Path’ from plugin header.
  • New: Add LICENSE file.
  • New: Add empty index.php to prevent files from being listed if web server has enabled directory listings.
  • Change: Minor code reformatting.
  • Change: Note compatibility through WP 4.5+.
  • Change: Dropped compatibility with version of WP older than 4.1.
  • Change: Update copyright date (2016).

Copyright & Disclaimer

Copyright © 2005-2019 by Scott Reilly (aka coffee2code)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Discussion / Support

Have any questions, comments, or suggestions? Please provide them via the plugin’s WordPress.org support forum. I’ll do my best to reply in a timely fashion and help as best I can.

Unfortunately, I cannot provide guaranteed support, nor do I provide support via any other means.

Was this plugin useful useful to you? Consider giving it a rating. If you’re inclined to give it a poor rating, please first post to the support forum to give me a chance to address or explain the situation.