Skip to content

Commit be077d7

Browse files
committed
updates
1 parent 036a64b commit be077d7

File tree

11 files changed

+457
-60
lines changed

11 files changed

+457
-60
lines changed

core/admin/class-settings.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,21 +558,21 @@ public function settings_page() {
558558
?>
559559
<div class="zerospam-block">
560560
<div class="zerospam-block__content zerospam-block__content--supports">
561-
<strong><?php _e( 'Detection Support', 'zero-spam' ); ?>:</strong>
561+
<strong><?php _e( 'Supported Signals', 'zero-spam' ); ?>:</strong>
562562
<?php
563563
foreach ( $section['supports'] as $k => $s ) :
564564
switch ( $s ) :
565565
case 'honeypot':
566566
echo '<img class="zerospam-small-icon" src="' . plugin_dir_url( ZEROSPAM ) . 'assets/img/icon-honeypot.svg" alt="' . esc_attr( __( 'Honeypot', 'zero-spam' ) ) . '" />';
567567
break;
568568
case 'email':
569-
echo '<img class="zerospam-small-icon" src="' . plugin_dir_url( ZEROSPAM ) . 'assets/img/icon-email.svg" alt="' . esc_attr( __( 'Email', 'zero-spam' ) ) . '" />';
569+
echo '<img class="zerospam-small-icon" src="' . plugin_dir_url( ZEROSPAM ) . 'assets/img/icon-email.svg" alt="' . esc_attr( __( 'Email Protection', 'zero-spam' ) ) . '" title="' . esc_attr( __( 'Email Protection', 'zero-spam' ) ) . '" />';
570570
break;
571571
case 'davidwalsh':
572572
echo '<img class="zerospam-small-icon" src="' . plugin_dir_url( ZEROSPAM ) . 'modules/davidwalsh/icon-david-walsh.png" alt="' . esc_attr( __( 'David Walsh', 'zero-spam' ) ) . '" />';
573573
break;
574574
case 'words':
575-
echo '<img class="zerospam-small-icon" src="' . plugin_dir_url( ZEROSPAM ) . 'assets/img/icon-words.svg" alt="' . esc_attr( __( 'Disallowed Words', 'zero-spam' ) ) . '" />';
575+
echo '<img class="zerospam-small-icon" src="' . plugin_dir_url( ZEROSPAM ) . 'assets/img/icon-words.svg" alt="' . esc_attr( __( 'Disallowed Words', 'zero-spam' ) ) . '" title="' . esc_attr( __( 'Disallowed Words', 'zero-spam' ) ) . '" />';
576576
break;
577577
endswitch;
578578

@@ -582,8 +582,8 @@ public function settings_page() {
582582
</div>
583583
<?php
584584
endif;
585-
endforeach;
586-
?>
585+
endforeach;
586+
?>
587587

588588
<?php if ( ! in_array( $subview, array( 'export', 'errors' ) ) ) : ?>
589589
<?php

core/class-access.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* Access
1717
*/
1818
class Access {
19-
2019
/**
2120
* Constructor
2221
*/

core/class-utilities.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,6 @@ public static function geolocation( $ip ) {
851851
}
852852
// 2. Query ipbase
853853
$location_details = apply_filters( 'zero_spam_ip_address_details', $ip, $location_details );
854-
echo 1;
855-
die();
856854

857855
// 3. Query the IPinfo API.
858856
$ipinfo_location = ZeroSpam\Modules\IPinfoModule::get_geolocation( $ip );

includes/class-plugin.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private function __construct() {
3131

3232
add_filter( 'zerospam_types', array( $this, 'types' ), 10, 1 );
3333
add_filter( 'zerospam_failed_types', array( $this, 'failed_types' ), 10, 1 );
34+
add_action( 'zero_spam_flagged_attempt', array( $this, 'flagged_attempt' ), 10, 3 );
3435
}
3536

3637
/**
@@ -85,7 +86,7 @@ private function init_modules() {
8586
new \ZeroSpam\Includes\Updates();
8687

8788
// Site security
88-
new \ZeroSpam\Modules\Security();
89+
new \ZeroSpam\Modules\Security\Security();
8990

9091
// Zero Spam module.
9192
new \ZeroSpam\Modules\Zero_Spam();
@@ -125,6 +126,11 @@ private function init_modules() {
125126
// Used to check if a plugin is installed & active.
126127
include_once ABSPATH . 'wp-admin/includes/plugin.php';
127128

129+
// Elementor plugin module.
130+
/*if ( is_plugin_active( 'elementor-pro/elementor-pro.php' ) ) {
131+
new \ZeroSpam\Modules\Elementor\Elementor();
132+
}*/
133+
128134
// GiveWP plugin module.
129135
if ( is_plugin_active( 'give/give.php' ) ) {
130136
new \ZeroSpam\Modules\Give\Give();
@@ -184,6 +190,29 @@ public function types( $types ) {
184190

185191
return $types;
186192
}
193+
194+
/**
195+
* Action taken for flagged attempts
196+
*
197+
* @param string $module The associated module.
198+
* @param string $signal The associated signal.
199+
* @param array $data Additional attempt data.
200+
*/
201+
public function flagged_attempt( $module, $signal, $data ) {
202+
$details = array(
203+
'type' => $module,
204+
'failed' => $signal,
205+
'data' => $data,
206+
);
207+
208+
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( $module . '_log_flagged_attempts' ) ) {
209+
\ZeroSpam\Includes\DB::log( $module, $details );
210+
}
211+
212+
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'share_data' ) ) {
213+
do_action( 'zerospam_share_detection', $details );
214+
}
215+
}
187216
}
188217

