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
| Method | Description |
|---|---|
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. |
field_validation_detect_urls() | gform_field_validation callback; Checks the value for links/URL and sets the field is_value_spam context property and validation result. |
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
| Name | Type | Default | Description |
|---|---|---|---|
$is_spam | bool | Variable being filtered. True for spam, false for non-spam. | |
$form | array | Current form object. |
Returns
bool— Returns true if honeypot validation fails. False otherwise.
Since:
2.72.9.21(Updated to get the entry note message fromget_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
| Name | Type | Default | Description |
|---|---|---|---|
$do_abort | bool | Variable being filtered. True to abort submission, false to continue. | |
$form | array | Current form object. |
Returns
bool— Returns true to abort form submission early and display confirmation. Returns false to let submission continue.
Since:
2.72.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
| Name | Type | Default | Description |
|---|---|---|---|
$entry | array | Current entry object. | |
$form | array | Current form object. |
Since:
2.73.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
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | Current 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
| Name | Type | Default | Description |
|---|---|---|---|
$form_id | int | The 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
| Name | Type | Default | Description |
|---|---|---|---|
$form_id | int | The current form ID. | |
$result | array | The 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
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The 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.72.9.16(Updated to useget_input_name().)2.9.21(Updated to perform a submission speed check, return early on invalid checks, and to useget_cached_result()andcache_result().)3.0(Updated to include state validation.)
Source: includes/honeypot/class-gf-honeypot-handler.php:176
field_validation_detect_urls()
public function field_validation_detect_urls( $result, $value, $form, $field )
gform_field_validation callback; Checks the value for links/URL and sets the field is_value_spam context property and validation result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$result | array | The field validation result. | |
$value | string | The field value to be checked. | |
$form | array | The current Form object. | |
$field | \GF_Field | The current Field object. |
Returns
array
Since: 3.1.0
Source: includes/honeypot/class-gf-honeypot-handler.php:275
get_honeypot_field_id()
public function get_honeypot_field_id( $form )
Returns the ID of the honeypot field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | Current form object. |
Returns
int— Returns the id of the honeypot field.
Since: 2.7
Source: includes/honeypot/class-gf-honeypot-handler.php:470
get_input_name()
public function get_input_name( $form, $id=null )
Returns the value used in the name attribute of the honeypot input.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The form being rendered or validated. | |
$id | null | int | null | The 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:497
get_honeypot_field()
public function get_honeypot_field( $form )
Creates the honeypot field object for the given form.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The 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:524
is_valid_version_hash()
public function is_valid_version_hash( $hash )
Validates a version hash.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$hash | string | The 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:580
is_honeypot_enabled()
public function is_honeypot_enabled( $form )
Determines if Honeypot should be enabled for this form submission.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The current form object. |
Returns
bool— True if honeypot should be enabled. False otherwise.
Since: 2.7
Source: includes/honeypot/class-gf-honeypot-handler.php:605
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:624
is_speed_check_enabled()
public function is_speed_check_enabled( $form )
Determines if the submission speed check is enabled.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The form being processed. |
Returns
bool
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:637
get_submission_speed_threshold()
public function get_submission_speed_threshold( $form )
Returns the submission speed threshold.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The form being processed. |
Returns
int
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:650
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
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The form being processed. |
Returns
bool
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:663
is_valid_submission_speed()
public function is_valid_submission_speed( $form )
Determines if the submission speed check is valid.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The current form object. |
Returns
array
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:676
format_submission_speeds_for_note()
public function format_submission_speeds_for_note( $speeds )
Formats the submission speeds for the entry note.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$speeds | array | The recorded speeds. |
Returns
string
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:731
check_submission_speeds()
public function check_submission_speeds( $speeds, $threshold )
Checks the submission speeds against the threshold.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$speeds | array | The recorded speeds. | |
$threshold | int | The submission speed threshold. |
Returns
array
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:756
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
| Name | Type | Default | Description |
|---|---|---|---|
$form_id | int | The current form ID. |
Returns
array
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:784
get_submission_speeds_json()
public function get_submission_speeds_json( $form_id )
JSON encodes the submission speeds for the current form markup.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form_id | int | The current form ID. |
Returns
false|string
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:821
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
| Name | Type | Default | Description |
|---|---|---|---|
$entry_meta | array | The registered entry meta. |
Returns
array
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:836
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
| Name | Type | Default | Description |
|---|---|---|---|
$value | mixed | string | The escaped value of the field, entry property, or meta-key. | |
$form_id | int | The ID of the current form. | |
$field_id | int | string | The field ID entry property, or meta-key. | |
$entry | array | The current entry. |
Returns
mixed|string
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:873
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
| Name | Type | Default | Description |
|---|---|---|---|
$meta_boxes | array | The registered meta boxes. | |
$entry | array | The current entry. |
Returns
array
Since: 2.9.21
Source: includes/honeypot/class-gf-honeypot-handler.php:927
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
| Name | Type | Default | Description |
|---|---|---|---|
$validation_result | array | The validation result. |
Returns
array
Since: 3.0
Source: includes/honeypot/class-gf-honeypot-handler.php:955