Email Address Encoder - Version 1.0.15

Version Description

  • Added EAE_REGEXP constant
  • Added eae_email_callback filter
  • Added unprotected email detector to admin bar
  • Respect eae_method filter in shortcode
  • Fixed issue with notices not hiding in some cases
  • Flush page cache when saving settings (W3 Total Cache; WP Rocket; LiteSpeed Cache; JCH Optimize)
Download this release

Release Info

Developer tillkruess
Plugin Icon 128x128 Email Address Encoder
Version 1.0.15
Comparing to
See all releases

Code changes from version 1.0.14 to 1.0.15

email-address-encoder.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Email Address Encoder
4
  Plugin URI: https://encoder.till.im/
5
  Description: A lightweight plugin that protects email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
6
- Version: 1.0.14
7
  Author: Till Krüss
8
  Author URI: https://till.im/
9
  Text Domain: email-address-encoder
@@ -24,6 +24,29 @@ if ( ! defined( 'EAE_FILTER_PRIORITY' ) ) {
24
  );
25
  }
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * Load admin related code.
29
  */
@@ -70,7 +93,10 @@ function eae_register_shortcode() {
70
  * @return string Encoded given text
71
  */
72
  function eae_shortcode( $attributes, $content = '' ) {
73
- return eae_encode_str( $content );
 
 
 
74
  }
75
 
76
  /**
@@ -98,28 +124,21 @@ function eae_encode_emails( $string ) {
98
  // override encoding function with the 'eae_method' filter
99
  $method = apply_filters( 'eae_method', 'eae_encode_str' );
100
 
101
- // override regex pattern with the 'eae_regexp' filter
102
- $regexp = apply_filters(
103
- 'eae_regexp',
104
- '{
105
- (?:mailto:)?
106
- (?:
107
- [-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+
108
- |
109
- ".*?"
110
- )
111
- \@
112
- (?:
113
- [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+
114
- |
115
- \[[\d.a-fA-F:]+\]
116
- )
117
- }xi'
118
- );
119
 
120
- return preg_replace_callback( $regexp, function ( $matches ) use ( $method ) {
121
- return $method( $matches[0] );
122
- }, $string );
 
 
 
 
 
 
 
 
 
123
  }
124
 
125
  /**
@@ -144,20 +163,16 @@ function eae_encode_str( $string, $hex = false ) {
144
  $seed = mt_rand( 0, (int) abs( crc32( $string ) / strlen( $string ) ) );
145
 
146
  foreach ( $chars as $key => $char ) {
147
-
148
  $ord = ord( $char );
149
 
150
  if ( $ord < 128 ) { // ignore non-ascii chars
151
-
152
  $r = ( $seed * ( 1 + $key ) ) % 100; // pseudo "random function"
153
 
154
- if ( $r > 60 && $char !== '@' && $char !== '.' ) ; // plain character (not encoded), except @-signs and dots
155
  else if ( $hex && $r < 25 ) $chars[ $key ] = '%' . bin2hex( $char ); // hex
156
  else if ( $r < 45 ) $chars[ $key ] = '&#x' . dechex( $ord ) . ';'; // hexadecimal
157
- else $chars[ $key ] = '&#' . $ord . ';'; // decimal (ascii)
158
-
159
  }
160
-
161
  }
162
 
163
  return implode( '', $chars );
3
  Plugin Name: Email Address Encoder
4
  Plugin URI: https://encoder.till.im/
5
  Description: A lightweight plugin that protects email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
6
+ Version: 1.0.15
7
  Author: Till Krüss
8
  Author URI: https://till.im/
9
  Text Domain: email-address-encoder
24
  );
25
  }
26
 
27
+ /**
28
+ * Define regular expression constant, unless it has already been defined.
29
+ */
30
+ if ( ! defined( 'EAE_REGEXP' ) ) {
31
+ define(
32
+ 'EAE_REGEXP',
33
+ '{
34
+ (?:mailto:)?
35
+ (?:
36
+ [-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+
37
+ |
38
+ ".*?"
39
+ )
40
+ \@
41
+ (?:
42
+ [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+
43
+ |
44
+ \[[\d.a-fA-F:]+\]
45
+ )
46
+ }xi'
47
+ );
48
+ }
49
+
50
  /**
51
  * Load admin related code.
52
  */
93
  * @return string Encoded given text
94
  */
95
  function eae_shortcode( $attributes, $content = '' ) {
96
+ // override encoding function with the 'eae_method' filter
97
+ $method = apply_filters( 'eae_method', 'eae_encode_str' );
98
+
99
+ return $method( $content );
100
  }
101
 
102
  /**
124
  // override encoding function with the 'eae_method' filter
125
  $method = apply_filters( 'eae_method', 'eae_encode_str' );
126
 
127
+ // override regular expression with the 'eae_regexp' filter
128
+ $regexp = apply_filters( 'eae_regexp', EAE_REGEXP );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
+ $callback = function ( $matches ) use ( $method ) {
131
+ return $method( $matches[ 0 ] );
132
+ };
133
+
134
+ // override callback method with the 'eae_email_callback' filter
135
+ if ( has_filter( 'eae_email_callback' ) ) {
136
+ $callback = apply_filters( 'eae_email_callback', $callback, $method );
137
+
138
+ return preg_replace_callback( $regexp, $callback, $string );
139
+ }
140
+
141
+ return preg_replace_callback( $regexp, $callback, $string );
142
  }
143
 
144
  /**
163
  $seed = mt_rand( 0, (int) abs( crc32( $string ) / strlen( $string ) ) );
164
 
165
  foreach ( $chars as $key => $char ) {
 
166
  $ord = ord( $char );
167
 
168
  if ( $ord < 128 ) { // ignore non-ascii chars
 
169
  $r = ( $seed * ( 1 + $key ) ) % 100; // pseudo "random function"
170
 
171
+ if ( $r > 75 && $char !== '@' && $char !== '.' ); // plain character (not encoded), except @-signs and dots
172
  else if ( $hex && $r < 25 ) $chars[ $key ] = '%' . bin2hex( $char ); // hex
173
  else if ( $r < 45 ) $chars[ $key ] = '&#x' . dechex( $ord ) . ';'; // hexadecimal
174
+ else $chars[ $key ] = "&#{$ord};"; // decimal (ascii)
 
175
  }
 
176
  }
177
 
178
  return implode( '', $chars );
includes/admin.php CHANGED
@@ -27,16 +27,26 @@ add_filter( 'plugin_action_links', 'eae_plugin_actions_links', 10, 2 );
27
  */
28
  add_action( 'admin_notices', 'eae_page_scanner_notice' );
29
 
 
 
 
 
 
30
  /**
31
  * Register admin scripts callback.
32
  */
33
- add_action( 'admin_enqueue_scripts', 'eae_enqueue_script' );
34
 
35
  /**
36
  * Register callback to transmit email address to remote server.
37
  */
38
  add_action( 'load-settings_page_email-address-encoder', 'eae_transmit_email' );
39
 
 
 
 
 
 
40
  /**
41
  * Register AJAX callback for "eae_dismiss_notice" action.
42
  */
@@ -151,12 +161,65 @@ function eae_plugin_actions_links( $links, $file ) {
151
  ), $links );
152
  }
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  /**
155
  * Callback to add dismissible notices script on Dashboard screen.
156
  *
157
  * @return void
158
  */
