PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
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 1 year ago
module.php
124 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 const SPAM_EXCEPTION = 'honeypot';
29 public function __construct() {
30 add_filter( 'jet-form-builder/security/spam-statuses', array( $this, 'add_spam_statuses' ) );
31 }
32 public function add_spam_statuses( $statuses ) {
33 $statuses[] = self::SPAM_EXCEPTION;
34 return $statuses;
35 }
36
37 public function init_hooks() {
38 add_filter(
39 'jet-form-builder/after-start-form',
40 array( $this, 'on_render_form' )
41 );
42 add_filter(
43 'jet-form-builder/request-handler/request',
44 array( $this, 'handle_request' )
45 );
46 add_filter(
47 'jet-form-builder/message-types',
48 array( $this, 'handle_global_messages' )
49 );
50 }
51
52 public function remove_hooks() {
53 remove_filter(
54 'jet-form-builder/after-start-form',
55 array( $this, 'on_render_form' )
56 );
57 remove_filter(
58 'jet-form-builder/request-handler/request',
59 array( $this, 'handle_request' )
60 );
61 remove_filter(
62 'jet-form-builder/message-types',
63 array( $this, 'handle_global_messages' )
64 );
65 }
66
67 public function on_render_form( string $content ): string {
68 $args = jet_form_builder()->post_type->get_args();
69
70 if ( empty( $args['use_honeypot'] ) ) {
71 return $content;
72 }
73
74 $field = Live_Form::force_render_field(
75 'text-field',
76 array(
77 'field_type' => 'email',
78 'name' => self::FIELD,
79 'autocomplete' => 'nope',
80 )
81 );
82
83 $content .= sprintf(
84 '<div style="transform: scale(0); position: absolute;">%s</div>',
85 $field
86 );
87
88 return $content;
89 }
90
91 /**
92 * @param array $request
93 *
94 * @return array
95 * @throws Spam_Exception
96 */
97 public function handle_request( array $request ): array {
98 $args = jet_form_builder()->post_type->get_args();
99
100 if ( empty( $args['use_honeypot'] ) ) {
101 return $request;
102 }
103
104 if ( ! empty( $request[ self::FIELD ] ) ) {
105 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
106 throw new Spam_Exception( self::SPAM_EXCEPTION );
107 }
108
109 unset( $request[ self::FIELD ] );
110
111 return $request;
112 }
113
114 public function handle_global_messages( array $types ): array {
115 $types[ self::SPAM_EXCEPTION ] = array(
116 'label' => __( 'Honeypot validation failed', 'jet-form-builder' ),
117 'value' => __( 'You are not allowed to fill in the honeypot field', 'jet-form-builder' ),
118 );
119
120 return $types;
121 }
122
123 }
124