WordPress Zero Spam - Version 4.8.1

Version Description

  • Fix for charts not showing up in the dashboard
Download this release

Release Info

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

Code changes from version 4.8.0 to 4.8.1

assets/css/admin-dashboard.css CHANGED
@@ -26,6 +26,10 @@
26
  display: block;
27
  }
28
 
 
 
 
 
29
  .wpzerospam-boxes {
30
  display: flex;
31
  flex-wrap: wrap;
@@ -56,51 +60,77 @@
56
  padding: 12px;
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  .wpzerospam-list {
60
  margin: 0;
61
  padding: 0;
62
  list-style: none;
63
  }
64
 
65
- .wpzerospam-list li {
66
  display: flex;
67
  }
68
 
69
- .wpzerospam-list-cell,
70
- .wpzerospam-list .wpzerospam-country-flag {
 
 
 
71
  flex-shrink: 0;
72
  }
73
 
74
- .wpzerospam-list .wpzerospam-country-flag {
75
- margin-right: 8px;
76
  width: 16px;
77
  }
78
 
79
- .wpzerospam-list-cell {
80
- width: 130px;
81
  }
82
 
83
- .wpzerospam-list-cell-small {
84
- text-align: right;
85
- width: 30px;
86
  }
87
 
88
- .wpzerospam-action {
89
- flex-grow: 1;
90
  text-align: right;
91
  }
92
 
93
- @media (min-width: 768px) {
94
- .wpzerospam-box {
95
- width: calc(100% / 3 - 18px);
96
- }
97
 
98
- .wpzerospam-box-line-chart,
99
- .wpzerospam-box-countries-pie {
100
- width: calc(100% / 2 - 18px);
101
- }
102
 
103
- .wpzerospam-box-line-chart {
104
- width: calc((100% / 3) * 2 - 18px);
105
- }
106
  }
26
  display: block;
27
  }
28
 
29
+
30
+ /**
31
+ * Info boxes
32
+ */
33
  .wpzerospam-boxes {
34
  display: flex;
35
  flex-wrap: wrap;
60
  padding: 12px;
61
  }
62
 
63
+ @media (min-width: 1024px) {
64
+ .wpzerospam-box {
65
+ width: calc(100% / 2 - 18px);
66
+ }
67
+ }
68
+
69
+ @media (min-width: 1200px) {
70
+ .wpzerospam-box {
71
+ width: calc(100% / 3 - 18px);
72
+ }
73
+
74
+ .wpzerospam-box-line-chart {
75
+ width: calc((100% / 3) * 2 - 18px);
76
+ }
77
+
78
+ .wpzerospam-box-countries-pie {
79
+ width: calc(100% / 2 - 18px);
80
+ }
81
+ }
82
+
83
+
84
+
85
+ /**
86
+ * List of IPs
87
+ */
88
  .wpzerospam-list {
89
  margin: 0;
90
  padding: 0;
91
  list-style: none;
92
  }
93
 
94
+ .wpzerospam-list-item {
95
  display: flex;
96
  }
97
 
98
+ .wpzerospam-list-cell-icon,
99
+ .wpzerospam-list-cell-ip,
100
+ .wpzerospam-list-cell-count,
101
+ .wpzerospam-list-cell-action {
102
+ flex-grow: 0;
103
  flex-shrink: 0;
104
  }
105
 
106
+ .wpzerospam-list-cell-icon {
107
+ margin-right: 5px;
108
  width: 16px;
109
  }
110
 
111
+ .wpzerospam-list-cell-ip {
112
+ width: 120px;
113
  }
114
 
115
+ .wpzerospam-list-cell-country {
116
+ flex-grow: 1;
117
+ font-size: 0.8rem;
118
  }
119
 
120
+ .wpzerospam-list-cell-count,
121
+ .wpzerospam-list-cell-action {
122
  text-align: right;
123
  }
124
 
125
+ .wpzerospam-list-cell-count {
126
+ width: 50px;
127
+ }
 
128
 
129
+ .wpzerospam-list-cell-action {
130
+ margin-left: 5px;
131
+ width: 80px;
132
+ }
133
 
134
+ .wpzerospam-list-cell-na {
135
+ color: #ccd0d4;
 
136
  }
classes/class-wpzerospam-blacklisted-table.php CHANGED
@@ -166,35 +166,6 @@ class WPZeroSpam_Blacklisted_Table extends WP_List_Table {
166
  return [];
167
  }
168
 
169
- /**
170
- * Allows you to sort the data by the variables set in the $_GET
171
- *
172
- * @return Mixed
173
- */
174
- private function sort_data( $a, $b ) {
175
- // Set defaults
176
- $orderby = 'last_updated';
177
- $order = 'desc';
178
-
179
- // If orderby is set, use this as the sort column
180
- if( ! empty( $_GET['orderby'] ) ) {
181
- $orderby = $_GET['orderby'];
182
- }
183
-
184
- // If order is set use this as the order
185
- if ( ! empty($_GET['order'] ) ) {
186
- $order = $_GET['order'];
187
- }
188
-
189
- $result = strcmp( $a->$orderby, $b->$orderby );
190
-
191
- if ( $order === 'asc' ) {
192
- return $result;
193
- }
194
-
195
- return -$result;
196
- }
197
-
198
  // Get results
