WordPress Zero Spam - Version 4.3.7

Version Description

  • Optimized scripts & when they get loaded (only when needed)
  • Fixed bug with incrementing spam detections in the blocked IPs log
Download this release

Release Info

Developer bmarshall511
Plugin Icon 128x128 WordPress Zero Spam
Version 4.3.7
Comparing to
See all releases

Code changes from version 4.3.6 to 4.3.7

addons/comments.php CHANGED
@@ -3,7 +3,7 @@
3
  * Handles checking submitted comments for spam
4
  *
5
  * @package WordPressZeroSpam
6
- * @since 4.0.0
7
  */
8
 
9
  /**
@@ -29,3 +29,26 @@ if ( ! function_exists( 'wpzerospam_preprocess_comment' ) ) {
29
  }
30
  }
31
  add_action( 'preprocess_comment', 'wpzerospam_preprocess_comment' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Handles checking submitted comments for spam
4
  *
5
  * @package WordPressZeroSpam
6
+ * @since 4.3.7
7
  */
8
 
9
  /**
29
  }
30
  }
31
  add_action( 'preprocess_comment', 'wpzerospam_preprocess_comment' );
32
+
33
+ /**
34
+ * Enqueue the comment form JS
35
+ */
36
+ if ( ! function_exists( 'wpzerospam_comment_form' ) ) {
37
+ function wpzerospam_comment_form() {
38
+ $options = wpzerospam_options();
39
+
40
+ // Make sure comment spam detection is enabled before loading
41
+ if ( 'enabled' == $options['verify_comments'] ) {
42
+ // WordPress Zero Spam comment addon
43
+ wp_enqueue_script(
44
+ 'wpzerospam-addon-comments',
45
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
46
+ '/assets/js/addons/wpzerospam-addon-comments.js',
47
+ [ 'wpzerospam' ],
48
+ $plugin['Version'],
49
+ true
50
+ );
51
+ }
52
+ }
53
+ }
54
+ add_action( 'comment_form', 'wpzerospam_comment_form' );
addons/contact-form-7.php CHANGED
@@ -3,7 +3,7 @@
3
  * Handles checking submitted Contact Form 7 forms for spam
4
  *
5
  * @package WordPressZeroSpam
6
- * @since 4.1.0
7
  */
8
 
9
  /**
@@ -27,3 +27,26 @@ if ( ! function_exists( 'wpzerospam_wpcf7_validate' ) ) {
27
  }
28
  }
29
  add_action( 'wpcf7_validate', 'wpzerospam_wpcf7_validate' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Handles checking submitted Contact Form 7 forms for spam
4
  *
5
  * @package WordPressZeroSpam
6
+ * @since 4.3.7
7
  */
8
 
9
  /**
27
  }
28
  }
29
  add_action( 'wpcf7_validate', 'wpzerospam_wpcf7_validate' );
30
+
31
+ /**
32
+ * Enqueue the CF7 form JS
33
+ */
34
+ if ( ! function_exists( 'wpzerospam_cf7' ) ) {
35
+ function wpzerospam_cf7() {
36
+ $options = wpzerospam_options();
37
+
38
+ // Make sure registration spam detection is enabled before loading
39
+ if ( 'enabled' == $options['verify_cf7'] ) {
40
+ // WordPress Zero Spam registration addon
41
+ wp_enqueue_script(
42
+ 'wpzerospam-addon-cf7',
43
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
44
+ '/assets/js/addons/wpzerospam-addon-cf7.js',
45
+ [ 'wpzerospam' ],
46
+ $plugin['Version'],
47
+ true
48
+ );
49
+ }
50
+ }
51
+ }
52
+ add_action( 'wpcf7_enqueue_scripts', 'wpzerospam_cf7' );
addons/ninja-forms.php CHANGED
@@ -3,27 +3,93 @@
3
  * Handles checking submitted Ninja Forms for spam
4
  *
5
  * @package WordPressZeroSpam
6
- * @since 4.1.0
7
  */
8
 
9
  /**
10
  * Validation for Ninja Forms submissions
11
  */
12
  if ( ! function_exists( 'wpzerospam_ninja_forms_validate' ) ) {
13
- function wpzerospam_ninja_forms_validate() {
14
  $options = wpzerospam_options();
15
-
16
  if (
17
  'enabled' != $options['verify_ninja_forms'] ||
18
- is_user_logged_in() ||
19
- wpzerospam_key_check()
20
  ) {
21
- return;
22
  }
23
 
24
- do_action( 'wpzerospam_ninja_forms_spam' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- wpzerospam_spam_detected( 'ninja_forms' );
27
  }
28
  }
29
- add_action( 'ninja_forms_process', 'wpzerospam_ninja_forms_validate' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Handles checking submitted Ninja Forms for spam
4
  *
5
  * @package WordPressZeroSpam
6
+ * @since 4.3.7
7
  */
8
 
9
  /**
10
  * Validation for Ninja Forms submissions
11
  */
12
  if ( ! function_exists( 'wpzerospam_ninja_forms_validate' ) ) {
13
+ function wpzerospam_ninja_forms_validate( $form_data ) {
14
  $options = wpzerospam_options();
 
15
  if (
16
  'enabled' != $options['verify_ninja_forms'] ||
17
+ is_user_logged_in()
 
18
  ) {
19
+ return $form_data;
20
  }
21
 
22
+ if (
23
+ empty( $form_data['extra'] ) ||
24
+ empty( $form_data['extra']['wpzerospam_key'] ) ||
25
+ wpzerospam_get_key() != $form_data['extra']['wpzerospam_key']
26
+ ) {
27
+ do_action( 'wpzerospam_ninja_forms_spam' );
28
+
29
+ wpzerospam_spam_detected( 'ninja_forms', $form_data, false );
30
+
31
+ $errors = [
32
+ 'form' => [
33
+ 'wpzerospam' => $options['blocked_message'],
34
+ ]
35
+ ];
36
+
37
+ $response = [
38
+ 'errors' => $errors,
39
+ ];
40
+ // @TODO - Find a way to display the error message to the user
41
+ echo wp_json_encode( $response );
42
+ wp_die();
43
+ }
44
 
45
+ return $form_data;
46
  }
47
  }
48
+ add_filter( 'ninja_forms_submit_data', 'wpzerospam_ninja_forms_validate' );
49
+
50
+ if( ! class_exists( 'WordPressZeroSpam_NF_ExtraData' ) ) {
51
+ class WordPressZeroSpam_NF_ExtraData {
52
+ // Stores the form IDs we want to modify
53
+ var $form_ids = [];
54
+ var $script_added = false;
55
+
56
+ public function __construct() {
57
+ $options = wpzerospam_options();
58
+
59
+ if ( 'enabled' == $options['verify_ninja_forms'] ) {
60
+ add_action('ninja_forms_before_form_display', [ $this, 'addHooks' ]);
61
+ }
62
+ }
63
+
64
+ public function addHooks( $form_id ) {
65
+ $this->form_ids[] = $form_id;
66
+
67
+ //Make sure we only add the script once
68
+ if( ! $this->script_added ) {
69
+ add_action( 'wp_footer', [ $this, 'add_extra_to_form' ], 99 );
70
+ $this->script_added = true;
71
+ }
72
+ }
73
+
74
+ public function add_extra_to_form() {
75
+ ?>
76
+ <script>
77
+ (function() {
78
+ var form_ids = [ <?php echo join( ", ", $this->form_ids ); ?> ];
79
+ nfRadio.channel( "forms" ).on( "before:submit", function( e ) {
80
+ if( form_ids.indexOf( +e.id ) === -1 ) return;
81
+
82
+ var extra = e.get( 'extra' );
83
+
84
+ extra.wpzerospam_key = '<?php echo wpzerospam_get_key(); ?>';
85
+
86
+ e.set('extra', extra);
87
+ });
88
+ })();
89
+ </script>
90
+ <?php
91
+ }
92
+ }
93
+ }
94
+
95
+ new WordPressZeroSpam_NF_ExtraData();
addons/registration.php CHANGED
@@ -3,7 +3,7 @@
3
  * Handles checking registration submissions for spam
4
  *
5
  * @package WordPressZeroSpam
6
- * @since 4.0.0
7
  */
8
 
9
  /**
@@ -28,3 +28,26 @@ if ( ! function_exists( 'wpzerospam_preprocess_registration' ) ) {
28
  }
29
  }
30
  add_filter( 'registration_errors', 'wpzerospam_preprocess_registration', 10, 3 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Handles checking registration submissions for spam
4
  *
5
  * @package WordPressZeroSpam
6
+ * @since 4.3.7
7
  */
8
 
9
  /**
28
  }
29
  }
30
  add_filter( 'registration_errors', 'wpzerospam_preprocess_registration', 10, 3 );
31
+
32
+ /**
33
+ * Enqueue the registration form JS
34
+ */
35
+ if ( ! function_exists( 'wpzerospam_registration_form' ) ) {
36
+ function wpzerospam_registration_form() {
37
+ $options = wpzerospam_options();
38
+
39
+ // Make sure registration spam detection is enabled before loading
40
+ if ( 'enabled' == $options['verify_registrations'] ) {
41
+ // WordPress Zero Spam registration addon
42
+ wp_enqueue_script(
43
+ 'wpzerospam-addon-registrations',
44
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
45
+ '/assets/js/addons/wpzerospam-addon-registrations.js',
46
+ [ 'wpzerospam' ],
47
+ $plugin['Version'],
48
+ true
49
+ );
50
+ }
51
+ }
52
+ }
53
+ add_action( 'login_enqueue_scripts', 'wpzerospam_registration_form' );
assets/css/admin-blocked-ips.css ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wpzerospam-add-ip-container {
2
+ align-items: center;
3
+ display: flex;
4
+ flex-wrap: wrap;
5
+ margin-left: -10px;
6
+ margin-right: -10px;
7
+ }
8
+
9
+ .wpzerospam-add-ip-container h2,
10
+ .wpzerospam-add-ip-field,
11
+ .wpzerospam-add-ip-submit {
12
+ margin-left: 10px;
13
+ margin-right: 10px;
14
+ }
15
+
16
+ .wpzerospam-add-ip-container h2 {
17
+ margin-top: 0;
18
+ width: calc(100% - 20px);
19
+ }
20
+
21
+ .wpzerospam-add-ip-container label {
22
+ display: block;
23
+ font-weight: bold;
24
+ }
25
+
26
+ .wpzerospam-add-ip-field {
27
+ width: calc(100% / 5 - 20px);
28
+ }
29
+
30
+ .wpzerospam-add-ip-field input,
31
+ .wpzerospam-add-ip-field select {
32
+ width: 100%;
33
+ }
34
+
35
+ #wpzerospam-add-ip-field-reason {
36
+ flex-grow: 1;
37
+ }
assets/css/{admin.css → admin-dashboard.css} RENAMED
@@ -75,44 +75,6 @@
75
  display: block;
76
  }
