Skip to main content

Gravity_Forms\Gravity_Forms\Honeypot\GF_Honeypot_Handler

Class GF_Honeypot_Handler

Since: 2.7 (Provides functionality for handling honeypot spam prevention services.)

Source: includes/honeypot/class-gf-honeypot-handler.php:19

Details

  • Kind: class
  • Namespace: Gravity_Forms\Gravity_Forms\Honeypot

Methods

MethodDescription
handle_entry_is_spam()Target of the gform_entry_is_spam filter. Checks entry for honeypot validation and returns true or false depending on the result.
handle_abort_submission()Target of the gform_abort_submission_with_confirmation filter. Aborts form submission early with a confirmation when honeypot fails and it is configured not to create an entry.
handle_after_submission()Target of the gform_after_submission. Clears the cached results.
maybe_add_honeypot_field()Adds the honeypot field to the form if honeypot is enabled.
get_cached_result()Returns the cached result for the given form ID.
cache_result()Caches the result for the given form ID.
validate_honeypot()Validates the submission against the honeypot field.
get_honeypot_field_id()Returns the ID of the honeypot field.
get_input_name()Returns the value used in the name attribute of the honeypot input.
get_honeypot_field()Creates the honeypot field object for the given form.
is_valid_version_hash()Validates a version hash.
is_honeypot_enabled()Determines if Honeypot should be enabled for this form submission.
is_api_submission()Determines if the current form submission was initiated via GFAPI.
is_speed_check_enabled()Determines if the submission speed check is enabled.
get_submission_speed_threshold()Returns the submission speed threshold.
is_strict_submission_speed_mode_enabled()Determines if strict mode is enabled for the submission speed check.
is_valid_submission_speed()Determines if the submission speed check is valid.
format_submission_speeds_for_note()Formats the submission speeds for the entry note.
check_submission_speeds()Checks the submission speeds against the threshold.
get_submission_speeds_array()Parses and sanitizes the submission speeds from the gform_submit_speeds input for the current form.
get_submission_speeds_json()JSON encodes the submission speeds for the current form markup.
submission_speeds_entry_meta()Registers and saves the submission speeds to the entry meta, so the user can display it as an entries list column.
submission_speeds_entries_field_value()Formats the value for display in an entries list column.
submission_speeds_entry_detail_meta_box()Displays the submission speeds on the entry detail page.
cache_invalid_state_counts()Caches the invalid state counts for the current form.

Method Reference

handle_entry_is_spam()

public function handle_entry_is_spam( $is_spam, $form )

Target of the gform_entry_is_spam filter. Checks entry for honeypot validation and returns true or false depending on the result.

Parameters

NameTypeDefaultDescription
$is_spamboolVariable being filtered. True for spam, false for non-spam.
$formarrayCurrent form object.

Returns

  • bool — Returns true if honeypot validation fails. False otherwise.

Since:

  • 2.7
  • 2.9.21 (Updated to get the entry note message from get_cached_result().)

Source: includes/honeypot/class-gf-honeypot-handler.php:32

handle_abort_submission()

public function handle_abort_submission( $do_abort, $form )

Target of the gform_abort_submission_with_confirmation filter. Aborts form submission early with a confirmation when honeypot fails and it is configured not to create an entry.

Parameters

NameTypeDefaultDescription
$do_abortboolVariable being filtered. True to abort submission, false to continue.
$formarrayCurrent form object.

Returns

  • bool — Returns true to abort form submission early and display confirmation. Returns false to let submission continue.

Since:

  • 2.7
  • 2.9.8 (Updated honeypotAction default to spam.)

Source: includes/honeypot/class-gf-honeypot-handler.php:68

handle_after_submission()

public function handle_after_submission( $entry, $form )

Target of the gform_after_submission. Clears the cached results.

Parameters

NameTypeDefaultDescription
$entryarrayCurrent entry object.
$formarrayCurrent form object.

Since:

  • 2.7
  • 3.0 (Updated to also clear cached invalid state counts.)

Source: includes/honeypot/class-gf-honeypot-handler.php:107

maybe_add_honeypot_field()

public function maybe_add_honeypot_field( $form )

Adds the honeypot field to the form if honeypot is enabled.

Parameters

NameTypeDefaultDescription
$formarrayCurrent form object.

Returns

  • array — Returns a form object with the new honeypot field appended to the fields array.

Since: 2.7

Source: includes/honeypot/class-gf-honeypot-handler.php:125

get_cached_result()

public function get_cached_result( $form_id )

Returns the cached result for the given form ID.

Parameters

NameTypeDefaultDescription
$form_idintThe current form ID.

Returns

  • false | array

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:146

cache_result()

public function cache_result( $form_id, $result )

Caches the result for the given form ID.

Parameters

NameTypeDefaultDescription
$form_idintThe current form ID.
$resultarrayThe result to be cached.

Returns

  • void

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:160

validate_honeypot()

public function validate_honeypot( $form )

Validates the submission against the honeypot field.

Parameters

NameTypeDefaultDescription
$formarrayThe current form object.

Returns

  • bool — True if form passes the honeypot validation (i.e. Not spam). False if honeypot validation fails (i.e. spam)

Since:

  • 2.7
  • 2.9.16 (Updated to use get_input_name().)
  • 2.9.21 (Updated to perform a submission speed check, return early on invalid checks, and to use get_cached_result() and cache_result().)
  • 3.0 (Updated to include state validation.)

Source: includes/honeypot/class-gf-honeypot-handler.php:176

get_honeypot_field_id()

public function get_honeypot_field_id( $form )

Returns the ID of the honeypot field.

Parameters

NameTypeDefaultDescription
$formarrayCurrent form object.

Returns

  • int — Returns the id of the honeypot field.

