PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.4.7
Email Encoder – Protect Email Addresses and Phone Numbers v2.4.7
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 3 months ago class-email-encoder-bundle-helpers.php 3 months ago class-email-encoder-bundle-settings.php 3 months ago index.php 6 years ago
class-email-encoder-bundle-ajax.php
96 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 if ( (bool) $EEB->settings->get_setting( 'encoder_form_frontend', true, 'encoder_form' ) ) {
32 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
33 add_action( 'wp_ajax_nopriv_eeb_get_email_form_output', [ $this, 'handle' ] );
34 }
35 }
36
37
38 public function enqueue_scripts(): void
39 {
40 $file = EEB_PLUGIN_DIR . 'core/includes/assets/js/encoder-form.js';
41 $ver = file_exists( $file ) ? filemtime( $file ) : false;
42
43 wp_enqueue_script(
44 'eeb-js-ajax-ef',
45 EEB_PLUGIN_URL . 'core/includes/assets/js/encoder-form.js',
46 [ 'jquery' ],
47 (string) $ver,
48 true
49 );
50
51 wp_localize_script( 'eeb-js-ajax-ef', 'eeb_ef', [
52 'ajaxurl' => admin_url( 'admin-ajax.php' ),
53 'security' => wp_create_nonce( 'eeb_form' )
54 ] );
55 }
56
57
58 public function handle(): void
59 {
60 check_ajax_referer( 'eeb_form', 'eebsec' );
61
62 $email = sanitize_email( $_POST['eebEmail'] ?? '' );
63 $method = sanitize_text_field( $_POST['eebMethod'] ?? '' );
64 $display = wp_kses_post( $_POST['eebDisplay'] ?? '' );
65 $display = $display ?: $email;
66
67 $EEB = Email_Encoder::instance();
68
69 $class = esc_attr( $this->getSetting( 'class_name', true ) );
70 $protect = (string) $this->getSetting( 'protection_text', true );
71 $link = '<a href="mailto:' . $email . '" class="' . $class . '">' . $display . '</a>';
72
73 switch ( $method ) {
74 case 'rot13':
75 $link = $this->encodeAscii($link, $protect);
76 break;
77
78 case 'escape':
79 $link = $this->encodeEscape($link, $protect);
80 break;
81
82 default:
83 $link = '<a href="mailto:' . antispambot($email) . '" class="' . $class . '">' . antispambot($display) . '</a>';
84 }
85
86 # @TODO: Proper way to do this
87 // wp_send_json_success( apply_filters('eeb/ajax/encoder_form_response', $link) );
88
89 # @TODO: Old way
90 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is encoded email HTML built with antispambot/rot13/escape encoding; escaping would break the protection.
91 echo apply_filters('eeb/ajax/encoder_form_response', $link);
92 exit;
93 }
94
95 }
96