159
- function eae_enqueue_script() {
160
  $screen = get_current_screen();
161
 
162
  if ( ! isset( $screen->id ) || $screen->id !== 'dashboard' ) {
@@ -210,7 +273,7 @@ function eae_page_scanner_notice() {
210
  return;
211
  }
212
 
213
- if ( get_option( 'eae_notices', '0' ) === '1' ) {
214
  return;
215
  }
216
 
@@ -286,3 +349,38 @@ function eae_transmit_email() {
286
  'updated'
287
  );
288
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  */
28
  add_action( 'admin_notices', 'eae_page_scanner_notice' );
29
 
30
+ /**
31
+ * Register scripts callback.
32
+ */
33
+ add_action( 'wp_enqueue_scripts', 'eae_enqueue_scripts' );
34
+
35
  /**
36
  * Register admin scripts callback.
37
  */
38
+ add_action( 'admin_enqueue_scripts', 'eae_enqueue_admin_scripts' );
39
 
40
  /**
41
  * Register callback to transmit email address to remote server.
42
  */
43
  add_action( 'load-settings_page_email-address-encoder', 'eae_transmit_email' );
44
 
45
+ /**
46
+ * Register callback to clear page caches.
47
+ */
48
+ add_action( 'load-options.php', 'eae_clear_caches' );
49
+
50
  /**
51
  * Register AJAX callback for "eae_dismiss_notice" action.
52
  */
161
  ), $links );
