WordPress Zero Spam - Version 4.5.0

Version Description

  • Added integration with the Stop Forum Spam known spammy IPs
  • Fixed issue with Gravity Forms not being enabled by default
Download this release

Release Info

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

Code changes from version 4.4.1 to 4.5.0

assets/css/admin-dashboard.css CHANGED
@@ -75,55 +75,6 @@
75
  display: block;
76
  }
77
 
78
- .wpzerospam-details-modal {
79
- background: rgba(0, 0, 0, 0.8);
80
- cursor: pointer;
81
- display: none;
82
- height: 100%;
83
- left: 0;
84
- position: fixed;
85
- top: 0;
86
- width: 100%;
87
- z-index: 9;
88
- }
89
-
90
- .wpzerospam-details-modal.is-active {
91
- display: block;
92
- }
93
-
94
- .wpzerospam-details-modal-inner {
95
- background-color: #fff;
96
- border: 1px solid #ccd0d4;
97
- border-radius: 5px;
98
- box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
99
- cursor: default;
100
- left: 50%;
101
- overflow: auto;
102
- max-height: 500px;
103
- max-width: 800px;
104
- padding: 30px;
105
- position: fixed;
106
- top: 50%;
107
- transform: translate(-50%, -50%);
108
- z-index: 99;
109
- width: 95%
110
- }
111
-
112
- .wpzerospam-details-item {
113
- display: flex;
114
- padding: 5px;
115
- }
116
-
117
- .wpzerospam-details-label {
118
- flex-shrink: 0;
119
- font-weight: bold;
120
- width: 150px;
121
- }
122
-
123
- .wpzerospam-details-data {
124
- flex-grow: 1;
125
- }
126
-
127
  .wpzerospam-boxes {
128
  display: flex;
129
  flex-wrap: wrap;
75
  display: block;
76
  }
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  .wpzerospam-boxes {
79
  display: flex;
80
  flex-wrap: wrap;
assets/css/admin-tables.css ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wpzerospam-details-modal {
2
+ background: rgba(0, 0, 0, 0.8);
3
+ cursor: pointer;
4
+ display: none;
5
+ height: 100%;
6
+ left: 0;
7
+ position: fixed;
8
+ top: 0;
9
+ width: 100%;
10
+ z-index: 9;
11
+ }
12
+
13
+ .wpzerospam-details-modal.is-active {
14
+ display: block;
15
+ }
16
+
17
+ .wpzerospam-details-modal-inner {
18
+ background-color: #fff;
19
+ border: 1px solid #ccd0d4;
20
+ border-radius: 5px;
21
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
22
+ cursor: default;
23
+ left: 50%;
24
+ overflow: auto;
25
+ max-height: 500px;
26
+ max-width: 800px;
27
+ padding: 30px;
28
+ position: fixed;
29
+ top: 50%;
30
+ transform: translate(-50%, -50%);
31
+ z-index: 99;
32
+ width: 95%
33
+ }
34
+
35
+ .wpzerospam-details-item {
36
+ display: flex;
37
+ padding: 5px;
38
+ }
39
+
40
+ .wpzerospam-details-label {
41
+ flex-shrink: 0;
42
+ font-weight: bold;
43
+ width: 150px;
44
+ }
45
+
46
+ .wpzerospam-details-data {
47
+ flex-grow: 1;
48
+ }
assets/js/{admin-dashboard.js → admin-tables.js} RENAMED
File without changes
classes/class-wpzerospam-blacklisted-table.php ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WordPress Zero Spam blacklisted table
4
+ *
5
+ * @package WordPressZeroSpam
6
+ * @since 4.0.0
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
10
+
11
+ if ( ! class_exists( 'WP_List_Table' ) ) {
12
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
13
+ }
14
+
15
+ class WPZeroSpam_Blacklisted_Table extends WP_List_Table {
16
+ function __construct() {
17
+ global $status, $page;
18
+
19
+ $args = [
20
+ 'singular' => __( 'Blacklist', 'wpzerospam' ),
21
+ 'plural' => __( 'Blacklist IPs', 'wpzerospam' ),
22
+ 'ajax' => true
23
+ ];
24
+ parent::__construct( $args );
25
+ }
26
+
27
+ // Register columns
28
+ function get_columns() {
29
+ // Render a checkbox instead of text
30
+ $columns = [
31
+ 'cb' => '<input type="checkbox" />',
32
+ 'last_updated' => __( 'Last Updated', 'wpzerospam' ),
33
+ 'user_ip' => __( 'IP Address', 'wpzerospam' ),
34
+ 'service' => __( 'Service', 'wpzerospam' ),
35
+ 'details' => __( 'Details', 'wpzerospam' )
36
+ ];
37
+
38
+ return $columns;
39
+ }
40
+
41
+ // Sortable columns
42
+ function get_sortable_columns() {
43
+ $sortable_columns = [
44
+ 'last_updated' => [ 'last_updated', false ],
45
+ 'user_ip' => [ 'user_ip', false ],
46
+ 'service' => [ 'service', false ],
47
+ ];
48
+
49
+ return $sortable_columns;
50
+ }
51
+
52
+ // Checkbox column
53
+ function column_cb( $item ){
54
+ return sprintf(
55
+ '<input type="checkbox" name="%1$s[]" value="%2$s" />',
56
+ /*$1%s*/ 'ids',
57
+ /*$2%s*/ $item->blacklist_id
58
+ );
59
+ }
60
+
61
+ // Render column
62
+ function column_default( $item, $column_name ) {
63
+ switch( $column_name ) {
64
+ case 'service':
65
+ switch( $item->blacklist_service ) {
66
+ case 'stopforumspam':
67
+ return '<a href="https://www.stopforumspam.com/" target="_blank" rel="noopener noreferrer">Stop Forum Spam</a>';
68
+ break;
69
+ default:
70
+ return $item->blacklist_service;
71
+ }
72
+ break;
73
+ case 'user_ip':
74
+ return '<a href="https://whatismyipaddress.com/ip/' . $item->user_ip .'" target="_blank" rel="noopener noreferrer">' . $item->user_ip . '</a>';
75
+ break;
76
+ case 'last_updated':
77
+ return date( 'M j, Y g:ia' , strtotime( $item->last_updated ) );
78
+ break;
79
+ case 'details':
80
+ if ( empty( $item->blacklist_data ) ) { return __( 'No details available.', 'wpzerospam' ); }
81
+ ob_start();
82
+ ?>
83
+ <button class="button action wpzerospam-details-trigger" data-id="<?php echo $item->blacklist_id; ?>"><?php _e( 'View Details', 'wpzerospam' ); ?></button>
84
+ <div class="wpzerospam-details-modal" id="wpzerospam-details-modal-<?php echo $item->blacklist_id; ?>">
85
+ <div class="wpzerospam-details-modal-inner">
86
+ <?php
87
+ $item->blacklist_data = json_decode( $item->blacklist_data, true );
88
+
89
+ echo '<div class="wpzerospam-details-item">';
90
+ echo '<div class="wpzerospam-details-label">' . __( 'Detected Spam IP', 'wpzerospam' ) . '</div>';
91
+ echo '<div class="wpzerospam-details-data">' . '<a href="https://whatismyipaddress.com/ip/' . $item->user_ip .'" target="_blank" rel="noopener noreferrer">' . $item->user_ip . '</a>' . '</div>';
92
+ echo '</div>';
93
+
94
+ echo '<div class="wpzerospam-details-item">';
95
+ echo '<div class="wpzerospam-details-label">' . __( 'Last Updated', 'wpzerospam' ) . '</div>';
96
+ echo '<div class="wpzerospam-details-data">' . date( 'M j, Y g:ia' , strtotime( $item->last_updated ) ) . '</div>';
97
+ echo '</div>';
98
+
99
+ echo '<div class="wpzerospam-details-item">';
100
+ echo '<div class="wpzerospam-details-label">' . __( 'Service', 'wpzerospam' ) . '</div>';
101
+ echo '<div class="wpzerospam-details-data">' . $item->blacklist_service . '</div>';
102
+ echo '</div>';
103
+
104
+ if ( ! empty( $item->blacklist_data ) ) {
105
+ foreach( $item->blacklist_data as $key => $value ):
106
+ if ( ! $value ) { continue; }
107
+ switch( $key ):
108
+ default:
109
+ echo '<div class="wpzerospam-details-item">';
110
+ echo '<div class="wpzerospam-details-label">' . $key . '</div>';
111
+ echo '<div class="wpzerospam-details-data">' . json_encode( $value ) . '</div>';
112
+ echo '</div>';
113
+ endswitch;
114
+ endforeach;
115
+ };
116
+ ?>
117
+ </div>
118
+ </div>
119
+ <?php
120
+ return ob_get_clean();
121
+ break;
122
+ }
123
+ }
124
+
125
+ // Register bulk actions
126
+ function get_bulk_actions() {
127
+ $actions = [ 'delete' => __( 'Delete', 'wpzerospam' ) ];
128
+
129
+ return $actions;
130
+ }
131
+
132
+ /**
133
+ * Define which columns are hidden
134
+ *
135
+ * @return Array
136
+ */
137
+ public function get_hidden_columns() {
138
+ return [];
139
+ }
140
+
141
+ /**
142
+ * Allows you to sort the data by the variables set in the $_GET
143
+ *
144
+ * @return Mixed
145
+ */
146
+ private function sort_data( $a, $b ) {
147
+ // Set defaults
148
+ $orderby = 'last_updated';
149
+ $order = 'desc';
150
+
151
+ // If orderby is set, use this as the sort column
152
+ if( ! empty( $_GET['orderby'] ) ) {
153
+ $orderby = $_GET['orderby'];
154
+ }
155
+
156
+ // If order is set use this as the order
157
+ if ( ! empty($_GET['order'] ) ) {
158
+ $order = $_GET['order'];
159
+ }
160
+
161
+ $result = strcmp( $a->$orderby, $b->$orderby );
162
+
163
+ if ( $order === 'asc' ) {
164
+ return $result;
165
+ }
166
+
167
+ return -$result;
168
+ }
169
+
170
+ // Get results
171
+ function prepare_items($args = []) {
172
+ $this->process_bulk_action();
173
+
174
+ $columns = $this->get_columns();
175
+ $hidden = $this->get_hidden_columns();
176
+ $sortable = $this->get_sortable_columns();
177
+
178
+ $data = wpzerospam_get_blacklist();
179
+ usort( $data, [ &$this, 'sort_data' ] );
180
+
181
+ $per_page = 50;
182
+ $current_page = $this->get_pagenum();
183
+ $total_items = count( $data );
184
+
185
+ $this->set_pagination_args([
186
+ 'total_items' => $total_items,
187
+ 'per_page' => $per_page
188
+ ]);
189
+
190
+ $data = array_slice ( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
191
+
192
+ $this->_column_headers = [ $columns, $hidden, $sortable ];
193
+ $this->items = $data;
194
+ }
195
+
196
+ // Process bulk actions
197
+ function process_bulk_action() {
198
+ global $wpdb;
199
+
200
+ $ids = ( isset( $_REQUEST['ids'] ) ) ? $_REQUEST['ids'] : '';
201
+
202
+ switch( $this->current_action() ) {
203
+ // Delete
204
+ case 'delete':
205
+ // Delete query
206
+ $nonce = ( isset( $_POST['wpzerospam_nonce'] ) ) ? $_POST['wpzerospam_nonce'] : '';
207
+ if ( ! wp_verify_nonce( $nonce, 'wpzerospam_nonce' ) ) return false;
208
+
209
+ if ( ! empty ( $ids ) && is_array( $ids ) ) {
210
+ // Delete query
211
+ foreach( $ids as $k => $blacklist_id ) {
212
+ $wpdb->delete( wpzerospam_tables( 'blacklist' ), [ 'blacklist_id' => $blacklist_id ] );
213
+ }
214
+ }
215
+ break;
216
+ }
217
+ }
218
+ }
inc/admin.php CHANGED
@@ -25,6 +25,15 @@ function wpzerospam_admin_menu() {
25
  'wpzerospam_blocked_ips_page'
26
  );
27
 
 
 
 
 
 
 
 
 
 
28
  add_submenu_page(
29
  'wordpress-zero-spam',
30
  __( 'WordPress Zero Spam Settings', 'wpzerospam' ),
@@ -36,6 +45,41 @@ function wpzerospam_admin_menu() {
36
  }
37
  add_action( 'admin_menu', 'wpzerospam_admin_menu' );
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  add_action( 'admin_action_add_blocked_ip', 'wpzerospam_add_blocked_ip_action' );
40
  function wpzerospam_add_blocked_ip_action() {
41
  if ( ! empty( $_POST ) ) {
@@ -305,6 +349,11 @@ function wpzerospam_validate_options( $input ) {
305
  if ( empty( $input['verify_fluentform'] ) ) {
306
  $input['verify_fluentform'] = 'disabled';
307
  }
 
 
 
 
 
308
  return $input;
309
  }
310
 
@@ -333,7 +382,28 @@ function wpzerospam_admin_init() {
333
  register_setting( 'wpzerospam', 'wpzerospam', 'wpzerospam_validate_options' );
334
 
335
  add_settings_section( 'wpzerospam_general_settings', __( 'General Settings', 'wpzerospam' ), 'wpzerospam_general_settings_cb', 'wpzerospam' );
336
- add_settings_section( 'wpzerospam_spam_checks', __( 'Spam Checks', 'wpzerospam' ), 'wpzerospam_spam_checks_cb', 'wpzerospam' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
 
338
  // Determines is spam detected IPs should automatically be blocked
339
  add_settings_field( 'auto_block_ips', __( 'Auto-block IPs', 'wpzerospam' ), 'wpzerospam_field_cb', 'wpzerospam', 'wpzerospam_general_settings', [
@@ -442,16 +512,6 @@ function wpzerospam_admin_init() {
442
  ]
443
  ]);
444
 
445
- if ( 'enabled' == $options['log_spam'] ) {
446
- // Redirect URL for spam detections
447
- add_settings_field( 'ipstack_api', __( 'ipstack API Key', 'wpzerospam' ), 'wpzerospam_field_cb', 'wpzerospam', 'wpzerospam_general_settings', [
448
- 'label_for' => 'ipstack_api',
449
- 'type' => 'text',
450
- 'class' => 'regular-text',
451
- 'desc' => 'Enter your <a href="https://ipstack.com/" target="_blank">ipstack API key</a> to enable location-based statistics.',
452
- ]);
453
- }
454
-
455
  // Comment spam check
456
  add_settings_field( 'verify_comments', __( 'Verify Comments', 'wpzerospam' ), 'wpzerospam_field_cb', 'wpzerospam', 'wpzerospam_spam_checks', [
457
  'label_for' => 'verify_comments',
25
  'wpzerospam_blocked_ips_page'
26
  );
27
 
28
+ add_submenu_page(
29
+ 'wordpress-zero-spam',
30
+ __( 'Blacklisted IPs', 'wpzerospam' ),
31
+ __( 'Blacklisted IPs', 'wpzerospam' ),
32
+ 'manage_options',
33
+ 'wordpress-zero-spam-blacklisted',
34
+ 'wpzerospam_blacklist_page'
35
+ );
36
+
37
  add_submenu_page(
38
  'wordpress-zero-spam',
39
  __( 'WordPress Zero Spam Settings', 'wpzerospam' ),
45
  }
46
  add_action( 'admin_menu', 'wpzerospam_admin_menu' );
47
 
48
+ function wpzerospam_blacklist_page() {
49
+ if ( ! current_user_can( 'manage_options' ) ) { return; }
50
+ ?>
51
+ <div class="wrap">
52
+ <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
53
+ <?php
54
+ /**
55
+ * Blocked IP table
56
+ */
57
+ require plugin_dir_path( WORDPRESS_ZERO_SPAM ) . '/classes/class-wpzerospam-blacklisted-table.php';
58
+
59
+ $table_data = new WPZeroSpam_Blacklisted_Table();
60
+
61
+ // Setup page parameters
62
+ $current_page = $table_data->get_pagenum();
63
+ $current_page = ( isset( $current_page ) ) ? $current_page : 1;
64
+ $paged = ( isset( $_GET['page'] ) ) ? absint( $_GET['page'] ) : $current_page;
65
+ $paged = ( isset( $_GET['paged'] ) ) ? absint( $_GET['paged'] ) : $current_page;
66
+ $paged = ( isset( $args['paged'] ) ) ? $args['paged'] : $paged;
67
+
68
+ // Fetch, prepare, sort, and filter our data...
69
+ $table_data->prepare_items();
70
+ ?>
71
+ <form id="log-table" method="post">
72
+ <?php wp_nonce_field( 'wpzerospam_nonce', 'wpzerospam_nonce' ); ?>
73
+
74
+ <?php # Current page ?>
75
+ <input type="hidden" name="paged" value="<?php echo $paged; ?>" />
76
+
77
+ <?php $table_data->display(); ?>
78
+ </form>
79
+ </div>
80
+ <?php
81
+ }
82
+
83
  add_action( 'admin_action_add_blocked_ip', 'wpzerospam_add_blocked_ip_action' );
84
  function wpzerospam_add_blocked_ip_action() {
85
  if ( ! empty( $_POST ) ) {
349
  if ( empty( $input['verify_fluentform'] ) ) {
350
  $input['verify_fluentform'] = 'disabled';
351
  }
352
+
353
+ if ( empty( $input['stop_forum_spam'] ) ) {
354
+ $input['stop_forum_spam'] = 'disabled';
355
+ }
356
+
357
  return $input;
358
  }
359
 
382
  register_setting( 'wpzerospam', 'wpzerospam', 'wpzerospam_validate_options' );
383
 
384
  add_settings_section( 'wpzerospam_general_settings', __( 'General Settings', 'wpzerospam' ), 'wpzerospam_general_settings_cb', 'wpzerospam' );
385
+ add_settings_section( 'wpzerospam_spam_checks', __( 'Integrations & Third-party APIs', 'wpzerospam' ), 'wpzerospam_spam_checks_cb', 'wpzerospam' );
386
+
387
+ if ( 'enabled' == $options['log_spam'] ) {
388
+ // Redirect URL for spam detections
389
+ add_settings_field( 'ipstack_api', __( 'ipstack API Key', 'wpzerospam' ), 'wpzerospam_field_cb', 'wpzerospam', 'wpzerospam_spam_checks', [
390
+ 'label_for' => 'ipstack_api',
391
+ 'type' => 'text',
392
+ 'class' => 'regular-text',
393
+ 'desc' => 'Enter your <a href="https://ipstack.com/" target="_blank">ipstack API key</a> to enable location-based statistics.',
394
+ ]);
395
+ }
396
+
397
+ // Enables the ability to check IPs against Stop Forum Spam blacklists.
398
+ add_settings_field( 'stop_forum_spam', __( 'Stop Forum Spam', 'wpzerospam' ), 'wpzerospam_field_cb', 'wpzerospam', 'wpzerospam_spam_checks', [
399
+ 'label_for' => 'stop_forum_spam',
400
+ 'type' => 'checkbox',
401
+ 'multi' => false,
402
+ 'desc' => 'Checks user IPs against <a href="https://www.stopforumspam.com/" target="_blank" rel="noopener noreferrer">Stop Forum Spam</a>\'s blacklist.',
403
+ 'options' => [
404
+ 'enabled' => __( 'Enabled', 'wpzerospam' )
405
+ ]
406
+ ]);
407
 
408
  // Determines is spam detected IPs should automatically be blocked
409
  add_settings_field( 'auto_block_ips', __( 'Auto-block IPs', 'wpzerospam' ), 'wpzerospam_field_cb', 'wpzerospam', 'wpzerospam_general_settings', [
512
  ]
513
  ]);
514
 
 
 
 
 
 
 
 
 
 
 
515
  // Comment spam check
516
  add_settings_field( 'verify_comments', __( 'Verify Comments', 'wpzerospam' ), 'wpzerospam_field_cb', 'wpzerospam', 'wpzerospam_spam_checks', [
517
  'label_for' => 'verify_comments',
inc/helpers.php CHANGED
@@ -232,8 +232,9 @@ if ( ! function_exists( 'wpzerospam_tables' ) ) {
232
  global $wpdb;
233
 
234
  $tables = [
235
- 'log' => $wpdb->prefix . 'wpzerospam_log',
236
- 'blocked' => $wpdb->prefix . 'wpzerospam_blocked'
 
237
  ];
238
 
239
  if ( ! $key ) {
@@ -408,8 +409,8 @@ if ( ! function_exists( 'wpzerospam_options' ) ) {
408
  $options['verify_cf7'] = 'enabled';
409
  }
410
 
411
- if ( empty( $options['verify_gforms'] ) ) {
412
- $options['verify_gforms'] = 'enabled';
413
  }
414
 
415
  if ( empty( $options['verify_ninja_forms'] ) ) {
@@ -428,6 +429,10 @@ if ( ! function_exists( 'wpzerospam_options' ) ) {
428
  $options['verify_fluentform'] = 'enabled';
429
  }
430
 
 
 
 
 
431
  return $options;
432
  }
433
  }
@@ -477,19 +482,38 @@ if ( ! function_exists( 'wpzerospam_check_access' ) ) {
477
  return $access;
478
  }
479
 
480
- $options = wpzerospam_options();
 
 
481
 
482
  // Check if the current user's IP address has been blocked
483
- $ip = wpzerospam_ip();
484
- $is_blocked = wpzerospam_get_blocked_ips( $ip );
485
-
486
  if ( ! $is_blocked ) {
487
- return $access;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  }
489
 
 
 
490
  if ( 'permanent' == $is_blocked->blocked_type ) {
491
  $access['access'] = false;
492
- $access['ip'] = $ip;
493
  $access['reason'] = $is_blocked->reason;
494
  } else {
495
  $todays_date = new DateTime( current_time( 'mysql' ) );
@@ -567,3 +591,170 @@ if ( ! function_exists( 'wpzerospam_current_url' ) ) {
567
  return $url;
568
  }
569
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  global $wpdb;
233
 
234
  $tables = [
235
+ 'log' => $wpdb->prefix . 'wpzerospam_log',
236
+ 'blocked' => $wpdb->prefix . 'wpzerospam_blocked',
237
+ 'blacklist' => $wpdb->prefix . 'wpzerospam_blacklist'
238
  ];
239
 
240
  if ( ! $key ) {
409
  $options['verify_cf7'] = 'enabled';
410
  }
411
 
412
+ if ( empty( $options['verify_gform'] ) ) {
413
+ $options['verify_gform'] = 'enabled';
414
  }
415
 
416
  if ( empty( $options['verify_ninja_forms'] ) ) {
429
  $options['verify_fluentform'] = 'enabled';
430
  }
431
 
432
+ if ( empty( $options['stop_forum_spam'] ) ) {
433
+ $options['stop_forum_spam'] = 'enabled';
434
+ }
435
+
436
  return $options;
437
  }
438
  }
482
  return $access;
483
  }
484
 
485
+ $options = wpzerospam_options();
486
+ $ip = wpzerospam_ip();
487
+ $access['ip'] = $ip;
488
 
489
  // Check if the current user's IP address has been blocked
490
+ $is_blocked = wpzerospam_get_blocked_ips( $ip );
 
 
491
  if ( ! $is_blocked ) {
492
+ // IP hasen't been blocked
493
+ // If enabled, check the Stop Forum Spam blacklist
494
+ if ( 'enabled' == $options['stop_forum_spam'] ) {
495
+ $stop_forum_spam_is_spam = wpzerospam_stopforumspam_is_spam( $ip );
496
+ if ( ! $stop_forum_spam_is_spam ) {
497
+ // IP wasn't found in the Stop Forum Spam blacklist
498
+ return $access;
499
+ } else {
500
+ // IP was found in the Stop Forum Spam blacklist
501
+ $access['access'] = false;
502
+ $access['reason'] = 'Stop Forum Spam';
503
+
504
+ return $access;
505
+ }
506
+ } else {
507
+ // Stop Forum Spam blacklist is disabled & the IP wasn't found in the
508
+ // blocked IPs table.
509
+ return $access;
510
+ }
511
  }
512
 
513
+ // IP address was found in the blocked IPs list, determine the type and if
514
+ // it should still be blocked.
515
  if ( 'permanent' == $is_blocked->blocked_type ) {
516
  $access['access'] = false;
 
517
  $access['reason'] = $is_blocked->reason;
518
  } else {
519
  $todays_date = new DateTime( current_time( 'mysql' ) );
591
  return $url;
592
  }
593
  }
594
+
595
+ /**
596
+ * Queries the Stop Forum Spam API
597
+ *
598
+ * @since 4.5.0
599
+ */
600
+ if ( ! function_exists( 'wpzerospam_stopforumspam_request' ) ) {
601
+ function wpzerospam_stopforumspam_request( $ip ) {
602
+ $api_url = 'http://api.stopforumspam.org/api?';
603
+ $params = [ 'ip' => $ip, 'json' => '' ];
604
+ $endpoint = $api_url . http_build_query( $params );
605
+ $response = wp_remote_get( $endpoint );
606
+
607
+ if ( is_array( $response ) && ! is_wp_error( $response ) ) {
608
+ $data = wp_remote_retrieve_body( $response );
609
+ $data = json_decode( $data, true );
610
+ if ( ! empty( $data['success'] ) && ! empty( $data['ip'] ) ) {
611
+ return $data['ip'];
612
+ }
613
+ }
614
+
615
+ return false;
616
+ }
617
+ }
618
+
619
+ /**
620
+ * Add/update blacklisted IP
621
+ *
622
+ * @since 4.5.0
623
+ */
624
+ if ( ! function_exists( 'wpzerospam_update_blacklist' ) ) {
625
+ function wpzerospam_update_blacklist( $data ) {
626
+ global $wpdb;
627
+
628
+ $update = [
629
+ 'last_updated' => current_time( 'mysql' ),
630
+ 'blacklist_data' => []
631
+ ];
632
+
633
+ if ( ! empty( $data['ip'] ) ) {
634
+ $update['user_ip'] = $data['ip'];
635
+ }
636
+
637
+ if ( ! empty( $data['blacklist_service'] ) ) {
638
+ $update['blacklist_service'] = $data['blacklist_service'];
639
+ }
640
+
641
+ if ( ! empty( $data['appears'] ) ) {
642
+ $update['blacklist_data']['appears'] = intval( $data['appears'] );
643
+ }
644
+
645
+ if ( ! empty( $data['confidence'] ) ) {
646
+ $update['blacklist_data']['confidence'] = floatval( $data['confidence'] );
647
+ }
648
+
649
+ if ( ! empty( $data['frequency'] ) ) {
650
+ $update['blacklist_data']['frequency'] = floatval( $data['frequency'] );
651
+ }
652
+
653
+ if ( ! empty( $data['lastseen'] ) ) {
654
+ $update['blacklist_data']['lastseen'] = floatval( $data['lastseen'] );
655
+ }
656
+
657
+ if ( ! empty( $data['delegated'] ) ) {
658
+ $update['blacklist_data']['delegated'] = floatval( $data['delegated'] );
659
+ }
660
+
661
+ if ( ! empty( $data['asn'] ) ) {
662
+ $update['blacklist_data']['asn'] = floatval( $data['asn'] );
663
+ }
664
+
665
+ if ( ! empty( $data['country'] ) ) {
666
+ $update['blacklist_data']['country'] = floatval( $data['country'] );
667
+ }
668
+
669
+ if ( ! empty( $update['blacklist_data'] ) ) {
670
+ $update['blacklist_data'] = json_encode( $update['blacklist_data'] );
671
+ }
672
+
673
+ if ( ! empty( $data['blacklist_id'] ) ) {
674
+ // Update
675
+ $wpdb->update( wpzerospam_tables( 'blacklist' ), $update, [
676
+ 'blacklist_id' => $data['blacklist_id']
677
+ ]);
678
+ return true;
679
+ }
680
+
681
+ // Insert
682
+ $wpdb->insert( wpzerospam_tables( 'blacklist' ), $update );
683
+ return true;
684
+ }
685
+ }
686
+
687
+ /**
688
+ * Checks the post submission for a valid key
689
+ *
690
+ * @since 4.5.0
691
+ */
692
+ if ( ! function_exists( 'wpzerospam_stopforumspam_is_spam' ) ) {
693
+ function wpzerospam_stopforumspam_is_spam( $ip ) {
694
+ // First check if the IP is already in the blacklist table
695
+ $in_blacklist = wpzerospam_in_blacklist( $ip );
696
+ if ( $in_blacklist ) {
697
+ // Check if the record should be updated
698
+ $last_updated = strtotime( $in_blacklist->last_updated );
699
+ $current_time = current_time( 'timestamp' );
700
+ $expiration = $last_updated + MONTH_IN_SECONDS;
701
+
702
+ if ( $current_time > $expiration ) {
703
+ // Expired, update the record
704
+ $stopforumspam_request = wpzerospam_stopforumspam_request( $ip );
705
+ if ( $stopforumspam_request ) {
706
+ wpzerospam_update_blacklist( $stopforumspam_request );
707
+
708
+ return $stopforumspam_request;
709
+ }
710
+ }
711
+
712
+ return $in_blacklist;
713
+ }
714
+
715
+ // Not in the blacklist, query the Stop Forum Spam API now
716
+ $stopforumspam_request = wpzerospam_stopforumspam_request( $ip );
717
+ if (
718
+ $stopforumspam_request &&
719
+ ! empty( $stopforumspam_request['appears'] ) &&
720
+ 'no' != $stopforumspam_request['appears']
721
+ ) {
722
+ $new_record = $stopforumspam_request;
723
+ $new_record['ip'] = $ip;
724
+ $new_record['blacklist_service'] = 'stopforumspam';
725
+
726
+ wpzerospam_update_blacklist( $new_record );
727
+
728
+ return $new_record;
729
+ }
730
+
731
+ return false;
732
+ }
733
+ }
734
+
735
+ /**
736
+ * Returns a record from the blacklist table if one exists
737
+ *
738
+ * @since 4.5.0
739
+ */
740
+ if ( ! function_exists( 'wpzerospam_in_blacklist' ) ) {
741
+ function wpzerospam_in_blacklist( $ip ) {
742
+ global $wpdb;
743
+
744
+ return $wpdb->get_row($wpdb->prepare(
745
+ 'SELECT * FROM ' . wpzerospam_tables( 'blacklist' ) . ' WHERE user_ip = %s',
746
+ $ip
747
+ ));
748
+ }
749
+ }
750
+
751
+ /**
752
+ * Return all blacklisted IPs in the DB
753
+ */
754
+ if ( ! function_exists( 'wpzerospam_get_blacklist' ) ) {
755
+ function wpzerospam_get_blacklist( $args = [] ) {
756
+ global $wpdb;
757
+
758
+ return $wpdb->get_results( 'SELECT * FROM ' . wpzerospam_tables( 'blacklist' ) );
759
+ }
760
+ }
inc/locations.php CHANGED
@@ -751,7 +751,53 @@ if ( ! function_exists( 'wpzerospam_get_location' ) ) {
751
  ],
752
  'IT' => [
753
  'name' => 'Italy',
754
- 'regions' => []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
  ],
756
  'JM' => [
757
  'name' => 'Jamaica',
@@ -1249,7 +1295,23 @@ if ( ! function_exists( 'wpzerospam_get_location' ) ) {
1249
  ],
1250
  'SG' => [
1251
  'name' => 'Singapore',
1252
- 'regions' => []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1253
  ],
1254
  'SK' => [
1255
  'name' => 'Slovakia',
751
  ],
752
  'IT' => [
753
  'name' => 'Italy',
754
+ 'regions' => [
755
+ '65' => [
756
+ 'name' => 'Abruzzo'
757
+ ],
758
+ '77' => [
759
+ 'name' => 'Basilicata'
760
+ ],
761
+ '78' => [
762
+ 'name' => 'Calabria'
763
+ ],
764
+ '72' => [
765
+ 'name' => 'Campania'
766
+ ],
767
+ '45' => [
768
+ 'name' => 'Emilia-Romagna'
769
+ ],
770
+ '62' => [
771
+ 'name' => 'Lazio'
772
+ ],
773
+ '42' => [
774
+ 'name' => 'Liguria'
775
+ ],
776
+ '25' => [
777
+ 'name' => 'Lombardy'
778
+ ],
779
+ '57' => [
780
+ 'name' => 'Marche'
781
+ ],
782
+ '67' => [
783
+ 'name' => 'Molise'
784
+ ],
785
+ '21' => [
786
+ 'name' => 'Piedmont'
787
+ ],
788
+ '75' => [
789
+ 'name' => 'Apulia'
790
+ ],
791
+ '52' => [
792
+ 'name' => 'Tuscany'
793
+ ],
794
+ '55' => [
795
+ 'name' => 'Umbria'
796
+ ],
797
+ '34' => [
798
+ 'name' => 'Veneto'
799
+ ]
800
+ ]
801
  ],
802
  'JM' => [
803
  'name' => 'Jamaica',
1295
  ],
1296
  'SG' => [
1297
  'name' => 'Singapore',
1298
+ 'regions' => [
1299
+ '01' => [
1300
+ 'name' => 'Central Singapore'
1301
+ ],
1302
+ '02' => [
1303
+ 'name' => 'North East'
1304
+ ],
1305
+ '03' => [
1306
+ 'name' => 'North West'
1307
+ ],
1308
+ '04' => [
1309
+ 'name' => 'South East'
1310
+ ],
1311
+ '05' => [
1312
+ 'name' => 'South West'
1313
+ ]
1314
+ ]
1315
  ],
1316
  'SK' => [
1317
  'name' => 'Slovakia',
inc/scripts.php CHANGED
@@ -11,8 +11,30 @@
11
  */
12
  if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
13
  function wpzerospam_admin_scripts( $hook_suffix ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  // Handle registering & enqueuing scripts based on the current admin page
15
  switch( $hook_suffix ) {
 
 
 
 
16
  case 'toplevel_page_wordpress-zero-spam':
17
  // Enqueue Chart.js for graphs
18
  wp_register_script(
@@ -32,17 +54,6 @@ if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
32
  '2.9.3'
33
  );
34
 
35
- // Enqueue the JS for the WordPress Zero Spam dashboard
36
- wp_enqueue_script(
37
- 'wpzerospam-admin-dashboard',
38
- plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
39
- '/assets/js/admin-dashboard.js',
40
- [ 'jquery', 'wpzerospam-charts' ],
41
- WORDPRESS_ZERO_SPAM_VERSION,
42
- true
43
- );
44
-
45
- // Enqueue the CSS for the WordPress Zero Spam dashboard
46
  wp_enqueue_style(
47
  'wpzerospam-admin-dashboard',
48
  plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
@@ -50,6 +61,9 @@ if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
50
  false,
51
  WORDPRESS_ZERO_SPAM_VERSION
52
  );
 
 
 
53
  break;
54
  case 'wp-zero-spam_page_wordpress-zero-spam-blocked-ips':
55
  // Enqueue the JS for the WordPress Zero Spam blocked IPs page
@@ -64,7 +78,7 @@ if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
64
 
65
  // Enqueue the CSS for the WordPress Zero Spam blocked IPs page
66
  wp_enqueue_style(
67
- 'wpzerospam-admin-dashboard',
68
  plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
69
  '/assets/css/admin-blocked-ips.css',
70
  false,
11
  */
12
  if ( ! function_exists( 'wpzerospam_admin_scripts' ) ) {
13
  function wpzerospam_admin_scripts( $hook_suffix ) {
14
+ wp_register_script(
15
+ 'wpzerospam-admin-tables',
16
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
17
+ '/assets/js/admin-tables.js',
18
+ [ 'jquery' ],
19
+ WORDPRESS_ZERO_SPAM_VERSION,
20
+ true
21
+ );
22
+
23
+ wp_register_style(
24
+ 'wpzerospam-admin-tables',
25
+ plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
26
+ '/assets/css/admin-tables.css',
27
+ false,
28
+ WORDPRESS_ZERO_SPAM_VERSION
29
+ );
30
+
31
+
32
  // Handle registering & enqueuing scripts based on the current admin page
33
  switch( $hook_suffix ) {
34
+ case 'wp-zero-spam_page_wordpress-zero-spam-blacklisted':
35
+ wp_enqueue_script( 'wpzerospam-admin-tables' );
36
+ wp_enqueue_style( 'wpzerospam-admin-tables' );
37
+ break;
38
  case 'toplevel_page_wordpress-zero-spam':
39
  // Enqueue Chart.js for graphs
40
  wp_register_script(
54
  '2.9.3'
55
  );
56
 
 
 
 
 
 
 
 
 
 
 
 
57
  wp_enqueue_style(
58
  'wpzerospam-admin-dashboard',
59
  plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
61
  false,
62
  WORDPRESS_ZERO_SPAM_VERSION
63
  );
64
+
65
+ wp_enqueue_script( 'wpzerospam-admin-tables' );
66
+ wp_enqueue_style( 'wpzerospam-admin-tables' );
67
  break;
68
  case 'wp-zero-spam_page_wordpress-zero-spam-blocked-ips':
69
  // Enqueue the JS for the WordPress Zero Spam blocked IPs page
78
 
79
  // Enqueue the CSS for the WordPress Zero Spam blocked IPs page
80
  wp_enqueue_style(
81
+ 'wpzerospam-admin-block_ips',
82
  plugin_dir_url( WORDPRESS_ZERO_SPAM ) .
83
  '/assets/css/admin-blocked-ips.css',
84
  false,
integrations/fluentform/fluentform.php CHANGED
@@ -15,7 +15,7 @@ if ( ! function_exists( 'wpzerospam_fluentform_validate' ) ) {
15
  return;
16
  }
17
 
18
- do_action( 'wpzerospam_cf7_spam' );
19
 
20
  $data = [
21
  'insertData' => $insertData,
15
  return;
16
  }
17
 
18
+ do_action( 'wpzerospam_fluentform_spam' );
19
 
20
  $data = [
21
  'insertData' => $insertData,
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.4.1
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
@@ -43,7 +43,9 @@ WordPress Zero Spam was initially built based on the work by [David Walsh](http:
43
  * [Contact Form by WPForms](https://wordpress.org/plugins/wpforms-lite/) submissions
44
  * [WP Fluent Forms](https://wordpress.org/plugins/fluentform/) submissions
45
 
46
- <small>This plugin does not support with Jetpack Comments. For more information, see [https://wordpress.org/support/topic/incompatible-with-jetpack-comments](https://wordpress.org/support/topic/incompatible-with-jetpack-comments).</small>
 
 
47
 
48
  Have a question, comment or suggestion? Feel free to [contact me](https://benmarshall.me/contact/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=wordpress_zero_spam), follow me [on Twitter](https://twitter.com/bmarshall0511) or [visit my site](https://benmarshall.me/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=wordpress_zero_spam).
49
 
@@ -90,9 +92,21 @@ Yes, that's what does the magic and keeps spam bots out.
90
  * `wpzerospam_ninja_forms_spam` - Fires when a spam submission is made with a Ninja Form.
91
  * `wpzerospam_bp_registration_spam` - Fires when a BuddyPress spam registration is detected.
92
  * `wpzerospam_wpform_spam` - Fires when a spam submission is made with a WPForm.
 
 
 
 
 
 
 
93
 
94
  == Changelog ==
95
 
 
 
 
 
 
96
  = 4.4.1 =
97
 
98
  * Fix for Gravity Forms not submitting
5
  Requires at least: 5.2
6
  Tested up to: 5.4.2
7
  Requires PHP: 7.1
8
+ Stable tag: 4.5.0
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
43
  * [Contact Form by WPForms](https://wordpress.org/plugins/wpforms-lite/) submissions
44
  * [WP Fluent Forms](https://wordpress.org/plugins/fluentform/) submissions
45
 
46
+ This plugin does not support Jetpack Comments. For more information, see [https://wordpress.org/support/topic/incompatible-with-jetpack-comments](https://wordpress.org/support/topic/incompatible-with-jetpack-comments). If you're running something other than one of the supported plugins above, it won't detect spam submissions without some additional integration.
47
+
48
+ Feel free to report any [bugs/feature requests here](https://github.com/bmarshall511/wordpress-zero-spam/issues).
49
 
50
  Have a question, comment or suggestion? Feel free to [contact me](https://benmarshall.me/contact/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=wordpress_zero_spam), follow me [on Twitter](https://twitter.com/bmarshall0511) or [visit my site](https://benmarshall.me/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=wordpress_zero_spam).
51
 
92
  * `wpzerospam_ninja_forms_spam` - Fires when a spam submission is made with a Ninja Form.
93
  * `wpzerospam_bp_registration_spam` - Fires when a BuddyPress spam registration is detected.
94
  * `wpzerospam_wpform_spam` - Fires when a spam submission is made with a WPForm.
95
+ * `wpzerospam_fluentform_spam` - Fires when a spam submission is made with a WP Fluent Form
96
+
97
+ == Screenshots ==
98
+
99
+ 1. WordPress Zero Spam dashboard
100
+ 2. WordPress Zero Spam blocked IPs
101
+ 3. WordPress Zero Spam settings
102
 
103
  == Changelog ==
104
 
105
+ = 4.5.0 =
106
+
107
+ * Added integration with the Stop Forum Spam known spammy IPs
108
+ * Fixed issue with Gravity Forms not being enabled by default
109
+
110
  = 4.4.1 =
111
 
112
  * Fix for Gravity Forms not submitting
templates/spam-line-chart.php CHANGED
@@ -40,9 +40,13 @@
40
  labels: <?php echo json_encode( $labels ); ?>,
41
  datasets: [{
42
  data: <?php echo json_encode( $data ); ?>,
43
- backgroundColor: 'rgba(99, 0, 13, 0.1)',
44
  borderColor: '#63000D',
45
- fill: true,
 
 
 
 
46
  }],
47
  },
48
  options: {
40
  labels: <?php echo json_encode( $labels ); ?>,
41
  datasets: [{
42
  data: <?php echo json_encode( $data ); ?>,
43
+ backgroundColor: 'rgba(88, 0, 15, 0.5)',
44
  borderColor: '#63000D',
45
+ borderWidth: 4,
46
+ pointBorderWidth: 2,
47
+ pointBackgroundColor: '#58000f',
48
+ pointRadius: 5,
49
+ fill: false,
50
  }],
51
  },
52
  options: {
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.4.1
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.2
19
  * Author: Ben Marshall
@@ -30,8 +30,8 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
30
 
31
  // Define plugin constants
32
  define( 'WORDPRESS_ZERO_SPAM', __FILE__ );
33
- define( 'WORDPRESS_ZERO_SPAM_DB_VERSION', '0.1' );
34
- define( 'WORDPRESS_ZERO_SPAM_VERSION', '4.4.1' );
35
 
36
  /**
37
  * Helpers
@@ -53,36 +53,54 @@ function wpzerospam_install() {
53
  $installed_db_version = get_option( 'wpzerospam_db_version' );
54
 
55
  if ( $installed_db_version != WORDPRESS_ZERO_SPAM_DB_VERSION ) {
56
- $log_table = wpzerospam_tables( 'log' );
57
- $blocked_table = wpzerospam_tables( 'blocked' );
58
-
59
- $sql = "CREATE TABLE $log_table (
60
- log_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
61
- log_type VARCHAR(255) NOT NULL,
62
- user_ip VARCHAR(255) NOT NULL,
63
- date_recorded DATETIME NOT NULL,
64
- page_url VARCHAR(255) NULL DEFAULT NULL,
65
- submission_data LONGTEXT NULL DEFAULT NULL,
66
- country VARCHAR(2) NULL DEFAULT NULL,
67
- region VARCHAR(255) NULL DEFAULT NULL,
68
- city VARCHAR(255) NULL DEFAULT NULL,
69
- latitude VARCHAR(255) NULL DEFAULT NULL,
70
- longitude VARCHAR(255) NULL DEFAULT NULL,
71
- PRIMARY KEY (`log_id`)) $charset_collate;";
72
-
73
- $sql .= "CREATE TABLE $blocked_table (
74
- blocked_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
75
- blocked_type ENUM('permanent','temporary') NOT NULL DEFAULT 'temporary',
76
- user_ip VARCHAR(255) NOT NULL,
77
- date_added DATETIME NOT NULL,
78
- start_block DATETIME NULL DEFAULT NULL,
79
- end_block DATETIME NULL DEFAULT NULL,
80
- reason VARCHAR(255) NULL DEFAULT NULL,
81
- attempts BIGINT UNSIGNED NOT NULL,
82
- PRIMARY KEY (`blocked_id`)) $charset_collate;";
83
-
84
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
85
- dbDelta( $sql );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  update_option( 'wpzerospam_db_version', WORDPRESS_ZERO_SPAM_DB_VERSION );
88
  }
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.5.0
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.2
19
  * Author: Ben Marshall
30
 
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.5.0' );
35
 
36
  /**
37
  * Helpers
53
  $installed_db_version = get_option( 'wpzerospam_db_version' );
54
 
55
  if ( $installed_db_version != WORDPRESS_ZERO_SPAM_DB_VERSION ) {
56
+ $log_table = wpzerospam_tables( 'log' );
57
+ $blocked_table = wpzerospam_tables( 'blocked' );
58
+ $blacklist_table = wpzerospam_tables( 'blacklist' );
59
+
60
+ $sql = '';
61
+ if ( $wpdb->get_var( 'SHOW TABLES LIKE \'' . $log_table . '\'' ) != $log_table ) {
62
+ $sql .= "CREATE TABLE $log_table (
63
+ log_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
64
+ log_type VARCHAR(255) NOT NULL,
65
+ user_ip VARCHAR(255) NOT NULL,
66
+ date_recorded DATETIME NOT NULL,
67
+ page_url VARCHAR(255) NULL DEFAULT NULL,
68
+ submission_data LONGTEXT NULL DEFAULT NULL,
69
+ country VARCHAR(2) NULL DEFAULT NULL,
70
+ region VARCHAR(255) NULL DEFAULT NULL,
71
+ city VARCHAR(255) NULL DEFAULT NULL,
72
+ latitude VARCHAR(255) NULL DEFAULT NULL,
73
+ longitude VARCHAR(255) NULL DEFAULT NULL,
74
+ PRIMARY KEY (`log_id`)) $charset_collate;";
75
+ }
76
+
77
+ if ( $wpdb->get_var( 'SHOW TABLES LIKE \'' . $blocked_table . '\'' ) != $blocked_table ) {
78
+ $sql .= "CREATE TABLE $blocked_table (
79
+ blocked_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
80
+ blocked_type ENUM('permanent','temporary') NOT NULL DEFAULT 'temporary',
81
+ user_ip VARCHAR(255) NOT NULL,
82
+ date_added DATETIME NOT NULL,
83
+ start_block DATETIME NULL DEFAULT NULL,
84
+ end_block DATETIME NULL DEFAULT NULL,
85
+ reason VARCHAR(255) NULL DEFAULT NULL,
86
+ attempts BIGINT UNSIGNED NOT NULL,
87
+ PRIMARY KEY (`blocked_id`)) $charset_collate;";
88
+ }
89
+
90
+ if ( $wpdb->get_var( 'SHOW TABLES LIKE \'' . $blacklist_table . '\'' ) != $blacklist_table ) {
91
+ $sql .= "CREATE TABLE $blacklist_table (
92
+ blacklist_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
93
+ user_ip VARCHAR(255) NOT NULL,
94
+ last_updated DATETIME NOT NULL,
95
+ blacklist_service VARCHAR(255) NULL DEFAULT NULL,
96
+ blacklist_data LONGTEXT NULL DEFAULT NULL,
97
+ PRIMARY KEY (`blacklist_id`)) $charset_collate;";
98
+ }
99
+
100
+ if( $sql ) {
101
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
102
+ dbDelta( $sql );
103
+ }
104
 
105
  update_option( 'wpzerospam_db_version', WORDPRESS_ZERO_SPAM_DB_VERSION );
106
  }