| 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 |
|