162
  }
163
 
164
+ /**
165
+ * Callback to load email detector script.
166
+ *
167
+ * @return void
168
+ */
169
+ function eae_enqueue_scripts() {
170
+ if ( ! is_admin_bar_showing() ) {
171
+ return;
172
+ }
173
+
174
+ if ( is_preview() ) {
175
+ return;
176
+ }
177
+
178
+ if ( ! current_user_can( 'manage_options' ) ) {
179
+ return;
180
+ }
181
+
182
+ if ( defined( 'EAE_DISABLE_NOTICES' ) && EAE_DISABLE_NOTICES ) {
183
+ return;
184
+ }
185
+
186
+ if ( get_option( 'eae_notices', '0' ) == '1' ) {
187
+ return;
188
+ }
189
+
190
+ add_action( 'wp_footer', 'eae_adminbar_styles' );
191
+
192
+ wp_enqueue_script(
193
+ 'email-detector',
194
+ plugins_url( 'email-detector.js', __FILE__ ),
195
+ null,
196
+ false,
197
+ true
198
+ );
199
+
200
+ wp_localize_script( 'email-detector', 'eaeDetectorL10n', array(
201
+ 'one_email' => __( '1 Unprotected Email', 'email-address-encoder' ),
202
+ 'many_emails' => __( '{number} Unprotected Emails', 'email-address-encoder' ),
203
+ ) );
204
+ }
205
+
206
+ /**
207
+ * Callback to load email detector script.
208
+ *
209
+ * @return void
210
+ */
211
+ function eae_adminbar_styles() {
212
+ $styles = '#wp-admin-bar-eae > .ab-item:before { content: "\f534"; top: 2px; }';
213
+
214
+ echo "\n<style type=\"text/css\">{$styles}</style>\n";
215
+ }
216
+
217
  /**
218
  * Callback to add dismissible notices script on Dashboard screen.
219
  *
220
  * @return void
221
  */
222
+ function eae_enqueue_admin_scripts() {
223
  $screen = get_current_screen();
224
 
225
  if ( ! isset( $screen->id ) || $screen->id !== 'dashboard' ) {
273
  return;
274
  }
275
 
276
+ if ( get_option( 'eae_notices', '0' ) == '1' ) {
277
  return;
278
  }
279
 
349
  'updated'
350
  );
351
  }
