-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from gravityview/develop
Merge Version 1.2
- Loading branch information
Showing
3 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
if ( ! class_exists( 'GFForms' ) || ! is_callable( array( 'GFForms', 'include_addon_framework' ) ) ) { | ||
return; | ||
} | ||
|
||
GFForms::include_addon_framework(); | ||
|
||
/** | ||
* @since 1.2 | ||
*/ | ||
class GF_Zero_Spam_AddOn extends GFAddOn { | ||
|
||
public function init() { | ||
parent::init(); | ||
|
||
add_filter( 'gform_form_settings_fields', array( $this, 'add_settings_field' ), 10, 2 ); | ||
add_filter( 'gform_tooltips', array( $this, 'add_tooltip' ) ); | ||
|
||
// Adding at 20 priority so anyone filtering the default priority (10) will define the default, but the | ||
// per-form setting may still _override_ the default. | ||
add_filter( 'gf_zero_spam_check_key_field', array( $this, 'filter_gf_zero_spam_check_key_field' ), 20, 2 ); | ||
} | ||
|
||
/** | ||
* Use per-form settings to determine whether to check for spam. | ||
* | ||
* @param bool $check_key_field | ||
* @param array $form | ||
* | ||
* @return array|mixed | ||
*/ | ||
public function filter_gf_zero_spam_check_key_field( $check_key_field = true, $form = array() ) { | ||
|
||
// The setting has been set, but it's not enabled. | ||
if ( isset( $form['enableGFZeroSpam'] ) && empty( $form['enableGFZeroSpam'] ) ) { | ||
return false; | ||
} | ||
|
||
return $check_key_field; | ||
} | ||
|
||
/** | ||
* Include custom tooltip text for the Zero Spam setting in the Form Settings page | ||
* | ||
* @param array $tooltips Key/Value pair of tooltip/tooltip text | ||
* | ||
* @return array | ||
*/ | ||
public function add_tooltip( $tooltips ) { | ||
|
||
$tooltips['enableGFZeroSpam'] = esc_html__( 'Enable to fight spam using a simple, effective method that is more effective than the built-in anti-spam honeypot.', 'gf-zero-spam' ); | ||
|
||
return $tooltips; | ||
} | ||
|
||
/** | ||
* Adds the Zero Spam field to the "Form Options" settings group in GF 2.5+ | ||
* | ||
* @see https://docs.gravityforms.com/gform_form_settings_fields/ | ||
* | ||
* @param array $fields Form Settings fields. | ||
* @param array $form The current form | ||
* | ||
* @return array | ||
*/ | ||
function add_settings_field( $fields, $form = array() ) { | ||
|
||
$fields['form_options']['fields'][] = array( | ||
'name' => 'enableGFZeroSpam', | ||
'type' => 'toggle', | ||
'label' => esc_html__( 'Prevent spam using Gravity Forms Zero Spam', 'gf-zero-spam' ), | ||
'tooltip' => gform_tooltip( 'enableGFZeroSpam', '', true ), | ||
'default_value' => apply_filters( 'gf_zero_spam_check_key_field', true, $form ), | ||
); | ||
|
||
return $fields; | ||
} | ||
} | ||
|
||
new GF_Zero_Spam_AddOn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters