WordPress Zero Spam - Version 5.0.9

Version Description

Download this release

Release Info

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

Code changes from version 5.0.8 to 5.0.9

core/admin/class-admin.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Admin class.
4
  *
5
  * @package ZeroSpam
6
  */
@@ -13,19 +13,12 @@ use ZeroSpam\Core\Admin\Admin;
13
  defined( 'ABSPATH' ) || die();
14
 
15
  /**
16
- * Admin.
17
- *
18
- * Handles access checks.
19
- *
20
- * @since 5.0.0
21
  */
22
  class Admin {
23
 
24
  /**
25
- * Admin constructor.
26
- *
27
- * @since 5.0.0
28
- * @access public
29
  */
30
  public function __construct() {
31
  new Settings();
1
  <?php
2
  /**
3
+ * Admin class
4
  *
5
  * @package ZeroSpam
6
  */
13
  defined( 'ABSPATH' ) || die();
14
 
15
  /**
16
+ * Admin
 
 
 
 
17
  */
18
  class Admin {
19
 
20
  /**
21
+ * Admin constructor
 
 
 
22
  */
23
  public function __construct() {
24
  new Settings();
core/admin/class-settings.php CHANGED
@@ -61,10 +61,7 @@ class Settings {
61
  }
62
 
63
  /**
64
- * Admin menu.
65
- *
66
- * @since 5.0.0
67
- * @access public
68
  */
69
  public function admin_menu() {
70
  add_submenu_page(
@@ -87,10 +84,7 @@ class Settings {
87
  }
88
 
89
  /**
90
- * Register settings.
91
- *
92
- * @since 5.0.0
93
- * @access public
94
  */
95
  public function register_settings() {
96
  register_setting(
@@ -172,19 +166,13 @@ class Settings {
172
  }
173
 
174
  /**
175
- * Settings section.
176
- *
177
- * @since 5.0.0
178
- * @access public
179
  */
180
  public function settings_section( $arg ) {
181
  }
182
 
183
  /**
184
- * Settings field.
185
- *
186
- * @since 5.0.0
187
- * @access public
188
  */
189
  public function settings_field( $args ) {
190
  switch ( $args['type'] ) {
@@ -284,10 +272,7 @@ class Settings {
284
  }
285
 
286
  /**
287
- * Settings page.
288
- *
289
- * @since 5.0.0
290
- * @access public
291
  */
292
  public function settings_page() {
293
  if ( ! current_user_can( 'manage_options' ) ) {
61
  }
62
 
63
  /**
64
+ * Admin menu
 
 
 
65
  */
66
  public function admin_menu() {
67
  add_submenu_page(
84
  }
85
 
86
  /**
87
+ * Register settings
 
 
 
88
  */
89
  public function register_settings() {
90
  register_setting(
166
  }
167
 
168
  /**
169
+ * Settings section
 
 
 
170
  */
171
  public function settings_section( $arg ) {
172
  }
173
 
174
  /**
175
+ * Settings field
 
 
 
176
  */
177
  public function settings_field( $args ) {
178
  switch ( $args['type'] ) {
272
  }
273
 
274
  /**
275
+ * Settings page
 
 
 
276
  */
277
  public function settings_page() {
278
  if ( ! current_user_can( 'manage_options' ) ) {
core/class-settings.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Settings class.
4
  *
5
  * @package ZeroSpam
6
  */
@@ -11,40 +11,26 @@ namespace ZeroSpam\Core;
11
  defined( 'ABSPATH' ) || die();
12
 
13
  /**
14
- * Settings.
15
- *
16
- * @since 5.0.0
17
  */
18
  class Settings {
 
19
  /**
20
- * Settings.
21
- *
22
- * Holds the plugin settings.
23
- *
24
- * @since 5.0.0
25
- * @access public
26
- * @static
27
  *
28
  * @var Settings
29
  */
30
  public static $settings = array();
31
 
32
  /**
33
- * Sections.
34
  *
35
- * @since 5.0.0
36
- * @access public
37
- * @static
38
- *
39
- * @var Settings
40
  */
41
  public static $sections = array();
42
 
43
  /**
44
- * Returns the plugin setting sections.
45
- *
46
- * @since 5.0.0
47
- * @access public
48
  */
49
  public static function get_sections() {
50
  self::$sections['general'] = array(
@@ -61,7 +47,7 @@ class Settings {
61
  /**
62
  * Configures the plugin's recommended settings.
63
  */
64
- public function auto_configure() {
65
  $settings = \ZeroSpam\Core\Settings::get_settings();
66
 
67
  $recommended_settings = array();
@@ -79,10 +65,7 @@ class Settings {
79
  }
80
 
81
  /**
82
- * Returns the plugin settings.
83
- *
84
- * @since 5.0.0
85
- * @access public
86
  */
87
  public static function get_settings( $key = false ) {
88
  $options = get_option( 'wpzerospam' );
1
  <?php
2
  /**
3
+ * Settings class
4
  *
5
  * @package ZeroSpam
6
  */
11
  defined( 'ABSPATH' ) || die();
12
 
13
  /**
14
+ * Settings
 
 
15
  */
16
  class Settings {
17
+
18
  /**
19
+ * Settings
 
 
 
 
 
 
20
  *
21
  * @var Settings
22
  */
23
  public static $settings = array();
24
 
25
  /**
26
+ * Sections
27
  *
28
+ * @var Sections
 
 
 
 
29
  */
30
  public static $sections = array();
31
 
32
  /**
33
+ * Returns the plugin setting sections
 
 
 
34
  */
35
  public static function get_sections() {
36
  self::$sections['general'] = array(
47
  /**
48
  * Configures the plugin's recommended settings.
49
  */
50
+ public static function auto_configure() {
51
  $settings = \ZeroSpam\Core\Settings::get_settings();
52
 
53
  $recommended_settings = array();
65
  }
66
 
67
  /**
68
+ * Returns the plugin settings
 
 
 
69
  */
70
  public static function get_settings( $key = false ) {
71
  $options = get_option( 'wpzerospam' );
core/class-utilities.php CHANGED
@@ -378,10 +378,7 @@ class Utilities {
378
  }
379
 
380
  /**
381
- * Returns a cache key.
382
- *
383
- * @since 5.0.0
384
- * @access public
385
  */
386
  public static function cache_key( $args, $table = false ) {
387
  return sanitize_title( $table . '_' . implode( '_', $args ) );
378
  }
379
 
380
  /**
381
+ * Returns a cache key
 
 
 
382
  */
383
  public static function cache_key( $args, $table = false ) {
384
  return sanitize_title( $table . '_' . implode( '_', $args ) );
modules/class-stopforumspam.php CHANGED
@@ -232,14 +232,20 @@ class StopForumSpam {
232
  ) {
233
  $errors->add( 'zerospam_error_stopformspam_username', $message );
234
 
 
 
 
 
 
235
  if ( ! empty( $settings['log_blocked_registrations']['value'] ) && 'enabled' === $settings['log_blocked_registrations']['value'] ) {
236
- $details = array(
237
- 'user_login' => $sanitized_user_login,
238
- 'user_email' => $user_email,
239
- 'failed' => 'stop_forum_spam_username',
240
- );
241
  ZeroSpam\Includes\DB::log( 'registration', $details );
242
  }
 
 
 
 
 
 
243
  }
244
 
245
  // Check email.
232
  ) {
233
  $errors->add( 'zerospam_error_stopformspam_username', $message );
234
 
235
+ $details = array(
236
+ 'user_login' => $sanitized_user_login,
237
+ 'user_email' => $user_email,
238
+ 'failed' => 'stop_forum_spam_username',
239
+ );
240
  if ( ! empty( $settings['log_blocked_registrations']['value'] ) && 'enabled' === $settings['log_blocked_registrations']['value'] ) {
 
 
 
 
 
241
  ZeroSpam\Includes\DB::log( 'registration', $details );
242
  }
243
+
244
+ // Share the detection if enabled.
245
+ if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'share_data' ) ) {
246
+ $details['type'] = 'registration';
247
+ do_action( 'zerospam_share_detection', $details );
248
+ }
249
  }
250
 
251
  // Check email.
modules/class-zerospam.php CHANGED
@@ -21,6 +21,7 @@ class Zero_Spam {
21
  * The zerospam.org API endpoint
22
  */
23
  const API_ENDPOINT = 'https://www.zerospam.org/wp-json/zerospam/v1/';
 
24
 
25
  /**
26
  * Constructor
@@ -28,6 +29,64 @@ class Zero_Spam {
28
  public function __construct() {
29
  // Fires when a user is blocked from accessing the site.
30
  add_action( 'zerospam_share_blocked', array( $this, 'share_blocked' ), 10, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
 
33
  /**
@@ -88,24 +147,15 @@ class Zero_Spam {
88
 
89
  // Only query the API if there's data to be sent.
90
  if ( ! empty( $api_data['checks'] ) ) {
91
- // Add site details.
92
- $api_data['site_url'] = site_url();
93
- $api_data['admin_email'] = get_bloginfo( 'admin_email' );
94
- $api_data['wp_version'] = get_bloginfo( 'version' );
95
- $api_data['site_name'] = get_bloginfo( 'name' );
96
- $api_data['site_desc'] = get_bloginfo( 'description' );
97
- $api_data['site_language'] = get_bloginfo( 'language' );
98
- $api_data['plugin_version'] = ZEROSPAM_VERSION;
99
 
100
  // Send the data to zerospam.org.
101
  $args = array(
102
  'body' => $api_data,
103
  );
104
 
105
- $response = wp_remote_post( $endpoint, $args );
106
- if ( ! is_wp_error( $response ) ) {
107
- wp_remote_retrieve_body( $response );
108
- }
109
  }
110
  }
111
  }
21
  * The zerospam.org API endpoint
22
  */
23
  const API_ENDPOINT = 'https://www.zerospam.org/wp-json/zerospam/v1/';
24
+ //const API_ENDPOINT = 'http://localhost:10023/wp-json/zerospam/v1/';
25
 
26
  /**
27
  * Constructor
29
  public function __construct() {
30
  // Fires when a user is blocked from accessing the site.
31
  add_action( 'zerospam_share_blocked', array( $this, 'share_blocked' ), 10, 1 );
32
+
33
+ // Fires when a user submission has been detected as spam.
34
+ add_action( 'zerospam_share_detection', array( $this, 'share_detection' ), 10, 1 );
35
+ }
36
+
37
+ /**
38
+ * Global API data.
39
+ */
40
+ public function global_api_data() {
41
+ $api_data = array();
42
+ $api_data['site_url'] = site_url();
43
+ $api_data['admin_email'] = get_bloginfo( 'admin_email' );
44
+ $api_data['wp_version'] = get_bloginfo( 'version' );
45
+ $api_data['site_name'] = get_bloginfo( 'name' );
46
+ $api_data['site_desc'] = get_bloginfo( 'description' );
47
+ $api_data['site_language'] = get_bloginfo( 'language' );
48
+ $api_data['plugin_version'] = ZEROSPAM_VERSION;
49
+
50
+ return $api_data;
51
+ }
52
+
53
+ /**
54
+ * Share detection details with zerospam.org
55
+ *
56
+ * @param array $data Contains all detection details.
57
+ */
58
+ public function share_detection( $data ) {
59
+ $endpoint = self::API_ENDPOINT . 'add-detection/';
60
+
61
+ $ip = \ZeroSpam\Core\User::get_ip();
62
+
63
+ if ( ! $ip || ! $data || ! is_array( $data ) || empty( $data['type'] ) ) {
64
+ return false;
65
+ }
66
+
67
+ $api_data = array(
68
+ 'user_ip' => $ip,
69
+ 'type' => trim( sanitize_text_field( $data['type'] ) ),
70
+ 'data' => array(),
71
+ );
72
+
73
+ // Loop through & clean the data.
74
+ foreach ( $data as $key => $value ) {
75
+ $api_data['data'][ $key ] = trim( sanitize_text_field( $value ) );
76
+ }
77
+
78
+ // Attempt to get the geolocation information.
79
+ $api_data['location'] = ZeroSpam\Modules\ipstack::get_geolocation( $ip );
80
+
81
+ $global_data = self::global_api_data();
82
+ $api_data = array_merge( $api_data, $global_data );
83
+
84
+ // Send the data to zerospam.org.
85
+ $args = array(
86
+ 'body' => $api_data,
87
+ );
88
+
89
+ wp_remote_post( $endpoint, $args );
90
  }
91
 
92
  /**
147
 
148
  // Only query the API if there's data to be sent.
149
  if ( ! empty( $api_data['checks'] ) ) {
150
+ $global_data = self::global_api_data();
151
+ $api_data = array_merge( $api_data, $global_data );
 
 
 
 
 
 
152
 
153
  // Send the data to zerospam.org.
154
  $args = array(
155
  'body' => $api_data,
156
  );
157
 
158
+ wp_remote_post( $endpoint, $args );
 
 
 
159
  }
160
  }
161
  }
modules/comments/class-comments.php CHANGED
@@ -51,7 +51,6 @@ class Comments {
51
  public function preprocess_comments( $commentdata ) {
52
  $block_user = false;
53
  $block_type = false;
54
- $settings = ZeroSpam\Core\Settings::get_settings();
55
 
56
  // Check honeypot.
57
  // @codingStandardsIgnoreLine
@@ -83,15 +82,22 @@ class Comments {
83
  }
84
 
85
  if ( $block_user && $block_type ) {
 
 
 
 
 
86
  // Log if enabled.
87
  if ( 'enabled' === ZeroSpam\Core\Settings::get_settings( 'log_blocked_comments' ) ) {
88
- $details = array(
89
- 'failed' => $block_type,
90
- );
91
- $details = array_merge( $details, $commentdata );
92
  ZeroSpam\Includes\DB::log( 'comment', $details );
93
  }
94
 
 
 
 
 
 
 
95
  $message = ZeroSpam\Core\Utilities::detection_message( 'comment_spam_message' );
96
 
97
  wp_die(
51
  public function preprocess_comments( $commentdata ) {
52
  $block_user = false;
53
  $block_type = false;
 
54
 
55
  // Check honeypot.
56
  // @codingStandardsIgnoreLine
82
  }
83
 
84
  if ( $block_user && $block_type ) {
85
+ $details = array(
86
+ 'failed' => $block_type,
87
+ );
88
+ $details = array_merge( $details, $commentdata );
89
+
90
  // Log if enabled.
91
  if ( 'enabled' === ZeroSpam\Core\Settings::get_settings( 'log_blocked_comments' ) ) {
 
 
 
 
92
  ZeroSpam\Includes\DB::log( 'comment', $details );
93
  }
94
 
95
+ // Share the detection if enabled.
96
+ if ( 'enabled' === ZeroSpam\Core\Settings::get_settings( 'share_data' ) ) {
97
+ $details['type'] = 'comment';
98
+ do_action( 'zerospam_share_detection', $details );
99
+ }
100
+
101
  $message = ZeroSpam\Core\Utilities::detection_message( 'comment_spam_message' );
102
 
103
  wp_die(
modules/registration/class-registration.php CHANGED
@@ -58,14 +58,20 @@ class Registration {
58
  $message = ZeroSpam\Core\Utilities::detection_message( 'registration_spam_message' );
59
  $errors->add( 'zerospam_error', $message );
60
 
 
 
 
 
 
61
  if ( 'enabled' === ZeroSpam\Core\Settings::get_settings( 'log_blocked_registrations' ) ) {
62
- $details = array(
63
- 'user_login' => $sanitized_user_login,
64
- 'user_email' => $user_email,
65
- 'failed' => 'honeypot',
66
- );
67
  ZeroSpam\Includes\DB::log( 'registration', $details );
68
  }
 
 
 
 
 
 
69
  }
70
 
71
  $errors = apply_filters( 'zerospam_registration_errors', $errors, $sanitized_user_login, $user_email );
58
  $message = ZeroSpam\Core\Utilities::detection_message( 'registration_spam_message' );
59
  $errors->add( 'zerospam_error', $message );
60
 
61
+ $details = array(
62
+ 'user_login' => $sanitized_user_login,
63
+ 'user_email' => $user_email,
64
+ 'failed' => 'honeypot',
65
+ );
66
  if ( 'enabled' === ZeroSpam\Core\Settings::get_settings( 'log_blocked_registrations' ) ) {
 
 
 
 
 
67
  ZeroSpam\Includes\DB::log( 'registration', $details );
68
  }
69
+
70
+ // Share the detection if enabled.
71
+ if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'share_data' ) ) {
72
+ $details['type'] = 'registration';
73
+ do_action( 'zerospam_share_detection', $details );
74
+ }
75
  }
76
 
77
  $errors = apply_filters( 'zerospam_registration_errors', $errors, $sanitized_user_login, $user_email );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://www.benmarshall.me/donate/?utm_source=wordpress_zero_spam&u
5
  Requires at least: 5.2
6
  Tested up to: 5.6.2
7
  Requires PHP: 7.3
8
- Stable tag: 5.0.8
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
@@ -73,6 +73,12 @@ For more information & developer documentation, see the [plugin’s website](htt
73
 
74
  == Changelog ==
75
 
 
 
 
 
 
 
76
  = v5.0.8 =
77
 
78
  * Fix for admin first-time config notice
5
  Requires at least: 5.2
6
  Tested up to: 5.6.2
7
  Requires PHP: 7.3
8
+ Stable tag: 5.0.9
9
  License: GNU GPLv3
10
  License URI: https://choosealicense.com/licenses/gpl-3.0/
11
 
73
 
74
  == Changelog ==
75
 
76
+ = v5.0.9 =
77
+
78
+ * Performance enhancements
79
+ * Various admin UI improvements
80
+ * Strengthened comment & registration spam detections
81
+
82
  = v5.0.8 =
83
 
84
  * Fix for admin first-time config notice
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>.
16
- * Version: 5.0.8
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.3
19
  * Author: Ben Marshall
@@ -31,7 +31,7 @@ defined( 'ABSPATH' ) || die();
31
  define( 'ZEROSPAM', __FILE__ );
32
  define( 'ZEROSPAM_PATH', plugin_dir_path( ZEROSPAM ) );
33
  define( 'ZEROSPAM_PLUGIN_BASE', plugin_basename( ZEROSPAM ) );
34
- define( 'ZEROSPAM_VERSION', '5.0.8' );
35
 
36
  add_action( 'plugins_loaded', 'zerospam_load_plugin_textdomain' );
37
 
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>.
16
+ * Version: 5.0.9
17
  * Requires at least: 5.2
18
  * Requires PHP: 7.3
19
  * Author: Ben Marshall
31
  define( 'ZEROSPAM', __FILE__ );
32
  define( 'ZEROSPAM_PATH', plugin_dir_path( ZEROSPAM ) );
33
  define( 'ZEROSPAM_PLUGIN_BASE', plugin_basename( ZEROSPAM ) );
34
+ define( 'ZEROSPAM_VERSION', '5.0.9' );
35
 
36
  add_action( 'plugins_loaded', 'zerospam_load_plugin_textdomain' );
37