Skip to content

Commit

Permalink
Merge pull request #11 from gravityview/develop
Browse files Browse the repository at this point in the history
Merge Version 1.2
  • Loading branch information
zackkatz authored Feb 16, 2022
2 parents d1094da + c510843 commit d75d2a0
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 8 deletions.
81 changes: 81 additions & 0 deletions gravityforms-zero-spam-form-settings.php
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();
20 changes: 19 additions & 1 deletion gravityforms-zero-spam.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Gravity Forms Zero Spam
* Plugin URI: https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=pluginuri
* Description: Enhance Gravity Forms to include effective anti-spam measures—without using a CAPTCHA.
* Version: 1.1.3
* Version: 1.2
* Author: GravityView
* Author URI: https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=authoruri
* License: GPL-2.0+
Expand All @@ -27,6 +27,9 @@ class GF_Zero_Spam {
* Instantiate the plugin on Gravity Forms loading
*/
public static function gform_loaded() {

include_once plugin_dir_path( __FILE__ ) . 'gravityforms-zero-spam-form-settings.php';

new self;
}

Expand Down Expand Up @@ -97,6 +100,21 @@ public function add_key_field( $form ) {
*/
public function check_key_field( $is_spam = false, $form = array(), $entry = array() ) {

/**
* Modify whether to process this entry submission for spam.
*
* @since 1.2
*
* @param bool $should_check_key_field Whether the Zero Spam plugin should check for the existence and validity of the key field. Default: true.
* @param array $form The form currently being processed.
* @param array $entry The entry currently being processed.
*/
$should_check_key_field = gf_apply_filters( 'gf_zero_spam_check_key_field', rgar( $form, 'id' ), true, $form, $entry );

if( false === $should_check_key_field ) {
return $is_spam;
}

// This was not submitted using a web form; created using API
if ( ! did_action( 'gform_pre_submission' ) ) {
return $is_spam;
Expand Down
62 changes: 55 additions & 7 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
=== Gravity Forms Zero Spam ===
Contributors: gravityview, karpstrucking, supporthero
Tags: gravityforms, gravity forms, anti-spam, antispam, spam, spam-blocker, spambot, spammer, addons, add-ons
Contributors: gravityview
Tags: gravityforms, gravity forms, anti-spam, antispam, spam, spam-blocker, spambot, spammer, add-ons, honeypot
Requires at least: 3.0.1
Tested up to: 5.8
Tested up to: 5.8.2
Stable tag: trunk
Requires PHP: 5.2.6
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Donate link: https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=donate

Enhance your Gravity Forms to include anti-spam measures originally based on the work of David Walsh's "Zero Spam" technique.

== Description ==

This Gravity Forms add-on blocks spam using a non-obtrusive anti-spam measure. There are no settings or configuration needed: all you need to do is activate the plugin!

### Is the Gravity Forms honeypot field not working for you? 🍯 🐝

Zero Spam is better than the Gravity Forms anti-spam honeypot field. If you're getting spammed, try this plugin.

### Use instead of reCaptcha

**reCaptcha is user-hostile!** Use this instead! Users don't need to click stoplights, crosswalks, or bicycles when you use this plugin to stop spam.

### Enable or disable per-form

If you only want the plugin for specific forms, that's possible! The plugin adds a simple "Prevent spam using Gravity Forms Zero Spam" setting to each form (requires Gravity Forms 2.5 or newer).

Requires [Gravity Forms](https://www.gravityforms.com/?partner_id=1210629&irgwc=1&utm_medium=affiliate&utm_campaign=1210629&utm_source=Katz%20Web%20Services%2C%20Inc.).

_Brought to you by [GravityView](https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=readme). We create essential Gravity Forms Add-Ons._

== Frequently Asked Questions ==

= Is this plugin PHP 7 and PHP 8 compatible? =
= Does the Gravity Forms Zero Spam plugin stop email notifications from being emailed when a message is considered spam? =

Yes.
Yes! When this plugin marks an entry as spam, it prevents processing of any configured notifications and add-on feeds.

Note: When an entry is marked as Spam, it also prevents use of the configured confirmation. Users submitted a entry marked as Spam will see the default Gravity Forms “Thanks for contacting us! We will get in touch with you shortly.” confirmation text instead.

= Does this plugin work in combination with other CAPTCHAs or spam blocker plugins? =
= Does this plugin work in combination with other CAPTCHAs, honeypot fields, or spam blocker plugins? =

Yep, you can use this plugin in combination with all other spam-blocking plugins:

Expand All @@ -39,7 +52,7 @@ Yep, you can use this plugin in combination with all other spam-blocking plugins
- WP Armor
- fail2ban

Zero Spam will not interfere with the operation of those plugins.
Zero Spam will not interfere with the operation of those plugins. It also doesn't interfere with Gravity Forms' built-in honeypot functionality.

= What version of Gravity Forms does this work with? =

Expand All @@ -49,12 +62,47 @@ This works with all Gravity Forms releases after v2.3 (released June 2017). The

No. For that, we recommend Ben Marshall‘s [WordPress Zero Spam plugin](https://wordpress.org/plugins/zero-spam/).

= How do I disable Zero Spam on specific forms? =

1. Go to the form
2. Click on Settings
3. Under Form Options, disable "Prevent spam using Gravity Forms Zero Spam". _Don't see the setting? This feature requires Gravity Forms 2.5 or newer._
4. Save the settings

New form submissions will not be checked using Zero Spam.

= I only want on sepecific forms. How do I disable Zero Spam by default? =

To disable by default, add this code to your site ([here's how](https://docs.gravityview.co/article/210-where-to-put-code-samples):

```
add_filter( 'gf_zero_spam_check_key_field', '__return_false' );
```

Once you have added that code:

1. Go to the form
2. Click on Settings
3. Under Form Options, enable "Prevent spam using Gravity Forms Zero Spam". _Don't see the setting? This feature requires Gravity Forms 2.5 or newer._
4. Save the settings

Now that form will use Zero Spam.

= Is this plugin PHP 7 and PHP 8 compatible? =

Yes.

= All entries are going to spam. What can I do? =

First, **de-activate and re-activate the plugin**. Then let us know on the support tab!


== Changelog ==

= 1.2 on December 10, 2021 =

* New! Added a per-form setting "Prevent spam using Gravity Forms Zero Spam" that enables or disables Gravity Forms Zero Spam from processing! [Check out the FAQ to learn how to use this setting](https://wordpress.org/plugins/gravity-forms-zero-spam/#faq-header). Note: this feature requires Gravity Forms 2.5 or newer.

= 1.1.3 on August 9, 2021 =

* Enhancement: Adds an entry note when an entry is marked as spam. Thanks to Gravity Forms for the enhancement!
Expand Down

0 comments on commit d75d2a0

Please sign in to comment.