PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.6
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.6
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmHoneypot.php

FrmHoneypot.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.5.6, at classes/models/FrmHoneypot.php

84 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmHoneypot extends FrmValidate {
7
8 /**
9 * @return string
10 */
11 protected function get_option_key() {
12 return 'honeypot';
13 }
14
15 /**
16 * @return bool
17 */
18 public function validate() {
19 if ( ! $this->is_option_on() || ! $this->check_honeypot_filter() ) {
20 // never flag as honeypot spam if disabled.
21 return true;
22 }
23 return ! $this->is_honeypot_spam();
24 }
25
26 /**
27 * @return boolean
28 */
29 private function is_honeypot_spam() {
30 $honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' );
31 $is_honeypot_spam = $honeypot_value !== '';
32 $form = $this->get_form();
33 $atts = compact( 'form' );
34 return apply_filters( 'frm_process_honeypot', $is_honeypot_spam, $atts );
35 }
36
37 /**
38 * @return mixed either true, or false.
39 */
40 private function check_honeypot_filter() {
41 $form = $this->get_form();
42 return apply_filters( 'frm_run_honeypot', true, compact( 'form' ) );
43 }
44
45 /**
46 * @return string
47 */
48 private function check_honeypot_setting() {
49 $form = $this->get_form();
50 $key = $this->get_option_key();
51 return $form->options[ $key ];
52 }
53
54 /**
55 * @param int $form_id
56 */
57 public static function maybe_render_field( $form_id ) {
58 $honeypot = new self( $form_id );
59 if ( $honeypot->should_render_field() ) {
60 $honeypot->render_field();
61 }
62 }
63
64 /**
65 * @return bool
66 */
67 public function should_render_field() {
68 return $this->is_option_on() && $this->check_honeypot_filter();
69 }
70
71 public function render_field() {
72 $honeypot = $this->check_honeypot_setting();
73 $form = $this->get_form();
74 ?>
75 <div class="frm_verify" <?php echo in_array( $honeypot, array( true, 'strict' ), true ) ? '' : 'aria-hidden="true"'; ?>>
76 <label for="frm_email_<?php echo esc_attr( $form->id ); ?>">
77 <?php esc_html_e( 'If you are human, leave this field blank.', 'formidable' ); ?>
78 </label>
79 <input type="<?php echo esc_attr( 'strict' === $honeypot ? 'email' : 'text' ); ?>" class="frm_verify" id="frm_email_<?php echo esc_attr( $form->id ); ?>" name="frm_verify" value="<?php echo esc_attr( FrmAppHelper::get_param( 'frm_verify', '', 'get', 'wp_kses_post' ) ); ?>" <?php FrmFormsHelper::maybe_hide_inline(); ?> />
80 </div>
81 <?php
82 }
83 }
84