199
  function prepare_items($args = []) {
200
  $this->process_bulk_action();
@@ -234,8 +205,6 @@ class WPZeroSpam_Blacklisted_Table extends WP_List_Table {
234
  $data = wpzerospam_query( 'blacklist', $query_args );
235
  if ( ! $data ) { return false; }
236
 
237
- usort( $data, [ &$this, 'sort_data' ] );
238
-
239
  $total_items = wpzerospam_query( 'blacklist', $query_args, true );
240
 
241
  $this->set_pagination_args([
166
  return [];
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  // Get results
170
  function prepare_items($args = []) {
171
  $this->process_bulk_action();
205
  $data = wpzerospam_query( 'blacklist', $query_args );
206
  if ( ! $data ) { return false; }
207
 
 
 
208
  $total_items = wpzerospam_query( 'blacklist', $query_args, true );
209
 
210
  $this->set_pagination_args([
classes/class-wpzerospam-blocked-ip-table.php CHANGED
@@ -146,35 +146,6 @@ class WPZeroSpam_Blocked_IP_Table extends WP_List_Table {
146
  return [];
147
  }
148
 
149
- /**
150
- * Allows you to sort the data by the variables set in the $_GET
151
- *
152
- * @return Mixed
153
- */
154
- private function sort_data( $a, $b ) {
155
- // Set defaults
156
- $orderby = 'date_added';
157
- $order = 'desc';
158
-
159
- // If orderby is set, use this as the sort column
160
- if( ! empty( $_GET['orderby'] ) ) {
161
- $orderby = $_GET['orderby'];
162
- }
163
-
164
- // If order is set use this as the order
165
- if ( ! empty($_GET['order'] ) ) {
166
- $order = $_GET['order'];
167
- }
168
-
169
- $result = strcmp( $a->$orderby, $b->$orderby );
170
-
171
- if ( $order === 'asc' ) {
172
- return $result;
173
- }
174
-
175
- return -$result;
176
- }
177
-
178
  // Get results
179
  function prepare_items($args = []) {
180
  $this->process_bulk_action();
@@ -214,8 +185,6 @@ class WPZeroSpam_Blocked_IP_Table extends WP_List_Table {
214
  $data = wpzerospam_query( 'blocked', $query_args );
215
  if ( ! $data ) { return false; }
216
 
217
- usort( $data, [ &$this, 'sort_data' ] );
218
-
219
  $total_items = wpzerospam_query( 'blocked', $query_args, true );
220
 
221
  $this->set_pagination_args([
146
  return [];
147
  }
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  // Get results
150
  function prepare_items($args = []) {
151
  $this->process_bulk_action();
185
  $data = wpzerospam_query( 'blocked', $query_args );
186
  if ( ! $data ) { return false; }
187
 
 
 
188
  $total_items = wpzerospam_query( 'blocked', $query_args, true );
189
 
190
  $this->set_pagination_args([
classes/class-wpzerospam-log-table.php CHANGED
@@ -388,35 +388,6 @@ class WPZeroSpam_Log_Table extends WP_List_Table {
388
  return [];
389
  }
390
 
391
- /**
392
- * Allows you to sort the data by the variables set in the $_GET
393
- *
394
- * @return Mixed
395
- */
396
- private function sort_data( $a, $b ) {
397
- // Set defaults
398
- $orderby = 'date_recorded';
399
- $order = 'desc';
400
-
401
- // If orderby is set, use this as the sort column
402
- if( ! empty( $_GET['orderby'] ) ) {
403
- $orderby = $_GET['orderby'];
404
- }
405
-
406
- // If order is set use this as the order
407
- if ( ! empty($_GET['order'] ) ) {
408
- $order = $_GET['order'];
409
- }
410
-
411
- $result = strcmp( $a->$orderby, $b->$orderby );
412
-
413
- if ( $order === 'asc' ) {
414
- return $result;
415
- }
416
-
417
- return -$result;
418
- }
419
-
420
  // Get results
421
  function prepare_items($args = []) {
422
  $this->process_bulk_action();
@@ -456,8 +427,6 @@ class WPZeroSpam_Log_Table extends WP_List_Table {
456
  $data = wpzerospam_query( 'log', $query_args );
457
  if ( ! $data ) { return false; }
458
 
459
- usort( $data, [ &$this, 'sort_data' ] );
460
-
461
  $total_items = wpzerospam_query( 'log', $query_args, true );
462
 
463
  $this->set_pagination_args([
388
  return [];
389
  }
390
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  // Get results
392
  function prepare_items($args = []) {
393
  $this->process_bulk_action();
427
  $data = wpzerospam_query( 'log', $query_args );
428
  if ( ! $data ) { return false; }
429
 
 
 
430
  $total_items = wpzerospam_query( 'log', $query_args, true );
431
 
432
  $this->set_pagination_args([
inc/admin.php CHANGED
@@ -291,7 +291,7 @@ function wpzerospam_blocked_ips_page() {
291
  function wpzerospam_dashboard() {
292
  if ( ! current_user_can( 'manage_options' ) ) { return; }
293
 
294
- $log = wpzerospam_get_log();
295
 
296
  $predefined_colors = [
297
  '#1a0003', '#4d000a', '#800011', '#b30017', '#e6001e', '#ff1a38', '#ff4d64', '#ff8090', '#ffb3bd', '#ffe5e9'
@@ -315,26 +315,26 @@ function wpzerospam_dashboard() {
315
 
316
  function wpzerospam_options_page() {
317
  if ( ! current_user_can( 'manage_options' ) ) { return; }
318
- ?>
319
- <div class="wrap">
320
- <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
321
 
322
- <?php require plugin_dir_path( WORDPRESS_ZERO_SPAM ) . '/templates/callout.php'; ?>
323
 
324
- <form action="options.php" method="post">
325
- <?php
326
- // Output security fields for the registered setting "wpzerospam"
327
- settings_fields( 'wpzerospam' );
328
 
329
- // Output setting sections and their fields
330
- do_settings_sections( 'wpzerospam' );
331
 
332
- // Output save settings button
333
- submit_button( 'Save Settings' );
334
- ?>
335
- </form>
336
- </div>
337
- <?php
338
  }
339
 
340
  function wpzerospam_validate_options( $input ) {
291
  function wpzerospam_dashboard() {
292
  if ( ! current_user_can( 'manage_options' ) ) { return; }
293
 
294
+ $log = wpzerospam_query( 'log' );
295
 
296
  $predefined_colors = [
297
  '#1a0003', '#4d000a', '#800011', '#b30017', '#e6001e', '#ff1a38', '#ff4d64', '#ff8090', '#ffb3bd', '#ffe5e9'
315
 
316
  function wpzerospam_options_page() {
317
  if ( ! current_user_can( 'manage_options' ) ) { return; }
318
+ ?>
319
+ <div class="wrap">
320
+ <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
321
 
322
+ <?php require plugin_dir_path( WORDPRESS_ZERO_SPAM ) . '/templates/callout.php'; ?>
323
 
324
+ <form action="options.php" method="post">
325
+ <?php
326
+ // Output security fields for the registered setting "wpzerospam"
327
+ settings_fields( 'wpzerospam' );
328
 
329
+ // Output setting sections and their fields
330
+ do_settings_sections( 'wpzerospam' );
331
 
332
+ // Output save settings button
333
+ submit_button( 'Save Settings' );
334
+ ?>
335
+ </form>
336
+ </div>
337
+ <?php
338
  }
339
 
340
  function wpzerospam_validate_options( $input ) {
inc/helpers.php CHANGED
@@ -4,6 +4,7 @@
4
  *
5
  * @package WordPressZeroSpam
6
  * @since 4.0.0
 
7
  */
8
 
9
  /**
@@ -11,6 +12,103 @@
11
  */
12
  require plugin_dir_path( WORDPRESS_ZERO_SPAM ) . '/inc/locations.php';
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  /**
15
  * Query the database
16
  */
@@ -88,99 +186,6 @@ if ( ! function_exists( 'wpzerospam_query' ) ) {
88
 
89
 
90
 
91
- /**
92
- * Handles what happens when spam is detected
93
- */
94
- if ( ! function_exists( 'wpzerospam_get_ip_info' ) ) {
95
- function wpzerospam_get_ip_info( $ip ) {
96
- $options = wpzerospam_options();
97
-
98
- if ( empty( $options['ipstack_api'] ) ) { return false; }
99
-
100
- $base_url = 'http://api.ipstack.com/';
101
- $remote_url = $base_url . $ip . '?access_key=' . $options['ipstack_api'];
102
- $response = wp_remote_get( $remote_url );
103
-
104
- if ( is_array( $response ) && ! is_wp_error( $response ) ) {
105
- $info = json_decode( $response['body'], true );
106
-
107
- return [
108
- 'type' => ! empty( $info['type'] ) ? sanitize_text_field( $info['type'] ) : false,
109
- 'continent_code' => ! empty( $info['continent_code'] ) ? sanitize_text_field( $info['continent_code'] ) : false,
110
- 'continent_name' => ! empty( $info['continent_name'] ) ? sanitize_text_field( $info['continent_name'] ) : false,
111
- 'country_code' => ! empty( $info['country_code'] ) ? sanitize_text_field( $info['country_code'] ) : false,
112
- 'country_name' => ! empty( $info['country_name'] ) ? sanitize_text_field( $info['country_name'] ) : false,
113
- 'region_code' => ! empty( $info['region_code'] ) ? sanitize_text_field( $info['region_code'] ) : false,
114
- 'region_name' => ! empty( $info['region_name'] ) ? sanitize_text_field( $info['region_name'] ) : false,
115
- 'city' => ! empty( $info['city'] ) ? sanitize_text_field( $info['city'] ) : false,
116
- 'zip' => ! empty( $info['zip'] ) ? sanitize_text_field( $info['zip'] ) : false,
117
- 'latitude' => ! empty( $info['latitude'] ) ? sanitize_text_field( $info['latitude'] ) : false,
118
- 'longitude' => ! empty( $info['longitude'] ) ? sanitize_text_field( $info['longitude'] ) : false,
119
- 'flag' => ! empty( $info['location']['country_flag'] ) ? sanitize_text_field( $info['location']['country_flag'] ) : false,
120
- ];
121
- }
122
-
123
- return false;
124
- }
125
- }
126
-
127
- /**
128
- * Returns an array of spam detection types
129
- */
130
- if ( ! function_exists( 'wpzerospam_types' ) ) {
131
- function wpzerospam_types( $key = false ) {
132
- $types = apply_filters( 'wpzerospam_types', [ 'blocked' => __( 'Access Blocked', 'wpzerospam' ) ] );
133
-
134
- if ( $key ) {
135
- if ( ! empty( $types[ $key ] ) ) {
136
- return $types[ $key ];
137
- }
138
-
139
- return $key;
140
- }
141
-
142
- return $types;
143
- }
144
- }
145
-
146
- /**
147
- * Returns spam detections from the database
148
- */
149
- if ( ! function_exists( 'wpzerospam_get_log' ) ) {
150
- function wpzerospam_get_log( $args = false ) {
151
- global $wpdb;
152
-
153
- if( 'total' == $args ) {
154
- return $wpdb->get_var( 'SELECT COUNT(log_id) FROM ' . wpzerospam_tables( 'log' ));
155
- }
156
-
157
- $sql = 'SELECT * FROM ' . wpzerospam_tables( 'log' );
158
- if ( is_array( $args ) ) {
159
- if ( ! empty( $args['type'] ) ) {
160
- $sql .= ' WHERE log_type = "' . $args['type'] . '"';
161
- }
162
-
163
- if ( ! empty( $args['orderby'] ) ) {
164
- $sql .= ' ORDER BY ' . $args['orderby'];
165
- }
166
-
167
- if ( ! empty( $args['order'] ) ) {
168
- $sql .= ' ' . $args['order'];
169
- }
170
-
171
- if ( ! empty( $args['limit'] ) ) {
172
- $sql .= ' LIMIT ' . $args['limit'];
173
- }
174
-
175
- if ( ! empty( $args['offset'] ) ) {
176
- $sql .= ', ' . $args['offset'];
177
- }
178
- }
179
-
180
- return $wpdb->get_results( $sql );
181
- }
182
- }
183
-
184
  /**
185
  * Handles what happens when spam is detected
186
  */
@@ -230,27 +235,6 @@ if ( ! function_exists( 'wpzerospam_spam_detected' ) ) {
230
  }
231
  }
232
 
233
- /**
234
- * Checks the post submission for a valid key
235
- */
236
- if ( ! function_exists( 'wpzerospam_key_check' ) ) {
237
- function wpzerospam_key_check( $data = false ) {
238
- if (
239
- $data &&
240
- ! empty( $data['wpzerospam_key'] ) &&
241
- $data['wpzerospam_key'] == wpzerospam_get_key()
242
- ) {
243
- return true;
244
- }
245
-
246
- if ( ! empty( $_POST['wpzerospam_key'] ) && $_POST['wpzerospam_key'] == wpzerospam_get_key() ) {
247
- return true;
248
- }
249
-
250
- return false;
251
- }
252
- }
253
-
254
  /**
255
  * Add a IP address to the blocked table
256
  */
@@ -1062,7 +1046,7 @@ if ( ! function_exists( 'wpzerospam_send_detection' ) ) {
1062
  return false;
1063
  }
1064
 
1065
- $request = wp_remote_post( $api_url, [
1066
  'method' => 'POST',
1067
  'body' => [
1068
  'ip' => $data['ip'],
@@ -1070,7 +1054,13 @@ if ( ! function_exists( 'wpzerospam_send_detection' ) ) {
1070
  'site' => site_url()
1071
  ],
1072
  'sslverify' => true
1073
- ]);
 
 
 
 
 
 
1074
  if ( is_wp_error( $request ) ) {
1075
  return false;
1076
  }
4
  *
5
  * @package WordPressZeroSpam
6
  * @since 4.0.0
7
+ * @link https://benmarshall.me/wordpress-zero-spam/
8
  */
9
 
10
  /**
12
  */
13
  require plugin_dir_path( WORDPRESS_ZERO_SPAM ) . '/inc/locations.php';
14
 
15
+ /**
16
+ * Returns the geolocation information for a specified IP address.
17
+ *
18
+ * @param string $ip IP address.
19
+ * @return array/false An array with the IP address location information or
20
+ * false if not found.
21
+ */
22
+ if ( ! function_exists( 'wpzerospam_get_ip_info' ) ) {
23
+ function wpzerospam_get_ip_info( $ip ) {
24
+ $options = wpzerospam_options();
25
+
26
+ if ( empty( $options['ipstack_api'] ) ) { return false; }
27
+
28
+ $base_url = 'http://api.ipstack.com/';
29
+ $remote_url = $base_url . $ip . '?access_key=' . $options['ipstack_api'];
30
+ $response = wp_remote_get( $remote_url );
31
+
32
+ if ( is_array( $response ) && ! is_wp_error( $response ) ) {
33
+ $info = json_decode( $response['body'], true );
34
+
35
+ return [
36
+ 'type' => ! empty( $info['type'] ) ? sanitize_text_field( $info['type'] ) : false,
37
+ 'continent_code' => ! empty( $info['continent_code'] ) ? sanitize_text_field( $info['continent_code'] ) : false,
38
+ 'continent_name' => ! empty( $info['continent_name'] ) ? sanitize_text_field( $info['continent_name'] ) : false,
39
+ 'country_code' => ! empty( $info['country_code'] ) ? sanitize_text_field( $info['country_code'] ) : false,
40
+ 'country_name' => ! empty( $info['country_name'] ) ? sanitize_text_field( $info['country_name'] ) : false,
41
+ 'region_code' => ! empty( $info['region_code'] ) ? sanitize_text_field( $info['region_code'] ) : false,
42
+ 'region_name' => ! empty( $info['region_name'] ) ? sanitize_text_field( $info['region_name'] ) : false,
43
+ 'city' => ! empty( $info['city'] ) ? sanitize_text_field( $info['city'] ) : false,
44
+ 'zip' => ! empty( $info['zip'] ) ? sanitize_text_field( $info['zip'] ) : false,
45
+ 'latitude' => ! empty( $info['latitude'] ) ? sanitize_text_field( $info['latitude'] ) : false,
46
+ 'longitude' => ! empty( $info['longitude'] ) ? sanitize_text_field( $info['longitude'] ) : false,
47
+ 'flag' => ! empty( $info['location']['country_flag'] ) ? sanitize_text_field( $info['location']['country_flag'] ) : false,
48
+ ];
49
+ }
50
+
51
+ return false;
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Returns the human-readable spam type or an array of available spam types.
57
+ *
58
+ * @param string $type_key The key of the type that should be returned.
59
+ * @return string/array The human-readable type name or an array of all the
60
+ * available types.
61
+ */
62
+ if ( ! function_exists( 'wpzerospam_types' ) ) {
63
+ function wpzerospam_types( $type_key = false ) {
64
+ $types = apply_filters( 'wpzerospam_types', [ 'blocked' => __( 'Access Blocked', 'wpzerospam' ) ] );
65
+
66
+ if ( $type_key ) {
67
+ if ( ! empty( $types[ $type_key ] ) ) {
68
+ return $types[ $type_key ];
69
+ }
70
+
71
+ return $type_key;
72
+ }
73
+
74
+ return $types;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Checks if either the submission data or $_POST contain the wpzerospam_key and
80
+ * if it matches whats in the database.
81
+ *
82
+ * @param array $submission_data An array of submission data that contains the
83
+ * wpzerospam_key field
84
+ * @return boolean true if the submission key matches the one in the database,
85
+ * false if it doesn’t.
86
+ */
87
+ if ( ! function_exists( 'wpzerospam_key_check' ) ) {
88
+ function wpzerospam_key_check( $submission_data = false ) {
89
+ if (
90
+ $submission_data &&
91
+ ! empty( $submission_data['wpzerospam_key'] ) &&
92
+ $submission_data['wpzerospam_key'] == wpzerospam_get_key()
93
+ ) {
94
+ return true;
95
+ }
96
+
97
+ if ( ! empty( $_POST['wpzerospam_key'] ) && $_POST['wpzerospam_key'] == wpzerospam_get_key() ) {
98
+ return true;
99
+ }
100
+
101
+ return false;
102
+ }
103
+ }
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
  /**
113
  * Query the database
114
  */
186
 
187
 
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  /**
190
  * Handles what happens when spam is detected
191
  */
235
  }
236
  }
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  /**
239
  * Add a IP address to the blocked table
240
  */
1046
  return false;
1047
  }
1048
 
1049
+ $request_args = [
1050
  'method' => 'POST',
1051
  'body' => [
1052
  'ip' => $data['ip'],
1054
  'site' => site_url()
1055
  ],
1056
  'sslverify' => true
1057
+ ];
1058
+
1059
+ if ( WP_DEBUG ) {
1060
+ $request_args['sslverify'] = false;
1061
+ }
1062
+
1063
+ $request = wp_remote_post( $api_url, $request_args );
1064
  if ( is_wp_error( $request ) ) {
1065
  return false;
1066
  }
inc/locations.php CHANGED
@@ -7,12 +7,19 @@
7
  */
8
 
9
  /**
10
- * Get region name by code
 
 
 
 
 
11
  *
12
  * @link https://en.wikipedia.org/wiki/ISO_3166-2:COUNTRY_CODE
 
 
13
  */
14
  if ( ! function_exists( 'wpzerospam_get_location' ) ) {
15
- function wpzerospam_get_location( $country, $region = false ) {
16
  $locations = [
17
  'US' => [
18
  'name' => 'United States',
@@ -1825,21 +1832,21 @@ if ( ! function_exists( 'wpzerospam_get_location' ) ) {
1825
  ]
1826
  ];
1827
 
1828
- if ( ! $region ) {
1829
- if ( ! empty( $locations[ $country ]['name'] ) ) {
1830
- return $locations[ $country ]['name'];
1831
- } elseif( ! $country ) {
1832
  return false;
1833
  } else {
1834
- return $country;
1835
  }
1836
  } else {
1837
- if ( ! empty( $locations[ $country ]['regions'][ $region ]['name'] ) ) {
1838
- return $locations[ $country ]['regions'][ $region ]['name'];
1839
- } elseif( ! $region ) {
1840
  return false;
1841
  } else {
1842
- return $region;
1843
  }
1844
  }
1845
  }
7
  */
8
 
9
  /**
10
+ * Returns the human-readable country or region name.
11
+ *
12
+ * * If no region is provided, it returns the country name.
13
+ * * If the country’s name isn’t available, it returns the country abbreviation.
14
+ * * If a region is provided, it returns the region name.
15
+ * * If the region name isn’t available, it returns the region abbreviation.
16
  *
17
  * @link https://en.wikipedia.org/wiki/ISO_3166-2:COUNTRY_CODE
18
+ * @param string $country_code The two letter country code.
19
+ * @param string $region_code The two letter region code.
20
  */
21
  if ( ! function_exists( 'wpzerospam_get_location' ) ) {
22
+ function wpzerospam_get_location( $country_code, $region_code = false ) {
23
  $locations = [
24
  'US' => [
25
  'name' => 'United States',
1832
  ]
1833
  ];
1834
 
1835
+ if ( ! $region_code ) {
1836
+ if ( ! empty( $locations[ $country_code ]['name'] ) ) {
1837
+ return $locations[ $country_code ]['name'];
1838
+ } elseif( ! $country_code ) {
1839
  return false;
1840
  } else {
1841
+ return $country_code;
1842
  }
1843
  } else {
1844
+ if ( ! empty( $locations[ $country_code ]['regions'][ $region_code ]['name'] ) ) {
1845
+ return $locations[ $country_code ]['regions'][ $region_code ]['name'];
1846
+ } elseif( ! $region_code ) {
1847
  return false;
1848
  } else {
1849
+ return $region_code;
1850
  }
1851
  }
1852
  }
inc/scripts.php CHANGED
@@ -19,6 +19,24 @@ if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
19
  WORDPRESS_ZERO_SPAM_VERSION
20
  );
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  wp_register_script(
23
  'wpzerospam-admin-tables',
24
  plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
@@ -44,23 +62,9 @@ if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
44
  wp_enqueue_style( 'wpzerospam-admin-tables' );
45
  break;
46
  case 'toplevel_page_wordpress-zero-spam':
47
- // Enqueue Chart.js for graphs
48
- wp_register_script(
49
- 'wpzerospam-charts',
50
- plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
51
- '/assets/js/Chart.bundle.min.js',
52
- [],
53
- '2.9.3'
54
- );
55
-
56
- // Enqueue Chart.css for graphs
57
- wp_enqueue_style(
58
- 'wpzerospam-charts',
59
- plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
60
- '/assets/css/Chart.min.css',
61
- false,
62
- '2.9.3'
63
- );
64
 
65
  wp_enqueue_style(
66
  'wpzerospam-admin-dashboard',
19
  WORDPRESS_ZERO_SPAM_VERSION
20
  );
21
 
22
+ // Register Chart.js for graphs
23
+ wp_register_script(
24
+ 'wpzerospam-charts',
25
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
26
+ '/assets/js/Chart.bundle.min.js',
27
+ [],
28
+ '2.9.3'
29
+ );
30
+
31
+ // Register Chart.css for graphs
32
+ wp_register_style(
33
+ 'wpzerospam-charts',
34
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
35
+ '/assets/css/Chart.min.css',
36
+ false,
37
+ '2.9.3'
38
+ );
39
+
40
  wp_register_script(
41
  'wpzerospam-admin-tables',
42
  plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
62
  wp_enqueue_style( 'wpzerospam-admin-tables' );
63
  break;
64
  case 'toplevel_page_wordpress-zero-spam':
65
+ // Enqueue Chart.js
66
+ wp_enqueue_script( 'wpzerospam-charts' );
67
+ wp_enqueue_style( 'wpzerospam-charts' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  wp_enqueue_style(
70
  'wpzerospam-admin-dashboard',
integrations/ninja-forms/ninja-forms.php CHANGED
@@ -19,7 +19,6 @@ add_filter( 'wpzerospam_types', function( $types ) {
19
  */
20
  if ( ! function_exists( 'wpzerospam_ninja_forms_validate' ) ) {
21
  function wpzerospam_ninja_forms_validate( $form_data ) {
22
-
23
  if ( is_user_logged_in() ) {
24
  return $form_data;
25
  }
@@ -35,18 +34,9 @@ if ( ! function_exists( 'wpzerospam_ninja_forms_validate' ) ) {
35
 
36
  wpzerospam_spam_detected( 'ninja_forms', $form_data, false );
37
 
38
- $errors = [
39
- 'form' => [
40
- 'wpzerospam' => $options['blocked_message'],
41
- ]
42
- ];
43
-
44
- $response = [
45
- 'errors' => $errors,
46
- ];
47
- // @TODO - Find a way to display the error message to the user
48
- echo wp_json_encode( $response );
49
- wp_die();
50
  }
51
 
52
  return $form_data;
@@ -54,21 +44,19 @@ if ( ! function_exists( 'wpzerospam_ninja_forms_validate' ) ) {
54
  }
55
  add_filter( 'ninja_forms_submit_data', 'wpzerospam_ninja_forms_validate' );
56
 
57
- if( ! class_exists( 'WordPressZeroSpam_NF_ExtraData' ) ) {
58
  class WordPressZeroSpam_NF_ExtraData {
59
- // Stores the form IDs we want to modify
60
  var $form_ids = [];
61
  var $script_added = false;
62
 
63
  public function __construct() {
64
- add_action('ninja_forms_before_form_display', [ $this, 'addHooks' ]);
65
  }
66
 
67
  public function addHooks( $form_id ) {
68
  $this->form_ids[] = $form_id;
69
 
70
- //Make sure we only add the script once
71
- if( ! $this->script_added ) {
72
  add_action( 'wp_footer', [ $this, 'add_extra_to_form' ], 99 );
73
  $this->script_added = true;
74
  }
@@ -79,6 +67,7 @@ if( ! class_exists( 'WordPressZeroSpam_NF_ExtraData' ) ) {
79
  <script>
80
  (function() {
81
  var form_ids = [ <?php echo join( ", ", $this->form_ids ); ?> ];
 
82
  nfRadio.channel( "forms" ).on( "before:submit", function( e ) {
83
  if( form_ids.indexOf( +e.id ) === -1 ) return;
84
 
19
  */
20
  if ( ! function_exists( 'wpzerospam_ninja_forms_validate' ) ) {
21
  function wpzerospam_ninja_forms_validate( $form_data ) {
 
22
  if ( is_user_logged_in() ) {
23
  return $form_data;
24
  }
34
 
35
  wpzerospam_spam_detected( 'ninja_forms', $form_data, false );
36
 
37
+ // @TODO - This is a hacky way to display an error for spam detections,
38
+ // but only way I've found to show an error.
39
+ $form_data['errors']['fields'][1] = $options['spam_message'];
 
 
 
 
 
 
 
 
 
40
  }
41
 
42
  return $form_data;
44
  }
45
  add_filter( 'ninja_forms_submit_data', 'wpzerospam_ninja_forms_validate' );
46
 
47
+ if ( ! class_exists( 'WordPressZeroSpam_NF_ExtraData' ) ) {
48
  class WordPressZeroSpam_NF_ExtraData {
 
49
  var $form_ids = [];
50
  var $script_added = false;
51
 
52
  public function __construct() {
53
+ add_action( 'ninja_forms_before_form_display', [ $this, 'addHooks' ] );
54
  }
55
 
56
  public function addHooks( $form_id ) {
57
  $this->form_ids[] = $form_id;
58
 
59
+ if ( ! $this->script_added ) {
 
60
  add_action( 'wp_footer', [ $this, 'add_extra_to_form' ], 99 );
61
  $this->script_added = true;
62
  }
67
  <script>
68
  (function() {
69
  var form_ids = [ <?php echo join( ", ", $this->form_ids ); ?> ];
70
+
71
  nfRadio.channel( "forms" ).on( "before:submit", function( e ) {
72
  if( form_ids.indexOf( +e.id ) === -1 ) return;
73
 
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.8.0
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
@@ -119,6 +119,10 @@ Yes, that's what does the magic and keeps spam bots out.
119
 
120
  == Changelog ==
121
 
 
 
 
 
122
  = 4.8.0 =
123
 
124
  * Added filter & seach options to admin tables
5
  Requires at least: 5.2
6
  Tested up to: 5.4.2
7
  Requires PHP: 7.1
8
+ Stable tag: 4.8.1
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
119
 
120
  == Changelog ==
121
 
122
+ = 4.8.1 =
123
+
124
+ * Fix for charts not showing up in the dashboard
125
+
126
  = 4.8.0 =
127
 
128
  * Added filter & seach options to admin tables
templates/ip-list.php CHANGED
@@ -36,28 +36,34 @@ $chart_limit = 20;
36
  $cnt++;
37
  if ( $cnt > $chart_limit ) { break; }
38
  ?>
39
- <li>
 
40
  <?php if ( ! empty( $ary['country'] ) ): ?>
41
  <img class="wpzerospam-country-flag" width="16" src="https://hatscripts.github.io/circle-flags/flags/<?php echo strtolower( $ary['country'] ); ?>.svg" alt="<?php echo wpzerospam_get_location( $ary['country'] ); ?>" />
42
  <?php endif; ?>
43
- <a href="https://whatismyipaddress.com/ip/<?php echo $ip; ?>" target="_blank" rel="noopener noreferrer" class="wpzerospam-list-cell"><strong><?php echo $ip; ?></strong></a>
44
- <span class="wpzerospam-list-cell">
45
- <?php if ( ! empty( $ary['country'] ) ): ?>
46
- <?php echo wpzerospam_get_location( $ary['country'] ); ?>
47
- <?php endif; ?>
48
  </span>
49
- <span class="wpzerospam-list-cell-small">
50
- <?php echo $ary['count']; ?>
 
 
 
 
 
 
 
 
 
 
51
  </span>
52
- <span class="wpzerospam-action">
53
  <?php
54
  $blocked_status = wpzerospam_get_blocked_ips( $ip );
55
  if ( $blocked_status && wpzerospam_is_blocked( $blocked_status ) ):
56
- ?>
57
  <span class="wpzerospam-blocked"><?php _e( 'Blocked', 'wpzerospam' ); ?></span>
58
  <?php else: ?>
59
  <a href="<?php echo admin_url( 'admin.php?page=wordpress-zero-spam-blocked-ips&ip=' . $ip ); ?>">
60
- <?php _e( 'Configure IP Block', 'wpzerospam' ); ?>
61
  </a>
62
  <?php endif; ?>
63
  </span>
36
  $cnt++;
37
  if ( $cnt > $chart_limit ) { break; }
38
  ?>
39
+ <li class="wpzerospam-list-item">
40
+ <span class="wpzerospam-list-cell wpzerospam-list-cell-icon">
41
  <?php if ( ! empty( $ary['country'] ) ): ?>
42
  <img class="wpzerospam-country-flag" width="16" src="https://hatscripts.github.io/circle-flags/flags/<?php echo strtolower( $ary['country'] ); ?>.svg" alt="<?php echo wpzerospam_get_location( $ary['country'] ); ?>" />
43
  <?php endif; ?>
 
 
 
 
 
44
  </span>
45
+ <span class="wpzerospam-list-cell wpzerospam-list-cell-ip">
46
+ <a href="https://whatismyipaddress.com/ip/<?php echo $ip; ?>" target="_blank" rel="noopener noreferrer"><strong><?php echo $ip; ?></strong></a>
47
+ </span>
48
+ <span class="wpzerospam-list-cell wpzerospam-list-cell-country<?php if ( empty( $ary['country'] ) ): ?> wpzerospam-list-cell-na<?php endif; ?>">
49
+ <?php if ( ! empty( $ary['country'] ) ): ?>
50
+ <?php echo wpzerospam_get_location( $ary['country'] ); ?>
51
+ <?php else: ?>
52
+ N/A
53
+ <?php endif; ?>
54
+ </span>
55
+ <span class="wpzerospam-list-cell wpzerospam-list-cell-count">
56
+ <?php echo number_format( $ary['count'], 0 ); ?>
57
  </span>
58
+ <span class="wpzerospam-list-cell wpzerospam-list-cell-action">
59
  <?php
60
  $blocked_status = wpzerospam_get_blocked_ips( $ip );
61
  if ( $blocked_status && wpzerospam_is_blocked( $blocked_status ) ):
62
+ ?>
63
  <span class="wpzerospam-blocked"><?php _e( 'Blocked', 'wpzerospam' ); ?></span>
64
  <?php else: ?>
65
  <a href="<?php echo admin_url( 'admin.php?page=wordpress-zero-spam-blocked-ips&ip=' . $ip ); ?>">
66
+ <?php _e( 'Block IP', 'wpzerospam' ); ?>
67
  </a>
68
  <?php endif; ?>
69
  </span>
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.8.0
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.2
19
  * Author: Ben Marshall
@@ -31,7 +31,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
31
  // Define plugin constants
32
  define( 'WORDPRESS_ZERO_SPAM', __FILE__ );
33
  define( 'WORDPRESS_ZERO_SPAM_DB_VERSION', '0.2' );
34
- define( 'WORDPRESS_ZERO_SPAM_VERSION', '4.8.0' );
35
 
36
  /**
37
  * Helpers
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.8.1
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.2
19
  * Author: Ben Marshall
31
  // Define plugin constants
32
  define( 'WORDPRESS_ZERO_SPAM', __FILE__ );
33
  define( 'WORDPRESS_ZERO_SPAM_DB_VERSION', '0.2' );
34
+ define( 'WORDPRESS_ZERO_SPAM_VERSION', '4.8.1' );
35
 
36
  /**
37
  * Helpers