Since: 2.7

Source: includes/honeypot/class-gf-honeypot-handler.php:335

get_input_name()

public function get_input_name( $form, $id=null )

Returns the value used in the name attribute of the honeypot input.

Parameters

NameTypeDefaultDescription
$formarrayThe form being rendered or validated.
$idnull | intnullThe ID of the honeypot field, or null to use GF_Honeypot_Handler::get_honeypot_field_id().

Returns

  • string

Since: 2.9.16

Source: includes/honeypot/class-gf-honeypot-handler.php:362

get_honeypot_field()

public function get_honeypot_field( $form )

Creates the honeypot field object for the given form.

Parameters

NameTypeDefaultDescription
$formarrayThe form the honeypot field is to be created for.

Returns

  • bool | \GF_Field — Returns the honeypot field.

Since: 2.7

Source: includes/honeypot/class-gf-honeypot-handler.php:389

is_valid_version_hash()

public function is_valid_version_hash( $hash )

Validates a version hash.

Parameters

NameTypeDefaultDescription
$hashstringThe version hash to be validated.

Returns

  • bool — Returns true if the hash is validated against the current and previous version of Gravity Forms

Since: 2.7

Source: includes/honeypot/class-gf-honeypot-handler.php:445

is_honeypot_enabled()

public function is_honeypot_enabled( $form )

Determines if Honeypot should be enabled for this form submission.

Parameters

NameTypeDefaultDescription
$formarrayThe current form object.

Returns

  • bool — True if honeypot should be enabled. False otherwise.

Since: 2.7

Source: includes/honeypot/class-gf-honeypot-handler.php:470

is_api_submission()

public function is_api_submission()

Determines if the current form submission was initiated via GFAPI.

Returns

  • bool — True if the current form submission was initiated via GFAPI. False otherwise.

Since: 2.7

Source: includes/honeypot/class-gf-honeypot-handler.php:489

is_speed_check_enabled()

public function is_speed_check_enabled( $form )

Determines if the submission speed check is enabled.

Parameters

NameTypeDefaultDescription
$formarrayThe form being processed.

Returns

  • bool

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:502

get_submission_speed_threshold()

public function get_submission_speed_threshold( $form )

Returns the submission speed threshold.

Parameters

NameTypeDefaultDescription
$formarrayThe form being processed.

Returns

  • int

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:515

is_strict_submission_speed_mode_enabled()

public function is_strict_submission_speed_mode_enabled( $form )

Determines if strict mode is enabled for the submission speed check.

Parameters

NameTypeDefaultDescription
$formarrayThe form being processed.

Returns

  • bool

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:528

is_valid_submission_speed()

public function is_valid_submission_speed( $form )

Determines if the submission speed check is valid.

Parameters

NameTypeDefaultDescription
$formarrayThe current form object.

Returns

  • array

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:541

format_submission_speeds_for_note()

public function format_submission_speeds_for_note( $speeds )

Formats the submission speeds for the entry note.

Parameters

NameTypeDefaultDescription
$speedsarrayThe recorded speeds.

Returns

  • string

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:589

check_submission_speeds()

public function check_submission_speeds( $speeds, $threshold )

Checks the submission speeds against the threshold.

Parameters

NameTypeDefaultDescription
$speedsarrayThe recorded speeds.
$thresholdintThe submission speed threshold.

Returns

  • array

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:614

get_submission_speeds_array()

public function get_submission_speeds_array( $form_id )

Parses and sanitizes the submission speeds from the gform_submit_speeds input for the current form.

Parameters

NameTypeDefaultDescription
$form_idintThe current form ID.

Returns

  • array

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:642

get_submission_speeds_json()

public function get_submission_speeds_json( $form_id )

JSON encodes the submission speeds for the current form markup.

Parameters

NameTypeDefaultDescription
$form_idintThe current form ID.

Returns

  • false | string

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:679

submission_speeds_entry_meta()

public function submission_speeds_entry_meta( $entry_meta )

Registers and saves the submission speeds to the entry meta, so the user can display it as an entries list column.

Callback for the gform_entry_meta filter added via GF_Honeypot_Service_Provider::init().

Parameters

NameTypeDefaultDescription
$entry_metaarrayThe registered entry meta.

Returns

  • array

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:694

submission_speeds_entries_field_value()

public function submission_speeds_entries_field_value( $value, $form_id, $field_id, $entry )

Formats the value for display in an entries list column.

Callback for the gform_entries_field_value filter added via GF_Honeypot_Service_Provider::init().

Parameters

NameTypeDefaultDescription
$valuemixed | stringThe escaped value of the field, entry property, or meta-key.
$form_idintThe ID of the current form.
$field_idint | stringThe field ID entry property, or meta-key.
$entryarrayThe current entry.

Returns

  • mixed | string

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:731

submission_speeds_entry_detail_meta_box()

public function submission_speeds_entry_detail_meta_box( $meta_boxes, $entry )

Displays the submission speeds on the entry detail page.

Callback for the gform_entry_detail_meta_boxes filter added via GF_Honeypot_Service_Provider::init().

Parameters

NameTypeDefaultDescription
$meta_boxesarrayThe registered meta boxes.
$entryarrayThe current entry.

Returns

  • array

Since: 2.9.21

Source: includes/honeypot/class-gf-honeypot-handler.php:785

cache_invalid_state_counts()

public function cache_invalid_state_counts( $validation_result )

Caches the invalid state counts for the current form.

Callback for the gform_validation filter added via GF_Honeypot_Service_Provider::init().

Parameters

NameTypeDefaultDescription
$validation_resultarrayThe validation result.

Returns

  • array

Since: 3.0

Source: includes/honeypot/class-gf-honeypot-handler.php:813