PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.3.6
Email Encoder – Protect Email Addresses and Phone Numbers v2.3.6
2.5.3 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 8 months ago class-email-encoder-bundle-helpers.php 8 months ago class-email-encoder-bundle-settings.php 8 months ago class-email-encoder-bundle-validate.php 8 months ago index.php 6 years ago
class-email-encoder-bundle-ajax.php
93 lines
1 <?php
2
3 namespace Legacy\EmailEncoderBundle;
4
5 use OnlineOptimisation\EmailEncoderBundle\Traits\PluginHelper;
6
7 class Email_Encoder_Ajax{
8
9 use PluginHelper;
10
11 public function boot(): void {
12 add_action( 'init', [ $this, 'register_hooks' ] );
13 }
14
15 public function register_hooks(): void
16 {
17 $EEB = Email_Encoder::instance();
18 $page = $EEB->settings->get_page_name();
19
20 $is_target_admin_page = $EEB->helpers->is_page( $page )
21 || ( wp_doing_ajax() && ( $_POST['action'] ?? '' ) === 'eeb_get_email_form_output')
22 ;
23
24 if ( $is_target_admin_page ) {
25 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
26 add_action( 'wp_ajax_eeb_get_email_form_output', [ $this, 'handle' ] );
27 }
28
29 if ( (bool) $EEB->settings->get_setting( 'encoder_form_frontend', true, 'encoder_form' ) ) {
30 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
31 add_action( 'wp_ajax_nopriv_eeb_get_email_form_output', [ $this, 'handle' ] );
32 }
33 }
34
35
36 public function enqueue_scripts(): void
37 {
38 $file = EEB_PLUGIN_DIR . 'core/includes/assets/js/encoder-form.js';
39 $ver = file_exists( $file ) ? filemtime( $file ) : false;
40
41 wp_enqueue_script(
42 'eeb-js-ajax-ef',
43 EEB_PLUGIN_URL . 'core/includes/assets/js/encoder-form.js',
44 [ 'jquery' ],
45 $ver,
46 true
47 );
48
49 wp_localize_script( 'eeb-js-ajax-ef', 'eeb_ef', [
50 'ajaxurl' => admin_url( 'admin-ajax.php' ),
51 'security' => wp_create_nonce( 'eeb_form' )
52 ] );
53 }
54
55
56 public function handle(): void
57 {
58 check_ajax_referer( 'eeb_form', 'eebsec' );
59
60 $email = sanitize_email( $_POST['eebEmail'] ?? '' );
61 $method = sanitize_text_field( $_POST['eebMethod'] ?? '' );
62 $display = wp_kses_post( $_POST['eebDisplay'] ?? '' );
63 $display = $display ?: $email;
64
65 $EEB = Email_Encoder::instance();
66
67 $class = esc_attr( $this->getSetting( 'class_name', true ) );
68 $protect = __( $this->getSetting( 'protection_text', true ), 'email-encoder-bundle' );
69 $link = '<a href="mailto:' . $email . '" class="' . $class . '">' . $display . '</a>';
70
71 switch ( $method ) {
72 case 'rot13':
73 $link = $this->encodeAscii($link, $protect);
74 break;
75
76 case 'escape':
77 $link = $this->encodeEscape($link, $protect);
78 break;
79
80 default:
81 $link = '<a href="mailto:' . antispambot($email) . '" class="' . $class . '">' . antispambot($display) . '</a>';
82 }
83
84 # @TODO: Proper way to do this
85 // wp_send_json_success( apply_filters('eeb/ajax/encoder_form_response', $link) );
86
87 # @TODO: Old way
88 echo apply_filters('eeb/ajax/encoder_form_response', $link);
89 exit;
90 }
91
92 }
93