189218
Plugin::instance();

modules/class-security.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

modules/elementor/class-elementor.php

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
/**
3+
* Adds integration for Elementor Pro forms
4+
*
5+
* @package ZeroSpam
6+
*/
7+
8+
namespace ZeroSpam\Modules\Elementor;
9+
10+
// Security Note: Blocks direct access to the plugin PHP files.
11+
defined( 'ABSPATH' ) || die();
12+
13+
/**
14+
* Elementor
15+
*/
16+
class Elementor {
17+
/**
18+
* Constructor
19+
*/
20+
public function __construct() {
21+
add_action( 'init', array( $this, 'init' ) );
22+
wp_add_inline_style(
23+
'zero-spam-admin',
24+
'
25+
.zerospam-type-elementor::before {
26+
background-image: url("../../modules/elementor/icon-elementor.svg");
27+
}
28+
'
29+
);
30+
}
31+
32+
/**
33+
* Fires after WordPress has finished loading but before any headers are sent
34+
*/
35+
public function init() {
36+
add_filter( 'zerospam_setting_sections', array( $this, 'sections' ) );
37+
add_filter( 'zerospam_settings', array( $this, 'settings' ), 10, 1 );
38+
add_filter( 'zerospam_types', array( $this, 'types' ), 10, 1 );
39+
40+
if (
41+
'enabled' === \ZeroSpam\Core\Settings::get_settings( 'elementor_enabled' ) &&
42+
\ZeroSpam\Core\Access::process()
43+
) {
44+
add_action( 'elementor_pro/forms/validation/email', array( $this, 'validate_email' ), 10, 3 );
45+
add_action( 'elementor_pro/forms/validation/text', array( $this, 'validate_text' ), 10, 3 );
46+
add_action( 'elementor_pro/forms/validation/textarea', array( $this, 'validate_text' ), 10, 3 );
47+
add_action( 'elementor_pro/forms/validation/html', array( $this, 'validate_text' ), 10, 3 );
48+
}
49+
}
50+
51+
/**
52+
* Admin setting sections
53+
*
54+
* @param array $sections Array of admin setting sections.
55+
*/
56+
public function sections( $sections ) {
57+
$sections['elementor'] = array(
58+
'title' => __( 'Elementor', 'zero-spam' ),
59+
'icon' => 'modules/elementor/icon-elementor.svg',
60+
'supports' => array( 'email', 'words' ),
61+
);
62+
63+
return $sections;
64+
}
65+
66+
/**
67+
* Admin settings
68+
*
69+
* @param array $settings Array of available settings.
70+
*/
71+
public function settings( $settings ) {
72+
$options = get_option( 'zero-spam-elementor' );
73+
74+
$settings['elementor_enabled'] = array(
75+
'title' => wp_kses(
76+
__( 'Protect Form Submissions', 'zero-spam' ),
77+
array(
78+
'a' => array(
79+
'href' => array(),
80+
'class' => array(),
81+
'target' => array(),
82+
'rel' => array(),
83+
),
84+
)
85+
),
86+
'desc' => __( 'Protects & monitors Elementor form submissions.', 'zero-spam' ),
87+
'module' => 'elementor',
88+
'type' => 'checkbox',
89+
'options' => array(
90+
'enabled' => false,
91+
),
92+
'value' => ! empty( $options['elementor_enabled'] ) ? $options['elementor_enabled'] : false,
93+
'recommended' => 'enabled',
94+
);
95+
96+
$message = __( 'We were unable to process your submission due to possible malicious activity.', 'zero-spam' );
97+
$settings['elementor_flagged_msg'] = array(
98+
'title' => __( 'Flagged Message', 'zero-spam' ),
99+
'desc' => __( 'Message displayed when a submission has been flagged.', 'zero-spam' ),
100+
'module' => 'elementor',
101+
'type' => 'text',
102+
'field_class' => 'large-text',
103+
'placeholder' => $message,
104+
'value' => ! empty( $options['elementor_flagged_msg'] ) ? $options['elementor_flagged_msg'] : $message,
105+
'recommended' => $message,
106+
);
107+
108+
$settings['elementor_log_flagged_attempts'] = array(
109+
'title' => __( 'Log Flagged Attempts', 'zero-spam' ),
110+
'module' => 'elementor',
111+
'type' => 'checkbox',
112+
'desc' => wp_kses(
113+
__( 'When enabled, stores blocked form submissions in the database.', 'zero-spam' ),
114+
array( 'strong' => array() )
115+
),
116+
'options' => array(
117+
'enabled' => false
118+
),
119+
'value' => ! empty( $options['elementor_log_flagged_attempts'] ) ? $options['elementor_log_flagged_attempts'] : false,
120+
'recommended' => 'enabled',
121+
);
122+
123+
return $settings;
124+
}
125+
126+
/**
127+
* Register custom fields
128+
*
129+
* @param \ElementorPro\Modules\Forms\Registrars\Form_Fields_Registrar $form_fields_registrar
130+
*/
131+
public function register_fields( $form_fields_registrar ) {
132+
//require_once ZEROSPAM_PATH . 'modules/elementor/fields/class-honeypot.php';
133+
}
134+
135+
/**
136+
* Validates form on submission
137+
*/
138+
public function validate_form( $record, $ajax_handler ) {
139+
140+
}
141+
142+
/**
143+
* Validates an email address
144+
*/
145+
public function validate_email( $field, $record, $ajax_handler ) {
146+
if ( \ZeroSpam\Core\Utilities::is_email_domain_blocked( $field['value'] ) ) {
147+
$ajax_handler->add_error( $field['id'], \ZeroSpam\Core\Utilities::detection_message( 'elementor_flagged_msg' ) );
148+
return;
149+
}
150+
}
151+
152+
/**
153+
* Validates text content
154+
*/
155+
public function validate_text( $field, $record, $ajax_handler ) {
156+
if ( \ZeroSpam\Core\Utilities::is_disallowed( $field['value'] ) ) {
157+
do_action(
158+
'zero_spam_flagged_attempt',
159+
'elementor',
160+
'disallowed_list',
161+
array(
162+
'field' => $field,
163+
'record' => $record,
164+
)
165+
);
166+
167+
$ajax_handler->add_error( $field['id'], \ZeroSpam\Core\Utilities::detection_message( 'elementor_flagged_msg' ) );
168+
return;
169+
}
170+
}
171+
}

