PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.3
JetFormBuilder — Dynamic Blocks Form Builder v3.2.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / security / honeypot / module.php
jetformbuilder / modules / security / honeypot Last commit date
module.php 2 years ago
module.php
114 lines
1 <?php
2
3
4 namespace JFB_Modules\Security\Honeypot;
5
6 use Jet_Form_Builder\Exceptions\Request_Exception;
7 use Jet_Form_Builder\Live_Form;
8 use JFB_Components\Module\Base_Module_It;
9 use JFB_Modules\Security\Exceptions\Spam_Exception;
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 class Module implements Base_Module_It {
17
18 const FIELD = '_jfb_email_hp_';
19
20 public function rep_item_id() {
21 return 'honeypot';
22 }
23
24 public function condition(): bool {
25 return true;
26 }
27
28 public function init_hooks() {
29 add_filter(
30 'jet-form-builder/after-start-form',
31 array( $this, 'on_render_form' )
32 );
33 add_filter(
34 'jet-form-builder/request-handler/request',
35 array( $this, 'handle_request' )
36 );
37 add_filter(
38 'jet-form-builder/message-types',
39 array( $this, 'handle_global_messages' )
40 );
41 }
42
43 public function remove_hooks() {
44 remove_filter(
45 'jet-form-builder/after-start-form',
46 array( $this, 'on_render_form' )
47 );
48 remove_filter(
49 'jet-form-builder/request-handler/request',
50 array( $this, 'handle_request' )
51 );
52 remove_filter(
53 'jet-form-builder/message-types',
54 array( $this, 'handle_global_messages' )
55 );
56 }
57
58 public function on_render_form( string $content ): string {
59 $args = jet_form_builder()->post_type->get_args();
60
61 if ( empty( $args['use_honeypot'] ) ) {
62 return $content;
63 }
64
65 $field = Live_Form::force_render_field(
66 'text-field',
67 array(
68 'field_type' => 'email',
69 'name' => self::FIELD,
70 'autocomplete' => 'nope',
71 )
72 );
73
74 $content .= sprintf(
75 '<div style="transform: scale(0); position: absolute;">%s</div>',
76 $field
77 );
78
79 return $content;
80 }
81
82 /**
83 * @param array $request
84 *
85 * @return array
86 * @throws Spam_Exception
87 */
88 public function handle_request( array $request ): array {
89 $args = jet_form_builder()->post_type->get_args();
90
91 if ( empty( $args['use_honeypot'] ) ) {
92 return $request;
93 }
94
95 if ( ! empty( $request[ self::FIELD ] ) ) {
96 throw new Spam_Exception( 'honeypot' );
97 }
98
99 unset( $request[ self::FIELD ] );
100
101 return $request;
102 }
103
104 public function handle_global_messages( array $types ): array {
105 $types['honeypot'] = array(
106 'label' => __( 'Honeypot validation failed', 'jet-form-builder' ),
107 'value' => __( 'You are not allowed to fill in the honeypot field', 'jet-form-builder' ),
108 );
109
110 return $types;
111 }
112
113 }
114