352
+
353
+ /**
354
+ * Clear page caches caches.
355
+ *
356
+ * @return void
357
+ */
358
+ function eae_clear_caches() {
359
+ if (
360
+ empty( $_POST ) ||
361
+ ! isset( $_POST[ 'option_page' ] ) ||
362
+ $_POST[ 'option_page' ] !== 'email-address-encoder'
363
+ ) {
364
+ return;
365
+ }
366
+
367
+ // W3 Total Cache
368
+ if ( function_exists( 'w3tc_flush_all' ) ) {
369
+ w3tc_flush_all();
370
+ }
371
+
372
+ // WP Rocket
373
+ if ( function_exists( 'rocket_clean_domain' ) ) {
374
+ rocket_clean_domain();
375
+ }
376
+
377
+ // JCH Optimize
378
+ if ( class_exists( 'JchPlatformCache' ) && method_exists( JchPlatformCache::class, 'deleteCache' ) ) {
379
+ JchPlatformCache::deleteCache( true );
380
+ }
381
+
382
+ // LiteSpeed Cache
383
+ if ( class_exists( 'LiteSpeed_Cache_API' ) && method_exists( LiteSpeed_Cache_API::class, 'purge_all' ) ) {
384
+ LiteSpeed_Cache_API::purge_all();
385
+ }
386
+ }
includes/dismiss-notice.js CHANGED
@@ -1,6 +1,6 @@
1
  ( function ( $ ) {
2
  $( function () {
3
- $( ".notice[data-dismissible] .notice-dismiss" ).click(function (event) {
4
  $.post( ajaxurl, {
5
  notice: $( this ).parent().attr( "data-dismissible" ),
6
  action: "eae_dismiss_notice",
1
  ( function ( $ ) {
2
  $( function () {
3
+ $( ".notice[data-dismissible] .notice-dismiss" ).click( function ( event ) {
4
  $.post( ajaxurl, {
5
  notice: $( this ).parent().attr( "data-dismissible" ),
6
  action: "eae_dismiss_notice",
includes/email-detector.js ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ( function () {
2
+ var fetchPageSource = function () {
3
+ if ( ! document.getElementById( "wp-admin-bar-root-default" ) ) {
4
+ return;
5
+ }
6
+
7
+ if ( ! ( "fetch" in window ) ) {
8
+ return;
9
+ }
10
+
11
+ fetch( document.location.href ).then( function ( response ) {
12
+ if ( ! response.ok ) {
13
+ throw Error( response.statusText );
14
+ }
15
+
16
+ return response;
17
+ } ).then( function ( response ) {
18
+ return response.text();
19
+ } ).then( function ( pageSource ) {
20
+ appendToAdminbar( findEmails( pageSource ) );
21
+ } ).catch( function () {
22
+ //
23
+ } );
24
+ };
25
+
26
+ var findEmails = function ( content ) {
27
+ var match;
28
+ var emails = [];
29
+ var regex = /(?:mailto:)?(?:[-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+|".*?")@(?:[-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+|\[[\d.a-fA-F:]+\])/gi;
30
+
31
+ while ( ( match = regex.exec( content ) ) !== null ) {
32
+ if ( match.index === regex.lastIndex ) {
33
+ regex.lastIndex++;
34
+ }
35
+
36
+ emails.push( match[ 0 ] );
37
+ }
38
+
39
+ return emails;
40
+ };
41
+
42
+ var appendToAdminbar = function ( emails ) {
43
+ if ( ! emails.length ) {
44
+ return;
45
+ }
46
+
47
+ var scannerUrl = "https://encoder.till.im/scanner?utm_source=wp-plugin&utm_medium=adminbar";
48
+
49
+ var text = emails.length === 1
50
+ ? eaeDetectorL10n.one_email
51
+ : eaeDetectorL10n.many_emails.replace( "{number}", emails.length );
52
+
53
+ var a = document.createElement( "a" );
54
+ a.setAttribute( "class", "ab-item" );
55
+ a.setAttribute( "href", scannerUrl + "&url=" + encodeURIComponent( window.location.href ) );
56
+ a.appendChild( document.createTextNode( text ) );
57
+
58
+ var li = document.createElement( "li" );
59
+ li.setAttribute( "id", "wp-admin-bar-eae" );
60
+ li.setAttribute( "class", "" );
61
+ li.appendChild( a );
62
+
63
+ document.getElementById( "wp-admin-bar-root-default" ).appendChild( li );
64
+ };
65
+
66
+ if ( document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading" ) {
67
+ fetchPageSource();
68
+ } else {
69
+ document.addEventListener( "DOMContentLoaded", fetchPageSource );
70
+ }
71
+ } () );
includes/ui.php CHANGED
@@ -3,7 +3,7 @@
3
 
4
  <h1><?php _e( 'Email Address Encoder', 'email-address-encoder' ); ?></h1>
5
 
6
- <?php if ( get_option( 'eae_notices', '0' ) !== '1' && ( ! defined( 'EAE_DISABLE_NOTICES' ) || ! EAE_DISABLE_NOTICES ) ) : ?>
7
 
8
  <div class="card" style="float: left; margin-bottom: 0; margin-right: 1.25rem;">
9
  <h2 class="title">
@@ -67,7 +67,7 @@
67
  <br>
68
  <label>
69
  <input type="radio" name="eae_search_in" value="filters" disabled>
70
- <?php _e( 'Full page scan', 'email-address-encoder' ); ?>
71
  (<a target="_blank" rel="noopener" href="https://encoder.till.im/download?utm_source=wp-plugin&utm_medium=setting"><?php _e( 'Premium only', 'email-address-encoder' ); ?></a>)
72
  <p class="description">
73
  <small><?php _e( 'Protects all email addresses on your site.', 'email-address-encoder' ); ?></small>
@@ -76,7 +76,7 @@
76
  <br>
77
  <label>
78
  <input type="radio" name="eae_search_in" value="void" <?php checked( 'void', get_option( 'eae_search_in' ) ); ?>>
79
- <?php _e( 'Nothing', 'email-address-encoder' ); ?>
80
  <p class="description">
81
  <small><?php _e( 'Turns off email protection.', 'email-address-encoder' ); ?></small>
82
  </p>
3
 
4
  <h1><?php _e( 'Email Address Encoder', 'email-address-encoder' ); ?></h1>
5
 
6
+ <?php if ( get_option( 'eae_notices', '0' ) != '1' && ( ! defined( 'EAE_DISABLE_NOTICES' ) || ! EAE_DISABLE_NOTICES ) ) : ?>
7
 
8
  <div class="card" style="float: left; margin-bottom: 0; margin-right: 1.25rem;">
9
  <h2 class="title">
67
  <br>
68
  <label>
69
  <input type="radio" name="eae_search_in" value="filters" disabled>
70
+ <?php _e( 'Full-page scanner', 'email-address-encoder' ); ?>
71
  (<a target="_blank" rel="noopener" href="https://encoder.till.im/download?utm_source=wp-plugin&utm_medium=setting"><?php _e( 'Premium only', 'email-address-encoder' ); ?></a>)
72
  <p class="description">
73
  <small><?php _e( 'Protects all email addresses on your site.', 'email-address-encoder' ); ?></small>
76
  <br>
77
  <label>
78
  <input type="radio" name="eae_search_in" value="void" <?php checked( 'void', get_option( 'eae_search_in' ) ); ?>>
79
+ <?php _e( 'Nothing, don’t do anything', 'email-address-encoder' ); ?>
80
  <p class="description">
81
  <small><?php _e( 'Turns off email protection.', 'email-address-encoder' ); ?></small>
82
  </p>
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: tillkruess
3
  Donate link: https://www.paypal.me/tillkruss
4
  Tags: antispam, anti spam, spam, email, e-mail, mail, spider, crawler, harvester, robots, spambot, block, obfuscate, obfuscation, encode, encoder, encoding, encrypt, encryption, protect, protection
5
  Requires at least: 2.0
6
- Tested up to: 5.0
7
  Requires PHP: 5.3
8
- Stable tag: 1.0.14
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -67,6 +67,15 @@ You can use the "Page Scanner" found under _Settings -> Email Encoder_ to see wh
67
 
68
  == Changelog ==
69
 
 
 
 
 
 
 
 
 
 
70
  = 1.0.14 =
71
 
72
  * Fixed Dashboard JavaScript issue
@@ -189,4 +198,4 @@ Added filter to override the regular expression.
189
 
190
  = 1.0.1 =
191
 
192
- Effects now also page, post and comment excerpts.
3
  Donate link: https://www.paypal.me/tillkruss
4
  Tags: antispam, anti spam, spam, email, e-mail, mail, spider, crawler, harvester, robots, spambot, block, obfuscate, obfuscation, encode, encoder, encoding, encrypt, encryption, protect, protection
5
  Requires at least: 2.0
6
+ Tested up to: 5.1
7
  Requires PHP: 5.3
8
+ Stable tag: 1.0.15
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
67
 
68
  == Changelog ==
69
 
70
+ = 1.0.15 =
71
+
72
+ * Added `EAE_REGEXP` constant
73
+ * Added `eae_email_callback` filter
74
+ * Added unprotected email detector to admin bar
75
+ * Respect `eae_method` filter in shortcode
76
+ * Fixed issue with notices not hiding in some cases
77
+ * Flush page cache when saving settings (W3 Total Cache; WP Rocket; LiteSpeed Cache; JCH Optimize)
78
+
79
  = 1.0.14 =
80
 
81
  * Fixed Dashboard JavaScript issue
198
 
199
  = 1.0.1 =
200
 
201
+ Effects now also page, post and comment excerpts.