77
 
78
- .wpzerospam-add-ip-container {
79
- align-items: center;
80
- display: flex;
81
- flex-wrap: wrap;
82
- margin-left: -10px;
83
- margin-right: -10px;
84
- }
85
-
86
- .wpzerospam-add-ip-container h2,
87
- .wpzerospam-add-ip-field,
88
- .wpzerospam-add-ip-submit {
89
- margin-left: 10px;
90
- margin-right: 10px;
91
- }
92
-
93
- .wpzerospam-add-ip-container h2 {
94
- margin-top: 0;
95
- width: calc(100% - 20px);
96
- }
97
-
98
- .wpzerospam-add-ip-container label {
99
- display: block;
100
- font-weight: bold;
101
- }
102
-
103
- .wpzerospam-add-ip-field {
104
- width: calc(100% / 5 - 20px);
105
- }
106
-
107
- .wpzerospam-add-ip-field input,
108
- .wpzerospam-add-ip-field select {
109
- width: 100%;
110
- }
111
-
112
- #wpzerospam-add-ip-field-reason {
113
- flex-grow: 1;
114
- }
115
-
116
  .wpzerospam-details-modal {
117
  background: rgba(0, 0, 0, 0.8);
118
  cursor: pointer;
@@ -197,11 +159,12 @@
197
  width: calc(100% / 3 - 18px);
198
  }
199
 
200
- .wpzerospam-box-line-chart {
201
- width: calc((100% / 3) * 2 - 18px);
202
- }
203
-
204
  .wpzerospam-box-countries-pie {
205
  width: calc(100% / 2 - 18px);
206
  }
 
 
 
 
207
  }
75
  display: block;
76
  }
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  .wpzerospam-details-modal {
79
  background: rgba(0, 0, 0, 0.8);
80
  cursor: pointer;
159
  width: calc(100% / 3 - 18px);
160
  }
161
 
162
+ .wpzerospam-box-line-chart,
 
 
 
163
  .wpzerospam-box-countries-pie {
164
  width: calc(100% / 2 - 18px);
165
  }
166
+
167
+ .wpzerospam-box-line-chart {
168
+ width: calc((100% / 3) * 2 - 18px);
169
+ }
170
  }