modules/elementor/icon-elementor.svg

Lines changed: 1 addition & 0 deletions
Loading

modules/gravityforms/class-gravityforms.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Malicious user detection techniques available:
66
*
77
* 1. Zero Spam honeypot field
8-
* 2. Checks blocked email domains
98
*
109
* @package ZeroSpam
1110
*/
@@ -74,7 +73,7 @@ public function sections( $sections ) {
7473
$sections['gravityforms'] = array(
7574
'title' => __( 'Gravity Forms', 'zero-spam' ),
7675
'icon' => 'modules/gravityforms/icon-gravity-forms.svg',
77-
'supports' => array( 'honeypot', 'email' ),
76+
'supports' => array( 'honeypot' ),
7877
);
7978

8079
return $sections;
@@ -205,8 +204,7 @@ public function settings( $settings ) {
205204
'recommended' => 'enabled',
206205
);
207206

208-
$message = __( 'We were unable to process your submission: IP address has been flagged as possible spam.', 'zero-spam' );
209-
207+
$message = __( 'We were unable to process your submission due to possible malicious activity.', 'zero-spam' );
210208
$settings['gravityforms_spam_message'] = array(
211209
'title' => __( 'Flagged Message', 'zero-spam' ),
212210
'desc' => __( 'Message displayed when a submission has been flagged.', 'zero-spam' ),

0 commit comments

Comments
 (0)