Skip to content

Commit 6b03b0c

Browse files
authored
Merge pull request #635 from CleanTalk/release_6.59
Release 6.59
2 parents 01418ab + e877b2d commit 6b03b0c

File tree

66 files changed

+1201
-832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1201
-832
lines changed

cleantalk.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: Anti-Spam by CleanTalk
55
Plugin URI: https://cleantalk.org
66
Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
7-
Version: 6.58.1
7+
Version: 6.59
88
Author: CleanTalk - Anti-Spam Protection <welcome@cleantalk.org>
99
Author URI: https://cleantalk.org
1010
Text Domain: cleantalk-spam-protect
@@ -118,7 +118,15 @@
118118
$plugin_version__agent = $major_version . '.' . $minor_version . '.' . $branch_sub . $padded;
119119
}
120120
define('APBCT_AGENT', 'wordpress-' . $plugin_version__agent); // Prepared agent
121-
const APBCT_MODERATE_URL = 'https://moderate.cleantalk.org'; // Api URL
121+
122+
if ( defined('CLEANTALK_SERVER') ) {
123+
define('APBCT_MODERATE_URL', 'https://moderate.' . CLEANTALK_SERVER);
124+
if ( ! defined('CLEANTALK_API_URL') ) {
125+
define('CLEANTALK_API_URL', 'https://api.' . CLEANTALK_SERVER);
126+
}
127+
} else {
128+
define('APBCT_MODERATE_URL', 'https://moderate.cleantalk.org'); // Api URL
129+
}
122130

123131
/**
124132
* Require base classes.
@@ -442,8 +450,11 @@ function apbct_write_js_errors($data)
442450
// Metform
443451
if (
444452
apbct_is_plugin_active('metform/metform.php') &&
445-
apbct_is_in_uri('/wp-json/metform/') &&
446-
sizeof($_POST) > 0
453+
sizeof($_POST) > 0 &&
454+
(
455+
apbct_is_in_uri('/wp-json/metform/') ||
456+
(apbct_get_rest_url_only_path() !== 'index.php' && apbct_is_in_uri(apbct_get_rest_url_only_path() . 'metform/'))
457+
)
447458
) {
448459
apbct_form__metform_subscribe__testSpam();
449460
}
@@ -582,7 +593,7 @@ function apbct_write_js_errors($data)
582593
. APBCT_URL_PATH
583594
. '/js/apbct-public-bundle.min.js'
584595
. '?ver=' . APBCT_VERSION . '" id="ct_public_functions-js"></script>';
585-
echo '<script src="https://moderate.cleantalk.org/ct-bot-detector-wrapper.js?ver='
596+
echo '<script src="' . APBCT_MODERATE_URL . '/ct-bot-detector-wrapper.js?ver='
586597
. APBCT_VERSION . '" id="ct_bot_detector-js"></script>';
587598
}, 100);
588599
}
@@ -2579,7 +2590,7 @@ function apbct_cookie()
25792590
$domain = '';
25802591

25812592
// Submit time
2582-
if ( empty($_POST) || Post::get('action') === 'apbct_set_important_parameters' ) {
2593+
if ( empty($_POST) ) {
25832594
$apbct_timestamp = time();
25842595
RequestParameters::set('apbct_timestamp', (string)$apbct_timestamp, true);
25852596
$cookie_test_value['cookies_names'][] = 'apbct_timestamp';
@@ -2751,11 +2762,13 @@ function ct_account_status_check($api_key = null, $process_errors = true)
27512762

27522763
//todo:temporary solution for description, until we found the way to transfer this from cloud
27532764
if (defined('APBCT_WHITELABEL_PLUGIN_DESCRIPTION')) {
2765+
/** @psalm-suppress PossiblyInvalidArrayAssignment */
27542766
$result['wl_antispam_description'] = APBCT_WHITELABEL_PLUGIN_DESCRIPTION;
27552767
}
27562768

