Version Description
on March 11, 2021 =
- Improved: No longer requires jQuery
- Fixed: Only checks for spam on submissions that were submitted by a form, not for entries created programatically
Download this release
Release Info
Developer | gravityview |
Plugin | Gravity Forms Zero Spam |
Version | 1.0.6 |
Comparing to | |
See all releases |
Code changes from version 1.0.4 to 1.0.6
- gravityforms-zero-spam.php +99 -47
- readme.txt +24 -4
gravityforms-zero-spam.php
CHANGED
@@ -1,67 +1,119 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
* Plugin Name: Gravity Forms Zero Spam
|
5 |
-
* Plugin URI:
|
6 |
-
* Description: Enhance
|
7 |
-
* Version: 1.0.
|
8 |
-
* Author:
|
9 |
-
* Author URI: https://
|
10 |
* License: GPL-2.0+
|
11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
12 |
*/
|
13 |
|
14 |
// my mother always said to use things as they're intended or not at all
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
|
|
|
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
public function deactivate() { // plugin deactivation
|
32 |
-
delete_option( 'gf_zero_spam_key' ); // remove the key
|
33 |
}
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
var gforms = '.gform_wrapper form';
|
46 |
-
$( document ).on( 'submit', gforms ,function() {
|
47 |
-
$('<input>').attr( 'type', 'hidden' )
|
48 |
-
.attr( 'name', 'gf_zero_spam_key' )
|
49 |
-
.attr( 'value', '<?php echo $this->get_key(); ?>' )
|
50 |
-
.appendTo( gforms );
|
51 |
-
return true;
|
52 |
-
});
|
53 |
-
});
|
54 |
-
</script>
|
55 |
-
<?php
|
56 |
}
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
}
|
61 |
-
return false;
|
62 |
}
|
63 |
-
}
|
64 |
|
65 |
-
|
|
|
|
|
66 |
|
67 |
-
|
|
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Plugin Name: Gravity Forms Zero Spam
|
4 |
+
* Plugin URI: https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=pluginuri
|
5 |
+
* Description: Enhance Gravity Forms to include effective anti-spam measures—without using a CAPTCHA.
|
6 |
+
* Version: 1.0.6
|
7 |
+
* Author: GravityView
|
8 |
+
* Author URI: https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=authoruri
|
9 |
* License: GPL-2.0+
|
10 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
11 |
*/
|
12 |
|
13 |
// my mother always said to use things as they're intended or not at all
|
14 |
+
if ( ! defined( 'WPINC' ) ) {
|
15 |
+
die;
|
16 |
+
}
|
17 |
+
|
18 |
+
// clean up after ourselves
|
19 |
+
register_deactivation_hook( __FILE__, array( 'GF_Zero_Spam', 'deactivate' ) );
|
20 |
|
21 |
+
// Fire it up
|
22 |
+
add_action( 'gform_loaded', array( 'GF_Zero_Spam', 'gform_loaded' ) );
|
23 |
+
|
24 |
+
class GF_Zero_Spam {
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Instantiate the plugin on Gravity Forms loading
|
28 |
+
*/
|
29 |
+
public static function gform_loaded() {
|
30 |
+
new self;
|
31 |
}
|
32 |
|
33 |
+
/**
|
34 |
+
* Cleans up plugin options when deactivating.
|
35 |
+
*
|
36 |
+
* @return void
|
37 |
+
*/
|
38 |
+
public static function deactivate() {
|
39 |
+
delete_option( 'gf_zero_spam_key' );
|
40 |
+
}
|
41 |
|
42 |
+
public function __construct() {
|
43 |
+
add_action( 'wp_print_footer_scripts', array( $this, 'add_key_field' ), 9999 );
|
44 |
+
add_filter( 'gform_entry_is_spam', array( $this, 'check_key_field' ), 10, 3 );
|
45 |
+
}
|
46 |
|
47 |
+
/**
|
48 |
+
* Retrieves the zero spam key (generating if needed)
|
49 |
+
*
|
50 |
+
* @return false|mixed|void
|
51 |
+
*/
|
52 |
+
public function get_key() {
|
53 |
|
54 |
+
$key = get_option( 'gf_zero_spam_key' );
|
55 |
+
|
56 |
+
if ( ! $key ) {
|
57 |
+
$key = wp_generate_password( 64, false, false );
|
58 |
+
update_option( 'gf_zero_spam_key', $key, false );
|
|
|
|
|
59 |
}
|
60 |
+
|
61 |
+
return $key;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Adds inject the hidden field and key into the form at submission
|
66 |
+
*
|
67 |
+
* @return void
|
68 |
+
*/
|
69 |
+
public function add_key_field() {
|
70 |
+
?>
|
71 |
+
<script type='text/javascript'>
|
72 |
+
document.addEventListener("DOMContentLoaded", function() {
|
73 |
+
var gforms = '.gform_wrapper form';
|
74 |
+
|
75 |
+
document.querySelector( gforms ).addEventListener( "submit", function ( e ) {
|
76 |
+
var input = document.createElement( "input" );
|
77 |
+
input.type = 'hidden';
|
78 |
+
input.name = 'gf_zero_spam_key';
|
79 |
+
input.value = '<?php echo esc_js( $this->get_key() ); ?>';
|
80 |
+
|
81 |
+
e.target.appendChild( input );
|
82 |
+
} );
|
83 |
+
});
|
84 |
+
</script>
|
85 |
+
<?php
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Checks for our zero spam key during validation
|
90 |
+
*
|
91 |
+
* @param bool $is_spam Indicates if the submission has been flagged as spam.
|
92 |
+
* @param array $form The form currently being processed.
|
93 |
+
* @param array $entry The entry currently being processed.
|
94 |
+
*
|
95 |
+
* @return bool True: it's spam; False: it's not spam!
|
96 |
+
*/
|
97 |
+
public function check_key_field( $is_spam = false, $form = array(), $entry = array() ) {
|
98 |
+
|
99 |
+
// This was not submitted using a web form; created using API
|
100 |
+
if ( ! did_action( 'gform_pre_submission' ) ) {
|
101 |
+
return $is_spam;
|
102 |
}
|
103 |
+
|
104 |
+
// Created using REST API or GFAPI
|
105 |
+
if ( isset( $entry['user_agent'] ) && 'API' === $entry['user_agent'] ) {
|
106 |
+
return $is_spam;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
}
|
108 |
+
|
109 |
+
if ( ! isset( $_POST['gf_zero_spam_key'] ) ) {
|
110 |
+
return true;
|
|
|
|
|
111 |
}
|
|
|
112 |
|
113 |
+
if ( $_POST['gf_zero_spam_key'] !== $this->get_key() ) {
|
114 |
+
return true;
|
115 |
+
}
|
116 |
|
117 |
+
return $is_spam;
|
118 |
+
}
|
119 |
+
}
|
readme.txt
CHANGED
@@ -1,22 +1,27 @@
|
|
1 |
=== Gravity Forms Zero Spam ===
|
2 |
-
Contributors: karpstrucking, supporthero
|
3 |
Tags: gravityforms, gravity forms, anti-spam, antispam, spam, spam-blocker, spambot, spammer, addons, add-ons
|
4 |
Requires at least: 3.0.1
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag:
|
|
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
10 |
Enhance your Gravity Forms to include anti-spam measures originally based on the work of David Walsh's "Zero Spam" technique.
|
11 |
|
12 |
== Description ==
|
|
|
13 |
This plugin adds a non-obtrusive anti-spam measure to all of your Gravity Forms. This measure is originally based on David Walsh's "Zero Spam" technique.
|
14 |
|
|
|
|
|
15 |
Requires: Gravity Forms v1.5+
|
16 |
|
17 |
== Frequently Asked Questions ==
|
|
|
18 |
= Is this plugin PHP7 compatible? =
|
19 |
-
|
20 |
Yes.
|
21 |
|
22 |
= Will this block spam comments or registrations on my site? =
|
@@ -24,6 +29,21 @@ Yes.
|
|
24 |
No. For that, we recommend Ben Marshall‘s [WordPress Zero Spam plugin](https://wordpress.org/plugins/zero-spam/).
|
25 |
|
26 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
= 1.0.4 =
|
28 |
* Should fix 'jQuery undefined' errors
|
29 |
|
1 |
=== Gravity Forms Zero Spam ===
|
2 |
+
Contributors: gravityview, karpstrucking, supporthero
|
3 |
Tags: gravityforms, gravity forms, anti-spam, antispam, spam, spam-blocker, spambot, spammer, addons, add-ons
|
4 |
Requires at least: 3.0.1
|
5 |
+
Tested up to: 5.6.1
|
6 |
+
Stable tag: trunk
|
7 |
+
Requires PHP: 5.2.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
Enhance your Gravity Forms to include anti-spam measures originally based on the work of David Walsh's "Zero Spam" technique.
|
12 |
|
13 |
== Description ==
|
14 |
+
|
15 |
This plugin adds a non-obtrusive anti-spam measure to all of your Gravity Forms. This measure is originally based on David Walsh's "Zero Spam" technique.
|
16 |
|
17 |
+
There are no settings or configuration needed: all you need to do is activate the plugin!
|
18 |
+
|
19 |
Requires: Gravity Forms v1.5+
|
20 |
|
21 |
== Frequently Asked Questions ==
|
22 |
+
|
23 |
= Is this plugin PHP7 compatible? =
|
24 |
+
|
25 |
Yes.
|
26 |
|
27 |
= Will this block spam comments or registrations on my site? =
|
29 |
No. For that, we recommend Ben Marshall‘s [WordPress Zero Spam plugin](https://wordpress.org/plugins/zero-spam/).
|
30 |
|
31 |
== Changelog ==
|
32 |
+
|
33 |
+
= 1.0.6 on March 11, 2021 =
|
34 |
+
|
35 |
+
* Improved: No longer requires jQuery
|
36 |
+
* Fixed: Only checks for spam on submissions that were submitted by a form, not for entries created programatically
|
37 |
+
|
38 |
+
= 1.0.5 on February 16, 2021 =
|
39 |
+
|
40 |
+
The Gravity Forms Zero Spam plugin is now maintained by [GravityView](https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=changelog). We look forward to continuing to improve this simple, effective spam blocker for Gravity Forms. Thanks to GoWP for their great work!
|
41 |
+
|
42 |
+
* Improved: Only add anti-spam JavaScript when the Gravity Forms plugin is active
|
43 |
+
* Fixed: Sanitized key, in case there were any unsafe characters generated by overriding the `random_password` filter.
|
44 |
+
* Fixed: Made `GF_Zero_Spam::deactivate` a static method
|
45 |
+
* Updated: Now using the `wp_print_footer_scripts` action to add the script (was `wp_footer`)
|
46 |
+
|
47 |
= 1.0.4 =
|
48 |
* Should fix 'jQuery undefined' errors
|
49 |
|