assets/js/addons/wpzerospam-addon-cf7.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * WordPress Zero Spam addon for handling core CF7 submissions.
3
+ */
4
+ WordPressZeroSpamAddons.cf7 = {
5
+ init: function() {
6
+ // Make sure the WordPress Zero Spam key is available.
7
+ if ( typeof wpzerospam.key == "undefined" ) { return; }
8
+
9
+ var $form = jQuery( '.wpcf7-form' );
10
+
11
+ // If the form can't be found & should be, send a message to the console.
12
+ if ( ! $form.length ) {
13
+ console.log(
14
+ 'WordPress Zero Spam was unable to locate the CF7 form (.wpcf7-form)'
15
+ );
16
+ return true;
17
+ }
18
+
19
+ // Triggered when the comment form is submitted
20
+ jQuery( ".wpcf7-submit", $form ).click( function() {
21
+ // Make sure the WordPress Zero Spam key isn't already on the form, if
22
+ // not, add it.
23
+ if ( ! jQuery( '[name="wpzerospam_key"]', $form ).length ) {
24
+ jQuery( "<input>" )
25
+ .attr( "type", "hidden" )
26
+ .attr( "name", "wpzerospam_key" )
27
+ .attr( "value", wpzerospam.key )
28
+ .appendTo( $form );
29
+ } else {
30
+ jQuery( '[name="wpzerospam_key"]', $form ).value( wpzerospam.key );
31
+ }
32
+
33
+ return true;
34
+ });
35
+ }
36
+ }
37
+
38
+ jQuery(function() {
39
+ WordPressZeroSpamAddons.cf7.init();
40
+ });
assets/js/addons/wpzerospam-addon-comments.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * WordPress Zero Spam addon for handling core comment submissions.
3
+ */
4
+ WordPressZeroSpamAddons.comments = {
5
+ init: function() {
6
+ // Make sure the WordPress Zero Spam key is available.
7
+ if ( typeof wpzerospam.key == "undefined" ) { return; }
8
+
9
+ var $form = jQuery( '#commentform' );
10
+
11
+ // If the form can't be found & should be, send a message to the console.
12
+ if ( ! $form.length ) {
13
+ console.log(
14
+ 'WordPress Zero Spam was unable to locate the comment form (#commentform)'
15
+ );
16
+ return true;
17
+ }
18
+
19
+ // Triggered when the comment form is submitted
20
+ $form.on( "submit", function() {
21
+ // Make sure the WordPress Zero Spam key isn't already on the form, if
22
+ // not, add it.
23
+ if ( ! jQuery( '[name="wpzerospam_key"]', jQuery( this ) ).length ) {
24
+ jQuery( "<input>" )
25
+ .attr( "type", "hidden" )
26
+ .attr( "name", "wpzerospam_key" )
27
+ .attr( "value", wpzerospam.key )
28
+ .appendTo( jQuery(this) );
29
+ } else {
30
+ jQuery( '[name="wpzerospam_key"]', jQuery( this ) ).value( wpzerospam.key );
31
+ }
32
+
33
+ return true;
34
+ });
35
+ }
36
+ }
37
+
38
+ jQuery(function() {
39
+ WordPressZeroSpamAddons.comments.init();
40
+ });
assets/js/addons/wpzerospam-addon-registrations.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * WordPress Zero Spam addon for handling core comment submissions.
3
+ */
4
+ WordPressZeroSpamAddons.registrations = {
5
+ init: function() {
6
+ // Make sure the WordPress Zero Spam key is available.
7
+ if ( typeof wpzerospam.key == "undefined" ) { return; }
8
+
9
+ var $form = jQuery( '#registerform' );
10
+
11
+ // If the form can't be found & should be, send a message to the console.
12
+ if ( ! $form.length ) {
13
+ console.log(
14
+ 'WordPress Zero Spam was unable to locate the registration form (#registerform)'
15
+ );
16
+ return true;
17
+ }
18
+
19
+ // Triggered when the comment form is submitted
20
+ $form.on( "submit", function() {
21
+ // Make sure the WordPress Zero Spam key isn't already on the form, if
22
+ // not, add it.
23
+ if ( ! jQuery( '[name="wpzerospam_key"]', jQuery( this ) ).length ) {
24
+ jQuery( "<input>" )
25
+ .attr( "type", "hidden" )
26
+ .attr( "name", "wpzerospam_key" )
27
+ .attr( "value", wpzerospam.key )
28
+ .appendTo( jQuery(this) );
29
+ } else {
30
+ jQuery( '[name="wpzerospam_key"]', jQuery( this ) ).value( wpzerospam.key );
31
+ }
32
+
33
+ return true;
34
+ });
35
+ }
36
+ }
37
+
38
+ jQuery(function() {
39
+ WordPressZeroSpamAddons.registrations.init();
40
+ });
assets/js/admin-blocked-ips.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($) {
2
+ $(function() {
3
+ var $addIPContainer = $(".wpzerospam-add-ip-container");
4
+
5
+ $("#blocked-type", $addIPContainer).change(function() {
6
+ if ( $(this).val() == 'permanent' ) {
7
+ $("#wpzerospam-add-ip-field-start-date").hide();
8
+ $("#wpzerospam-add-ip-field-end-date").hide();
9
+ } else {
10
+ $("#wpzerospam-add-ip-field-start-date").show();
11
+ $("#wpzerospam-add-ip-field-end-date").show();
12
+ }
13
+ });
14
+ });
15
+ })(jQuery);
assets/js/{admin.js → admin-dashboard.js} RENAMED
@@ -1,17 +1,8 @@
1
  (function($) {
2
  $(function() {
3
- var $addIPContainer = $(".wpzerospam-add-ip-container");
4
-
5
- $("#blocked-type", $addIPContainer).change(function() {
6
- if ( $(this).val() == 'permanent' ) {
7
- $("#wpzerospam-add-ip-field-start-date").hide();
8
- $("#wpzerospam-add-ip-field-end-date").hide();
9
- } else {
10
- $("#wpzerospam-add-ip-field-start-date").show();
11
- $("#wpzerospam-add-ip-field-end-date").show();
12
- }
13
- });
14
-
15
  var $detailsTrigger = $( '.wpzerospam-details-trigger' );
16
  $detailsTrigger.click(function( e ) {
17
  e.preventDefault();
1
  (function($) {
2
  $(function() {
3
+ /**
4
+ * Handles opening the 'View Details' modal on the spam log.
5
+ */
 
 
 
 
 
 
 
 
 
6
  var $detailsTrigger = $( '.wpzerospam-details-trigger' );
7
  $detailsTrigger.click(function( e ) {
8
  e.preventDefault();
assets/js/wpzerospam.js CHANGED
@@ -1,10 +1,7 @@
1
  var WordPressZeroSpam = {
2
  init: function() {
3
- var forms = "#commentform";
4
- forms += ", #registerform";
5
- forms += ", #buddypress #signup_form";
6
  forms += ", .wpzerospam";
7
- forms += ", .ninja-forms-form";
8
  forms += ", .wpforms-form";
9
  forms += ", .gform_wrapper form";
10
 
@@ -21,28 +18,6 @@ var WordPressZeroSpam = {
21
  .appendTo( ".gform_wrapper form " );
22
  });
23
 
24
- // WPForms
25
- jQuery( ".wpcf7-submit" ).click( function() {
26
- jQuery( "<input>" )
27
- .attr( "type", "hidden" )
28
- .attr( "name", "wpzerospam_key" )
29
- .attr( "value", wpzerospam.key )
30
- .appendTo( ".wpcf7-form" );
31
- });
32
-
33
- // NinjaForms
34
- jQuery( document ).on( "nfFormReady", function( e, layoutView ) {
35
- var form = layoutView['$el'].find( 'form' );
36
-
37
- jQuery( "<input>" )
38
- .attr( "type", "hidden" )
39
- .attr( "name", "wpzerospam_key" )
40
- .attr( "value", wpzerospam.key )
41
- .appendTo( form );
42
-
43
- return true;
44
- });
45
-
46
  // All other forms
47
  jQuery( forms ).on( "submit", function() {
48
  if ( ! jQuery( '[name="wpzerospam_key"]', jQuery( this ) ).length ) {
@@ -61,6 +36,9 @@ var WordPressZeroSpam = {
61
  }
62
  };
63
 
 
 
 
64
  jQuery(function() {
65
  WordPressZeroSpam.init();
66
  });
1
  var WordPressZeroSpam = {
2
  init: function() {
3
+ var forms = "#buddypress #signup_form";
 
 
4
  forms += ", .wpzerospam";
 
5
  forms += ", .wpforms-form";
6
  forms += ", .gform_wrapper form";
7
 
18
  .appendTo( ".gform_wrapper form " );
19
  });
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  // All other forms
22
  jQuery( forms ).on( "submit", function() {
23
  if ( ! jQuery( '[name="wpzerospam_key"]', jQuery( this ) ).length ) {
36
  }
37
  };
38
 
39
+ // Will hold the enqueues addons on request.
40
+ var WordPressZeroSpamAddons = {};
41
+
42
  jQuery(function() {
43
  WordPressZeroSpam.init();
44
  });
inc/admin.php CHANGED
@@ -195,7 +195,7 @@ function wpzerospam_dashboard() {
195
 
196
  <div class="wpzerospam-callout">
197
  <div class="wpzerospam-callout-content">
198
- <h2><?php _e( 'Are you a fan of the <a href="https://wordpress.org/plugins/zero-spam/" target="_blank">WordPress Zero Spam</a> plugin? Show your support.', 'wpzerospam' ); ?></h2>
199
  <p><?php _e( 'Help support the continued development of the WordPress Zero Spam plugin by <a href="https://benmarshall.me/donate?utm_source=wordpress_zero_spam&utm_medium=settings_page&utm_campaign=admin" target="_blank">donating today</a>. Your donation goes towards the time it takes to develop new features &amp; updates, but also helps provide pro bono work for nonprofits. <a href="https://benmarshall.me/donate?utm_source=wordpress_zero_spam&utm_medium=settings_page&utm_campaign=admin" target="_blank">Learn more</a>.', 'wpzerospam' ); ?></p>
200
  </div>
201
  <div class="wpzerospam-callout-actions">
195
 
196
  <div class="wpzerospam-callout">
197
  <div class="wpzerospam-callout-content">
198
+ <h2><?php _e( 'Are you a fan of the <a href="https://benmarshall.me/wordpress-zero-spam/?utm_source=wordpress_zero_spam&utm_medium=settings_page&utm_campaign=admin" target="_blank">WordPress Zero Spam</a> plugin? Show your support.', 'wpzerospam' ); ?></h2>
199
  <p><?php _e( 'Help support the continued development of the WordPress Zero Spam plugin by <a href="https://benmarshall.me/donate?utm_source=wordpress_zero_spam&utm_medium=settings_page&utm_campaign=admin" target="_blank">donating today</a>. Your donation goes towards the time it takes to develop new features &amp; updates, but also helps provide pro bono work for nonprofits. <a href="https://benmarshall.me/donate?utm_source=wordpress_zero_spam&utm_medium=settings_page&utm_campaign=admin" target="_blank">Learn more</a>.', 'wpzerospam' ); ?></p>
200
  </div>
201
  <div class="wpzerospam-callout-actions">
inc/helpers.php CHANGED
@@ -62,7 +62,7 @@ if ( ! function_exists( 'wpzerospam_get_log' ) ) {
62
  * Handles what happens when spam is detected
63
  */
64
  if ( ! function_exists( 'wpzerospam_spam_detected' ) ) {
65
- function wpzerospam_spam_detected( $type, $data = [] ) {
66
  $options = wpzerospam_options();
67
 
68
  wpzerospam_log_spam( $type, $data );
@@ -82,12 +82,16 @@ if ( ! function_exists( 'wpzerospam_spam_detected' ) ) {
82
  ]);
83
  }
84
 
85
- if ( 'redirect' == $options['spam_handler'] ) {
86
- wp_redirect( esc_url( $options['spam_redirect_url'] ) );
87
- exit();
88
- } else {
89
- status_header( 403 );
90
- die( $options['spam_message'] );
 
 
 
 
91
  }
92
  }
93
  }
@@ -128,8 +132,11 @@ if ( ! function_exists( 'wpzerospam_update_blocked_ip' ) ) {
128
  // First, check if the IP is already in the DB
129
  $check = wpzerospam_get_blocked_ips( $record['user_ip'] );
130
  if ( $check ) {
 
 
 
131
  // IP exists, update accordingly
132
- $update = [];
133
 
134
  if ( $record['blocked_type'] && $record['blocked_type'] != $check->blocked_type ) {
135
  $update['blocked_type'] = $record['blocked_type'];
62
  * Handles what happens when spam is detected
63
  */
64
  if ( ! function_exists( 'wpzerospam_spam_detected' ) ) {
65
+ function wpzerospam_spam_detected( $type, $data = [], $handle_error = true ) {
66
  $options = wpzerospam_options();
67
 
68
  wpzerospam_log_spam( $type, $data );
82
  ]);
83
  }
84
 
85
+ // Check if WordPress Zero Spam should handle the error. False for forms
86
+ // that process via AJAX & expect a json response.
87
+ if ( $handle_error ) {
88
+ if ( 'redirect' == $options['spam_handler'] ) {
89
+ wp_redirect( esc_url( $options['spam_redirect_url'] ) );
90
+ exit();
91
+ } else {
92
+ status_header( 403 );
93
+ die( $options['spam_message'] );
94
+ }
95
  }
96
  }
97
  }
132
  // First, check if the IP is already in the DB
133
  $check = wpzerospam_get_blocked_ips( $record['user_ip'] );
134
  if ( $check ) {
135
+ $attempts = $check->attempts;
136
+ $attempts++;
137
+
138
  // IP exists, update accordingly
139
+ $update = [ 'attempts' => $attempts ];
140
 
141
  if ( $record['blocked_type'] && $record['blocked_type'] != $check->blocked_type ) {
142
  $update['blocked_type'] = $record['blocked_type'];
inc/scripts.php CHANGED
@@ -1,47 +1,116 @@
1
  <?php
2
  /**
3
- * CSS & JS
4
  *
5
  * @package WordPressZeroSpam
6
  * @since 4.0.0
7
  */
8
 
9
  /**
10
- * Add admin scripts
11
  */
12
- function wpzerospam_admin_scripts( $hook_suffix ) {
13
- if( ! function_exists('get_plugin_data') ) {
14
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- $plugin = get_plugin_data( WORDPRESS_ZERO_SPAM );
 
 
 
 
 
 
 
 
18
 
19
- $admin_pages = [ 'toplevel_page_wordpress-zero-spam', 'wp-zero-spam_page_wordpress-zero-spam-blocked-ips' ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- if (
22
- ! empty( $hook_suffix ) &&
23
- in_array( $hook_suffix, $admin_pages )
24
- ) {
25
- wp_enqueue_style( 'wpzerospam-admin', plugin_dir_url( WORDPRESS_ZERO_SPAM ) . '/assets/css/admin.css', false, $plugin['Version'] );
26
- wp_enqueue_script( 'wpzerospam-admin', plugin_dir_url( WORDPRESS_ZERO_SPAM ) . '/assets/js/admin.js', [ 'jquery' ], $plugin['Version'], true );
27
- wp_enqueue_style( 'wpzerospam-charts', plugin_dir_url( WORDPRESS_ZERO_SPAM ) . '/assets/css/Chart.min.css', false, '2.9.3' );
28
- wp_enqueue_script( 'wpzerospam-charts', plugin_dir_url( WORDPRESS_ZERO_SPAM ) . '/assets/js/Chart.bundle.min.js', [], '2.9.3' );
 
 
29
  }
30
  }
31
  add_action( 'admin_enqueue_scripts', 'wpzerospam_admin_scripts' );
32
 
33
  /**
34
- * Add site scripts
35
  */
36
- function wpzerospam_enqueue_scripts() {
37
- if( ! function_exists('get_plugin_data') ) {
38
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
39
- }
 
 
 
40
 
41
- $plugin = get_plugin_data( WORDPRESS_ZERO_SPAM );
 
 
 
 
 
 
 
 
 
42
 
43
- wp_enqueue_script( 'wpzerospam', plugin_dir_url( WORDPRESS_ZERO_SPAM ) . '/assets/js/wpzerospam.js', [ 'jquery' ], $plugin['Version'], true );
44
- wp_localize_script( 'wpzerospam', 'wpzerospam', [ 'key' => wpzerospam_get_key() ] );
 
 
 
 
 
45
  }
46
  add_action( 'wp_enqueue_scripts', 'wpzerospam_enqueue_scripts' );
47
  add_action( 'login_footer', 'wpzerospam_enqueue_scripts' );
1
  <?php
2
  /**
3
+ * Contains all JS & CSS scripts for the WordPress Zero Spam plugin.
4
  *
5
  * @package WordPressZeroSpam
6
  * @since 4.0.0
7
  */
8
 
9
  /**
10
+ * Register & enqueue the WordPress Zero Spam JS & CSS for the admin dashboard
11
  */
12
+ if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
13
+ function wpzerospam_admin_scripts( $hook_suffix ) {
14
+ // Retrieve the current plugin data (used to get the scripts version)
15
+ if( ! function_exists('get_plugin_data') ) {
16
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
17
+ }
18
+ $plugin = get_plugin_data( WORDPRESS_ZERO_SPAM );
19
+
20
+ // Handle registering & enqueuing scripts based on the current admin page
21
+ switch( $hook_suffix ) {
22
+ case 'toplevel_page_wordpress-zero-spam':
23
+ // Enqueue Chart.js for graphs
24
+ wp_register_script(
25
+ 'wpzerospam-charts',
26
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
27
+ '/assets/js/Chart.bundle.min.js',
28
+ [],
29
+ '2.9.3'
30
+ );
31
+
32
+ // Enqueue Chart.css for graphs
33
+ wp_enqueue_style(
34
+ 'wpzerospam-charts',
35
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
36
+ '/assets/css/Chart.min.css',
37
+ false,
38
+ '2.9.3'
39
+ );
40
 
41
+ // Enqueue the JS for the WordPress Zero Spam dashboard
42
+ wp_enqueue_script(
43
+ 'wpzerospam-admin-dashboard',
44
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
45
+ '/assets/js/admin-dashboard.js',
46
+ [ 'jquery', 'wpzerospam-charts' ],
47
+ $plugin['Version'],
48
+ true
49
+ );
50
 
51
+ // Enqueue the CSS for the WordPress Zero Spam dashboard
52
+ wp_enqueue_style(
53
+ 'wpzerospam-admin-dashboard',
54
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
55
+ '/assets/css/admin-dashboard.css',
56
+ false,
57
+ $plugin['Version']
58
+ );
59
+ break;
60
+ case 'wp-zero-spam_page_wordpress-zero-spam-blocked-ips':
61
+ // Enqueue the JS for the WordPress Zero Spam blocked IPs page
62
+ wp_enqueue_script(
63
+ 'wpzerospam-admin-blocked-ips',
64
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
65
+ '/assets/js/admin-blocked-ips.js',
66
+ [ 'jquery' ],
67
+ $plugin['Version'],
68
+ true
69
+ );
70
 
71
+ // Enqueue the CSS for the WordPress Zero Spam blocked IPs page
72
+ wp_enqueue_style(
73
+ 'wpzerospam-admin-dashboard',
74
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
75
+ '/assets/css/admin-blocked-ips.css',
76
+ false,
77
+ $plugin['Version']
78
+ );
79
+ break;
80
+ }
81
  }
82
  }
83
  add_action( 'admin_enqueue_scripts', 'wpzerospam_admin_scripts' );
84
 
85
  /**
86
+ * Register & enqueue the WordPress Zero Spam JS & CSS for the frontend
87
  */
88
+ if ( ! function_exists( 'wpzerospam_enqueue_scripts' ) ) {
89
+ function wpzerospam_enqueue_scripts() {
90
+ // Retrieve the current plugin data (used to get the scripts version)
91
+ if( ! function_exists('get_plugin_data') ) {
92
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
93
+ }
94
+ $plugin = get_plugin_data( WORDPRESS_ZERO_SPAM );
95
 
96
+ // Load the JS that contains the WordPressZeroSpam oject, needed on all
97
+ // pages
98
+ wp_enqueue_script(
99
+ 'wpzerospam',
100
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
101
+ '/assets/js/wpzerospam.js',
102
+ [ 'jquery' ],
103
+ $plugin['Version'],
104
+ true
105
+ );
106
 
107
+ // Pass the latest generate key to the frontend script
108
+ wp_localize_script(
109
+ 'wpzerospam',
110
+ 'wpzerospam',
111
+ [ 'key' => wpzerospam_get_key() ]
112
+ );
113
+ }
114
  }
115
  add_action( 'wp_enqueue_scripts', 'wpzerospam_enqueue_scripts' );
116
  add_action( 'login_footer', 'wpzerospam_enqueue_scripts' );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://benmarshall.me/donate/?utm_source=wordpress_zero_spam&utm_m
5
  Requires at least: 5.2
6
  Tested up to: 5.4.2
7
  Requires PHP: 7.1
8
- Stable tag: 4.3.6
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
@@ -56,6 +56,10 @@ For more information, see the [plugin’s website](https://benmarshall.me/wordpr
56
 
57
  == Frequently Asked Questions ==
58
 
 
 
 
 
59
  = How can I integrate this into a plugin, theme or custom form? =
60
 
61
  It's easy as adding the class `wpzerospam` to the `form` element, then adding a check in the form processor that the `wpzerospam_key` post value matches the option value in the database using the `wpzerospam_key_check()` helper function.
@@ -88,6 +92,11 @@ Yes, that's what does the magic and keeps spam bots out.
88
 
89
  == Changelog ==
90
 
 
 
 
 
 
91
  = 4.3.6 =
92
 
93
  * Added a check for the `is_plugin_active` functions to ensure they're available before calling it
5
  Requires at least: 5.2
6
  Tested up to: 5.4.2
7
  Requires PHP: 7.1
8
+ Stable tag: 4.3.7
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
56
 
57
  == Frequently Asked Questions ==
58
 
59
+ = Why aren't spammy comments being blocked? =
60
+
61
+ WordPress Zero Spam relies on the default core form id (`#commentform`) in order to detect comments. Verify your comment forms have this ID or add the class `wpzerospam` to them so the plugin knows to it should attempt to detect spam comments.
62
+
63
  = How can I integrate this into a plugin, theme or custom form? =
64
 
65
  It's easy as adding the class `wpzerospam` to the `form` element, then adding a check in the form processor that the `wpzerospam_key` post value matches the option value in the database using the `wpzerospam_key_check()` helper function.
92
 
93
  == Changelog ==
94
 
95
+ = 4.3.7 =
96
+
97
+ * Optimized scripts & when they get loaded (only when needed)
98
+ * Fixed bug with incrementing spam detections in the blocked IPs log
99
+
100
  = 4.3.6 =
101
 
102
  * Added a check for the `is_plugin_active` functions to ensure they're available before calling it
templates/ip-list.php CHANGED
@@ -8,7 +8,7 @@
8
 
9
  $chart_limit = 20;
10
  ?>
11
- <div class="wpzerospam-box">
12
  <h3><?php _e( 'Most Spam by IP Address', 'wpzerospam' ); ?></h3>
13
  <div class="inside">
14
  <?php
8
 
9
  $chart_limit = 20;
10
  ?>
11
+ <div class="wpzerospam-box wpzerospam-box-ip-list">
12
  <h3><?php _e( 'Most Spam by IP Address', 'wpzerospam' ); ?></h3>
13
  <div class="inside">
14
  <?php
wordpress-zero-spam.php CHANGED
@@ -13,7 +13,7 @@
13
  * Plugin Name: WordPress Zero Spam
14
  * Plugin URI: https://benmarshall.me/wordpress-zero-spam
15
  * Description: Tired of all the useless and bloated WordPress spam plugins? The WordPress Zero Spam plugin makes blocking spam a cinch. <strong>Just install, activate and say goodbye to spam.</strong> Based on work by <a href="http://davidwalsh.name/wordpress-comment-spam" target="_blank">David Walsh</a>.
16
- * Version: 4.3.6
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.2
19
  * Author: Ben Marshall
13
  * Plugin Name: WordPress Zero Spam
14
  * Plugin URI: https://benmarshall.me/wordpress-zero-spam
15
  * Description: Tired of all the useless and bloated WordPress spam plugins? The WordPress Zero Spam plugin makes blocking spam a cinch. <strong>Just install, activate and say goodbye to spam.</strong> Based on work by <a href="http://davidwalsh.name/wordpress-comment-spam" target="_blank">David Walsh</a>.
16
+ * Version: 4.3.7
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.2
19
  * Author: Ben Marshall