PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.5.1
Email Encoder – Protect Email Addresses and Phone Numbers v2.5.1
2.5.2 2.5.1 2.5.0 2.4.8 trunk 0.10 0.11 0.12 0.20 0.21 0.22 0.30 0.31 0.32 0.40 0.41 0.42 0.50 0.60 0.70 0.71 0.80 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5 1.5.2 1.51 1.53 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7
email-encoder-bundle / core / includes / classes / class-email-encoder-bundle-ajax.php
email-encoder-bundle / core / includes / classes Last commit date
class-email-encoder-bundle-ajax.php 2 months ago class-email-encoder-bundle-helpers.php 3 months ago class-email-encoder-bundle-settings.php 2 months ago index.php 6 years ago
class-email-encoder-bundle-ajax.php
99 lines
1 <?php
2
3 namespace Legacy\EmailEncoderBundle;
4
5 if ( ! defined( 'ABSPATH' ) ) exit;
6
7 use OnlineOptimisation\EmailEncoderBundle\Traits\PluginHelper;
8
9 class Email_Encoder_Ajax{
10
11 use PluginHelper;
12
13 public function boot(): void {
14 add_action( 'init', [ $this, 'register_hooks' ] );
15 }
16
17 public function register_hooks(): void
18 {
19 $EEB = Email_Encoder::instance();
20 $page = $EEB->settings->get_page_name();
21
22 $is_target_admin_page = $EEB->helpers->is_page( $page )
23 || ( wp_doing_ajax() && ( $_POST['action'] ?? '' ) === 'eeb_get_email_form_output')
24 ;
25
26 if ( $is_target_admin_page ) {
27 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
28 add_action( 'wp_ajax_eeb_get_email_form_output', [ $this, 'handle' ] );
29 }
30
31 // The [eeb_form] shortcode and eeb_form() template tag are always
32 // available on the frontend; the public AJAX endpoint always
33 // listens. The form JS is enqueued lazily by EncoderForm itself
34 // when the form actually renders — covers shortcodes in widgets,
35 // FSE blocks, theme files, and template-tag calls without
36 // scanning post_content site-wide.
37 add_action( 'wp_ajax_nopriv_eeb_get_email_form_output', [ $this, 'handle' ] );
38 }
39
40
41 public function enqueue_scripts(): void
42 {
43 $file = EEB_PLUGIN_DIR . 'core/includes/assets/js/encoder-form.js';
44 $ver = file_exists( $file ) ? filemtime( $file ) : false;
45
46 wp_enqueue_script(
47 'eeb-js-ajax-ef',
48 EEB_PLUGIN_URL . 'core/includes/assets/js/encoder-form.js',
49 [ 'jquery' ],
50 (string) $ver,
51 true
52 );
53
54 wp_localize_script( 'eeb-js-ajax-ef', 'eeb_ef', [
55 'ajaxurl' => admin_url( 'admin-ajax.php' ),
56 'security' => wp_create_nonce( 'eeb_form' )
57 ] );
58 }
59
60
61 public function handle(): void
62 {
63 check_ajax_referer( 'eeb_form', 'eebsec' );
64
65 $email = sanitize_email( $_POST['eebEmail'] ?? '' );
66 $method = sanitize_text_field( $_POST['eebMethod'] ?? '' );
67 $display = wp_kses_post( $_POST['eebDisplay'] ?? '' );
68 $display = $display ?: $email;
69
70 $EEB = Email_Encoder::instance();
71
72 $class = esc_attr( $this->getSetting( 'class_name', true ) );
73 $protect = (string) $this->getSetting( 'protection_text', true );
74 $link = '<a href="mailto:' . $email . '" class="' . $class . '">' . $display . '</a>';
75
76 switch ( $method ) {
77 case 'rot13':
78 $link = $this->encodeAscii($link, $protect);
79 break;
80
81 case 'escape':
82 $link = $this->encodeEscape($link, $protect);
83 break;
84
85 default:
86 $link = '<a href="mailto:' . antispambot($email) . '" class="' . $class . '">' . antispambot($display) . '</a>';
87 }
88
89 # @TODO: Proper way to do this
90 // wp_send_json_success( apply_filters('eeb/ajax/encoder_form_response', $link) );
91
92 # @TODO: Old way
93 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is encoded email HTML built with antispambot/rot13/escape encoding; escaping would break the protection.
94 echo apply_filters('eeb/ajax/encoder_form_response', $link);
95 exit;
96 }
97
98 }
99