27572769
//todo:temporary solution for FAQ
27582770
if (defined('APBCT_WHITELABEL_FAQ_LINK')) {
2771+
/** @psalm-suppress PossiblyInvalidArrayAssignment */
27592772
$result['wl_faq_url'] = APBCT_WHITELABEL_FAQ_LINK;
27602773
}
27612774

inc/cleantalk-admin.php

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,16 @@ function ct_dashboard_statistics_widget()
9595
if (isset($apbct->data['wl_brandname']) && $apbct->data['wl_brandname'] !== APBCT_NAME) {
9696
$actual_plugin_name = $apbct->data['wl_brandname'];
9797
}
98+
/**
99+
* Hook. List of allowed user roles for the Dashboard widget.
100+
* add_filter('apbct_hook_dashboard_widget_allowed_roles_list', function($roles_list) {
101+
* $roles_list[] = 'editor';
102+
* return $roles_list;
103+
* });
104+
*/
105+
$roles_list = apply_filters('apbct_hook_dashboard_widget_allowed_roles_list', array('administrator'));
98106

99-
if ( apbct_is_user_role_in(array('administrator')) ) {
107+
if (is_array($roles_list) && apbct_is_user_role_in($roles_list) ) {
100108
wp_add_dashboard_widget(
101109
'ct_dashboard_statistics_widget',
102110
$actual_plugin_name,
@@ -172,7 +180,7 @@ function ct_dashboard_statistics_widget_output($_post, $_callback_args)
172180
"<u>{$apbct->brief_data['error']}</u>"
173181
)
174182
. '</h2>';
175-
if ( $apbct->user_token && ! $apbct->white_label ) {
183+
if (apbct_is_user_role_in(array('administrator')) && $apbct->user_token && ! $apbct->white_label ) {
176184
$link = LinkConstructor::buildCleanTalkLink(
177185
'anti_crawler_inactive',
178186
'my',
@@ -225,7 +233,7 @@ function ct_dashboard_statistics_widget_output($_post, $_callback_args)
225233
} ?>
226234
</table>
227235
<?php
228-
if ( $apbct->user_token && ! $apbct->data["wl_mode_enabled"] ) {
236+
if (apbct_is_user_role_in(array('administrator')) && $apbct->user_token && ! $apbct->data["wl_mode_enabled"] ) {
229237
$link = LinkConstructor::buildCleanTalkLink(
230238
'dashboard_widget_all_data_link',
231239
'my/show_requests',
@@ -244,50 +252,55 @@ function ct_dashboard_statistics_widget_output($_post, $_callback_args)
244252
<?php
245253
}
246254
// Notice at the bottom
247-
if ( isset($current_user) && in_array('administrator', $current_user->roles) ) {
248-
if ( $apbct->spam_count && $apbct->spam_count > 0 ) {
255+
if ( $apbct->spam_count && $apbct->spam_count > 0 ) {
256+
$cp_total_stats = '';
257+
//Link to CP is only for admins due the token provided
258+
if ( apbct_is_user_role_in(array('administrator')) ) {
249259
$link = LinkConstructor::buildCleanTalkLink(
250260
'dashboard_widget_go_to_cp',
251261
'my',
252262
array(
253263
'user_token' => $apbct->user_token,
254-
'cp_mode' => 'antispam'
264+
'cp_mode' => 'antispam'
255265
)
256266
);
257-
echo '<div class="ct_widget_wprapper_total_blocked">'
258-
. ($apbct->data["wl_mode_enabled"] ? '' : '<img src="' . Escape::escUrl($apbct->logo__small__colored) . '" class="ct_widget_small_logo"/>')
259-
. '<span title="' . sprintf(
260-
__(
261-
'This is the count from the %s\'s cloud and could be different to admin bar counters',
262-
'cleantalk-spam-protect'
263-
) . '">',
264-
$actual_plugin_name
265-
)
266-
. sprintf(
267-
/* translators: %s: Number of spam messages */
268-
__(
269-
'%s%s%s has blocked %s spam for past year. The statistics are automatically updated every 24 hours.',
270-
'cleantalk-spam-protect'
271-
),
272-
! $apbct->data["wl_mode_enabled"] ? '<a href="' . $link . '" target="_blank">' : '',
273-
$actual_plugin_name,
274-
! $apbct->data["wl_mode_enabled"] ? '</a>' : '',
275-
number_format($apbct->data['spam_count'], 0, ',', ' ')
276-
)
277-
. '</span>'
278-
. (! $apbct->white_label && ! $apbct->data["wl_mode_enabled"]
279-
? '<br><br>'
280-
. '<b style="font-size: 16px;">'
281-
. sprintf(
282-
__('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'),
283-
'<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">',
284-
'</a></u>'
285-
)
286-
. '</b>'
287-
: ''
288-
)
289-
. '</div>';
267+
$cp_total_stats =
268+
($apbct->data["wl_mode_enabled"] ? '' : '<img src="' . Escape::escUrl($apbct->logo__small__colored) . '" class="ct_widget_small_logo"/>')
269+
. '<span title="'
270+
. sprintf(
271+
__(
272+
'This is the count from the %s\'s cloud and could be different to admin bar counters',
273+
'cleantalk-spam-protect'
274+
) . '">',
275+
$actual_plugin_name
276+
)
277+
. sprintf(
278+
/* translators: %s: Number of spam messages */
279+
__(
280+
'%s%s%s has blocked %s spam for past year. The statistics are automatically updated every 24 hours.',
281+
'cleantalk-spam-protect'
282+
),
283+
! $apbct->data["wl_mode_enabled"] ? '<a href="' . $link . '" target="_blank">' : '',
284+
$actual_plugin_name,
285+
! $apbct->data["wl_mode_enabled"] ? '</a>' : '',
286+
number_format($apbct->data['spam_count'], 0, ',', ' ')
287+
)
288+
. '</span>';
290289
}
290+
echo '<div class="ct_widget_wprapper_total_blocked">'
291+
. $cp_total_stats
292+
. (! $apbct->white_label && ! $apbct->data["wl_mode_enabled"]
293+
? '<br><br>'
294+
. '<b style="font-size: 16px;">'
295+
. sprintf(
296+
__('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'),
297+
'<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">',
298+
'</a></u>'
299+
)
300+
. '</b>'
301+
: ''
302+
)
303+
. '</div>';
291304
}
292305
echo '</div>';
293306
}
@@ -527,10 +540,18 @@ function apbct_admin__enqueue_scripts($hook)
527540
$data = array_merge($data, EmailEncoder::getLocalizationText());
528541
wp_localize_script('cleantalk-admin-js', 'ctAdminCommon', $data);
529542

543+
/**
544+
* Hook. List of allowed user roles for the Dashboard widget.
545+
* add_filter('apbct_hook_dashboard_widget_allowed_roles_list', function($roles_list) {
546+
* $roles_list[] = 'editor';
547+
* return $roles_list;
548+
* });
549+
*/
550+
$roles_list = apply_filters('apbct_hook_dashboard_widget_allowed_roles_list', array('administrator'));
530551
// DASHBOARD page JavaScript and CSS
531552
if (
532553
$hook == 'index.php' &&
533-
apbct_is_user_role_in(array('administrator')) &&
554+
is_array($roles_list) && apbct_is_user_role_in($roles_list) &&
534555
$apbct->settings['wp__dashboard_widget__show'] &&
535556
! $apbct->moderate_ip
536557
) {

inc/cleantalk-ajax.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@
129129
*/
130130
function ct_validate_email_ajaxlogin($email = null)
131131
{
132-
$email = is_null($email) ? $email : Post::get('email');
133-
$email = \Cleantalk\ApbctWP\Sanitize::cleanEmail($email);
134-
$is_good = ! ( ! filter_var($email, FILTER_VALIDATE_EMAIL) || email_exists($email));
135-
136132
if ( class_exists('AjaxLogin') && Post::get('action') === 'validate_email' ) {
133+
$email = is_null($email) ? $email : Post::get('email');
134+
$email = \Cleantalk\ApbctWP\Sanitize::cleanEmail($email);
135+
$is_good = ! ( ! filter_var($email, FILTER_VALIDATE_EMAIL) || email_exists($email));
136+
137137
$sender_info = array();
138138
$checkjs = apbct_js_test(TT::toString(Post::get('ct_checkjs')));
139139
$sender_info['post_checkjs_passed'] = $checkjs;
@@ -156,25 +156,25 @@ function ct_validate_email_ajaxlogin($email = null)
156156
$is_good = false;
157157
}
158158
}
159-
}
160159

161-
if ( $is_good ) {
162-
$ajaxresult = array(
163-
'description' => null,
164-
'cssClass' => 'noon',
165-
'code' => 'success'
166-
);
167-
} else {
168-
$ajaxresult = array(
169-
'description' => 'Invalid Email',
170-
'cssClass' => 'error-container',
171-
'code' => 'error'
172-
);
173-
}
160+
if ( $is_good ) {
161+
$ajaxresult = array(
162+
'description' => null,
163+
'cssClass' => 'noon',
164+
'code' => 'success'
165+
);
166+
} else {
167+
$ajaxresult = array(
168+
'description' => 'Invalid Email',
169+
'cssClass' => 'error-container',
170+
'code' => 'error'
171+
);
172+
}
174173

175-
$ajaxresult = json_encode($ajaxresult);
176-
print $ajaxresult;
177-
wp_die();
174+
$ajaxresult = json_encode($ajaxresult);
175+
print $ajaxresult;
176+
wp_die();
177+
}
178178
}
179179

180180
/**

inc/cleantalk-common.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,21 @@ function apbct_base_call($params = array(), $reg_flag = false)
221221
! apbct_is_trackback() &&
222222
! defined('XMLRPC_REQUEST')
223223
) {
224-
$params['exception_action'] = 1;
224+
/**
225+
* If the constant APBCT_SERVICE__DISABLE_EMPTY_EMAIL_EXCEPTION is defined,
226+
* it means that the exception action should be disabled for empty email checks.
227+
*
228+
* Check all post data option ignore this constant.
229+
* @since 6.58.99
230+
*/
231+
if (
232+
$apbct->service_constants->disable_empty_email_exception->isDefined() &&
233+
!$apbct->settings['data__general_postdata_test']
234+
) {
235+
$params['exception_action'] = 0;
236+
} else {
237+
$params['exception_action'] = 1;
238+
}
225239
}
226240
/**
227241
* Skip checking excepted requests if the "Log excluded requests" option is disabled.
@@ -410,11 +424,16 @@ function apbct_exclusions_check__url()
410424
$exclusions = explode(',', $apbct->settings['exclusions__urls']);
411425
}
412426

427+
$rest_url_only_path = apbct_get_rest_url_only_path();
413428
// Fix for AJAX and WP REST API forms
414429
$haystack =
415430
(
416431
Server::get('REQUEST_URI') === '/wp-admin/admin-ajax.php' ||
417-
stripos(TT::toString(Server::get('REQUEST_URI')), '/wp-json/') === 0
432+
stripos(TT::toString(Server::getString('REQUEST_URI')), '/wp-json/') === 0 ||
433+
(
434+
$rest_url_only_path !== 'index.php' &&
435+
stripos(TT::toString(Server::getString('REQUEST_URI')), $rest_url_only_path) === 0
436+
)
418437
) &&
419438
TT::toString(Server::get('HTTP_REFERER'))
420439
? str_ireplace(

inc/cleantalk-integrations-by-hook.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,16 @@
420420
'setting' => 'forms__registrations_test',
421421
'ajax' => true
422422
),
423+
'QuickCal' => array(
424+
'hook' => 'booked_add_appt',
425+
'setting' => 'forms__contact_forms_test',
426+
'ajax' => true
427+
),
428+
'RegistrationMagic' => array(
429+
'hook' => 'rm_validate_before_form_submit',
430+
'setting' => 'forms__registrations_test',
431+
'ajax' => false
432+
),
423433
);
424434

425435
add_action('plugins_loaded', function () use ($apbct_active_integrations) {

0 commit comments

Comments
 (0)