Skip to content
2 changes: 1 addition & 1 deletion cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: Anti-Spam by CleanTalk
Plugin URI: https://cleantalk.org
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.
Version: 6.74.99-dev
Version: 6.76.99-dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is for tests, then it should be returned to the current productive one.

Author: CleanTalk - Anti-Spam Protection <welcome@cleantalk.org>
Author URI: https://cleantalk.org
Text Domain: cleantalk-spam-protect
Expand Down
24 changes: 22 additions & 2 deletions inc/cleantalk-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,6 @@ function apbct__bot_detector_get_fired_exclusions()
*/
function apbct__bot_detector_get_fd_log()
{
global $apbct;
$result = array(
'plugin_status' => 'OK',
'error_msg' => '',
Expand All @@ -1872,7 +1871,7 @@ function apbct__bot_detector_get_fd_log()
}

try {
if ( TT::toString($apbct->settings['data__bot_detector_enabled']) === '0') {
if ( ! apbct__is_bot_detector_enabled() ) {
throw new \Exception('bot detector library usage is disabled');
}
// Retrieve bot detector frontend data log from Alt Sessions
Expand Down Expand Up @@ -1929,3 +1928,24 @@ function apbct__bot_detector_get_custom_exclusion_from_settings()
}
return $exclusions;
}

/**
* Check if Bot-Detector is enabled/disabled
*
* @return bool
*/
function apbct__is_bot_detector_enabled()
{
global $apbct;

// Constant is preferred
if ( isset($apbct->service_constants->bot_detector_enabled) && $apbct->service_constants->bot_detector_enabled->isDefined() ) {
return (bool) $apbct->service_constants->bot_detector_enabled->getValue();
}
// Check by $apbct->data
if ( isset($apbct->data['bot_detector_enabled']) ) {
return (bool) $apbct->data['bot_detector_enabled'];
}
// By default - enabled
return true;
}
6 changes: 3 additions & 3 deletions inc/cleantalk-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function apbct_init()
$apbct->settings['data__pixel'] &&
empty($apbct->pixel_url) &&
!(
$apbct->settings['data__bot_detector_enabled'] === '1' &&
apbct__is_bot_detector_enabled() &&
$apbct->settings['data__pixel'] === '3'
)
) {
Expand Down Expand Up @@ -540,7 +540,7 @@ function apbct_hook__wp_footer()
(
$apbct->settings['data__pixel'] === '3' &&
! apbct_is_cache_plugins_exists() &&
$apbct->settings['data__bot_detector_enabled'] !== '1'
! apbct__is_bot_detector_enabled()
)
) {
echo '<img alt="Cleantalk Pixel" title="Cleantalk Pixel" id="apbct_pixel" style="display: none;" src="' . Escape::escUrl($apbct->pixel_url) . '">';
Expand Down Expand Up @@ -1245,7 +1245,7 @@ function apbct_enqueue_and_localize_public_scripts()
ApbctEnqueue::getInstance()->js($bundle_name, array(), $in_footer);

// Bot detector
if ( $apbct->settings['data__bot_detector_enabled'] && ! apbct_bot_detector_scripts_exclusion()) {
if ( apbct__is_bot_detector_enabled() && ! apbct_bot_detector_scripts_exclusion()) {
// Attention! Skip old enqueue way for external script.
wp_enqueue_script(
'ct_bot_detector',
Expand Down
30 changes: 21 additions & 9 deletions inc/cleantalk-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,17 @@ function apbct_settings__set_fields()
'callback' => 'apbct_settings__check_alt_cookies_types'
),
//bot detector
'data__bot_detector_enabled' => array(
'title' => __('Use ', 'cleantalk-spam-protect')
. $apbct->data['wl_brandname']
. __(' JavaScript library', 'cleantalk-spam-protect'),
'description' => __('This option includes external ', 'cleantalk-spam-protect')
. $apbct->data['wl_brandname']
. __(' JavaScript library to getting visitors info data', 'cleantalk-spam-protect'),
'childrens' => array('exclusions__bot_detector')
'bot_detector_state' => array(
'callback' => function () {
printf(
esc_html__('JavaScript library (Bot Detector) is %s', 'cleantalk-spam-protect'),
apbct__is_bot_detector_enabled()
? esc_html__('enabled', 'cleantalk-spam-protect')
: esc_html__('disabled', 'cleantalk-spam-protect')
);
},
'long_description' => true,
'display' => apbct__is_bot_detector_enabled(),
),
'exclusions__bot_detector' => array(
'title' => __('JavaScript Library Exclusions', 'cleantalk-spam-protect'),
Expand All @@ -588,28 +591,31 @@ function apbct_settings__set_fields()
'Regular expression. Use to skip a HTML form from special service field attach.',
'cleantalk-spam-protect'
),
'parent' => 'data__bot_detector_enabled',
'display' => apbct__is_bot_detector_enabled(),
),
'exclusions__bot_detector__form_attributes' => array(
'type' => 'text',
'title' => __('Exclude any forms that has attribute matches.', 'cleantalk-spam-protect'),
'parent' => 'exclusions__bot_detector',
'class' => 'apbct_settings-field_wrapper--sub',
'long_description' => true,
'display' => apbct__is_bot_detector_enabled(),
),
'exclusions__bot_detector__form_children_attributes' => array(
'type' => 'text',
'title' => __('Exclude any forms that includes a child element with attribute matches.', 'cleantalk-spam-protect'),
'parent' => 'exclusions__bot_detector',
'class' => 'apbct_settings-field_wrapper--sub',
'long_description' => true,
'display' => apbct__is_bot_detector_enabled(),
),
'exclusions__bot_detector__form_parent_attributes' => array(
'type' => 'text',
'title' => __('Exclude any forms that includes a parent element with attribute matches.', 'cleantalk-spam-protect'),
'parent' => 'exclusions__bot_detector',
'class' => 'apbct_settings-field_wrapper--sub',
'long_description' => true,
'display' => apbct__is_bot_detector_enabled(),
),
'wp__use_builtin_http_api' => array(
'title' => __("Use WordPress HTTP API", 'cleantalk-spam-protect'),
Expand Down Expand Up @@ -3155,6 +3161,12 @@ function apbct_settings__get__long_description()
'title' => __('Contact data encoding', 'cleantalk-spam-protect'),
'desc' => ContactsEncoder::getEmailEncoderCommonLongDescription(),
),
'bot_detector_state' => array(
'title' => esc_html__('JavaScript library (Bot Detector)', 'cleantalk-spam-protect'),
'desc' => esc_html__('The state of this option is now controlled by a constant', 'cleantalk-spam-protect')
. ' '
. '`APBCT_SERVICE__BOT_DETECTOR_ENABLED`'
),
);

if (!empty($setting_id) && isset($descriptions[$setting_id])) {
Expand Down
11 changes: 11 additions & 0 deletions inc/cleantalk-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -1377,3 +1377,14 @@ function apbct_update_to_6_60_0()
}
}
}

function apbct_update_to_6_76_0()
{
global $apbct;

if ( isset($apbct->settings['data__bot_detector_enabled']) ) {
$bot_detector_state = $apbct->settings['data__bot_detector_enabled'];
$apbct->data['bot_detector_enabled'] = $bot_detector_state;
$apbct->saveData();
}
}
2 changes: 1 addition & 1 deletion js/apbct-public-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/apbct-public-bundle_ext-protection.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/apbct-public-bundle_ext-protection_gathering.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/apbct-public-bundle_full-protection.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/apbct-public-bundle_full-protection_gathering.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/apbct-public-bundle_gathering.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/apbct-public-bundle_int-protection.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/apbct-public-bundle_int-protection_gathering.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/cleantalk-admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/cleantalk-admin.min.js.map

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions js/prebuild/apbct-public-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function apbctAjaxEmailDecodeBulk(event, encodedEmailNodes, clickSource) {
referrer: document.referrer,
encodedEmails: '',
};
if (ctPublic.settings__data__bot_detector_enabled == 1) {
if (+ctPublic.bot_detector_enabled) {
data.event_token = apbctLocalStorage.get('bot_detector_event_token');
} else {
data.event_javascript_data = getJavascriptClientData();
Expand Down Expand Up @@ -1906,7 +1906,7 @@ class ApbctFetchProxyProtection {
data.raw_body = bodyText;
}

if (+ctPublic.settings__data__bot_detector_enabled) {
if (+ctPublic.bot_detector_enabled) {
const eventToken = new ApbctHandler().toolGetEventToken();
if (eventToken) {
data.ct_bot_detector_event_token = eventToken;
Expand Down Expand Up @@ -1992,6 +1992,7 @@ class ApbctFetchProxyProtection {
return await this.checkRequest(match.formKey, match.config, bodyText);
}
}

/**
* Set init params
*/
Expand Down Expand Up @@ -2129,7 +2130,7 @@ function ctSetCookie( cookies, value, expires ) {
// do it just once
ctSetAlternativeCookie(cookies, {forceAltCookies: true});
} else {
if (!+ctPublic.settings__data__bot_detector_enabled) {
if (!+ctPublic.bot_detector_enabled) {
ctNoCookieAttachHiddenFieldsToForms();
}
}
Expand Down Expand Up @@ -2167,7 +2168,7 @@ function ctSetAlternativeCookie(cookies, params) {
if (Array.isArray(cookies)) {
cookies = getJavascriptClientData(cookies);
}
} else if (!+ctPublic.settings__data__bot_detector_enabled) {
} else if (!+ctPublic.bot_detector_enabled) {
console.log('APBCT ERROR: getJavascriptClientData() is not loaded');
}

Expand Down Expand Up @@ -2624,7 +2625,7 @@ class ApbctAttachData {
if (typeof ctPublic.force_alt_cookies == 'undefined' ||
(ctPublic.force_alt_cookies !== 'undefined' && !ctPublic.force_alt_cookies)
) {
if (!+ctPublic.settings__data__bot_detector_enabled || gatheringLoaded) {
if (!+ctPublic.bot_detector_enabled || gatheringLoaded) {
ctNoCookieAttachHiddenFieldsToForms();
document.addEventListener('gform_page_loaded', ctNoCookieAttachHiddenFieldsToForms);
}
Expand Down Expand Up @@ -2694,7 +2695,7 @@ class ApbctAttachData {
event.target.action && event.target.action.toString().indexOf('mailpoet_subscription_form') !== -1
) {
window.XMLHttpRequest.prototype.send = function(data) {
if (!+ctPublic.settings__data__bot_detector_enabled) {
if (!+ctPublic.bot_detector_enabled) {
const noCookieData = 'data%5Bct_no_cookie_hidden_field%5D=' + getNoCookieData() + '&';
defaultSend.call(this, noCookieData + data);
} else {
Expand Down Expand Up @@ -3009,7 +3010,7 @@ class ApbctHandler {
cronFormsHandler(cronStartTimeout = 2000) {
setTimeout(function() {
setInterval(function() {
if (!+ctPublic.settings__data__bot_detector_enabled && typeof ApbctGatheringData !== 'undefined') {
if (!+ctPublic.bot_detector_enabled && typeof ApbctGatheringData !== 'undefined') {
new ApbctGatheringData().restartFieldsListening();
}
new ApbctEventTokenTransport().restartBotDetectorEventTokenAttach();
Expand Down Expand Up @@ -3082,7 +3083,7 @@ class ApbctHandler {
let addidionalCleantalkData = '';

if (!(
+ctPublic.settings__data__bot_detector_enabled &&
+ctPublic.bot_detector_enabled &&
apbctLocalStorage.get('bot_detector_event_token')
)) {
let noCookieData = getNoCookieData();
Expand All @@ -3099,7 +3100,7 @@ class ApbctHandler {

if (isNeedToAddCleantalkDataCheckFormData) {
if (!(
+ctPublic.settings__data__bot_detector_enabled &&
+ctPublic.bot_detector_enabled &&
apbctLocalStorage.get('bot_detector_event_token')
)) {
let noCookieData = getNoCookieData();
Expand Down Expand Up @@ -3157,7 +3158,7 @@ class ApbctHandler {
args[1].body instanceof FormData || (typeof args[1].body.append === 'function')
) {
if (
+ctPublic.settings__data__bot_detector_enabled &&
+ctPublic.bot_detector_enabled &&
apbctLocalStorage.get('bot_detector_event_token')
) {
args[1].body.append(
Expand Down Expand Up @@ -3317,7 +3318,7 @@ class ApbctHandler {
try {
args[1].body = attachFieldsToBody(
args[1].body,
selectFieldsData(+ctPublic.settings__data__bot_detector_enabled),
selectFieldsData(+ctPublic.bot_detector_enabled),
);
} catch (e) {
// Continue even if error
Expand All @@ -3333,7 +3334,7 @@ class ApbctHandler {
try {
args[1].body = attachFieldsToBody(
args[1].body,
selectFieldsData(+ctPublic.settings__data__bot_detector_enabled),
selectFieldsData(+ctPublic.bot_detector_enabled),
);
} catch (e) {
// Continue even if error
Expand All @@ -3354,7 +3355,7 @@ class ApbctHandler {
if (+ctPublic.settings__forms__wc_add_to_cart) {
args[1].body = attachFieldsToBody(
args[1].body,
selectFieldsData(+ctPublic.settings__data__bot_detector_enabled),
selectFieldsData(+ctPublic.bot_detector_enabled),
);
}
} catch (e) {
Expand Down Expand Up @@ -3583,7 +3584,7 @@ class ApbctHandler {
let noCookieData = '';
let visibleFieldsString = '';
if (
+ctPublic.settings__data__bot_detector_enabled &&
+ctPublic.bot_detector_enabled &&
apbctLocalStorage.get('bot_detector_event_token')
) {
const token = new ApbctHandler().toolGetEventToken();
Expand Down Expand Up @@ -3649,7 +3650,7 @@ class ApbctHandler {
options.data.requests[0].path === '/wc/store/v1/cart/add-item'
) {
if (
+ctPublic.settings__data__bot_detector_enabled &&
+ctPublic.bot_detector_enabled &&
apbctLocalStorage.get('bot_detector_event_token')
) {
let token = localStorage.getItem('bot_detector_event_token');
Expand All @@ -3664,7 +3665,7 @@ class ApbctHandler {
// checkout
if (options.path.includes('/wc/store/v1/checkout')) {
if (
+ctPublic.settings__data__bot_detector_enabled &&
+ctPublic.bot_detector_enabled &&
apbctLocalStorage.get('bot_detector_event_token')
) {
options.data.ct_bot_detector_event_token = localStorage.getItem('bot_detector_event_token');
Expand Down Expand Up @@ -4186,7 +4187,7 @@ async function apbct_ready() {

if (
apbctLocalStorage.get('apbct_existing_visitor') && // Not for the first hit
+ctPublic.settings__data__bot_detector_enabled && // If Bot-Detector is active
+ctPublic.bot_detector_enabled && // If Bot-Detector is active
!apbctLocalStorage.get('bot_detector_event_token') && // and no `event_token` generated
typeof ApbctGatheringData === 'undefined' // and no `gathering` loaded yet
) {
Expand All @@ -4205,7 +4206,7 @@ async function apbct_ready() {

// Gathering data when bot detector is disabled
if (
( ! +ctPublic.settings__data__bot_detector_enabled || gatheringLoaded ) &&
( ! +ctPublic.bot_detector_enabled || gatheringLoaded ) &&
typeof ApbctGatheringData !== 'undefined'
) {
const gatheringData = new ApbctGatheringData();
Expand All @@ -4227,7 +4228,7 @@ async function apbct_ready() {

setTimeout(function() {
// Attach data when bot detector is enabled
if (+ctPublic.settings__data__bot_detector_enabled) {
if (+ctPublic.bot_detector_enabled) {
const eventTokenTransport = new ApbctEventTokenTransport();
eventTokenTransport.attachEventTokenToMultipageGravityForms();
eventTokenTransport.attachEventTokenToWoocommerceGetRequestAddToCart();
Expand All @@ -4236,7 +4237,7 @@ async function apbct_ready() {
const attachData = new ApbctAttachData();

// Attach data when bot detector is disabled or blocked
if (!+ctPublic.settings__data__bot_detector_enabled || gatheringLoaded) {
if (!+ctPublic.bot_detector_enabled || gatheringLoaded) {
attachData.attachHiddenFieldsToForms(gatheringLoaded);
}

Expand All @@ -4263,7 +4264,7 @@ async function apbct_ready() {
handler.catchJqueryAjax();
handler.catchWCRestRequestAsMiddleware();

if (+ctPublic.settings__data__bot_detector_enabled) {
if (+ctPublic.bot_detector_enabled) {
let botDetectorEventTokenStored = false;
window.addEventListener('botDetectorEventTokenUpdated', (event) => {
const botDetectorEventToken = event.detail?.eventToken;
Expand All @@ -4283,7 +4284,7 @@ async function apbct_ready() {
});
}

if (ctPublic.settings__sfw__anti_crawler && +ctPublic.settings__data__bot_detector_enabled) {
if (ctPublic.settings__sfw__anti_crawler && +ctPublic.bot_detector_enabled) {
handler.toolForAntiCrawlerCheckDuringBotDetector();
}

Expand Down Expand Up @@ -4316,8 +4317,8 @@ let botDetectorLogEventTypesCollected = [];

// bot_detector frontend_data log alt session saving cron
if (
ctPublicFunctions.hasOwnProperty('data__bot_detector_enabled') &&
ctPublicFunctions.data__bot_detector_enabled == 1 &&
ctPublicFunctions.hasOwnProperty('bot_detector_enabled') &&
+ctPublicFunctions.bot_detector_enabled &&
ctPublicFunctions.hasOwnProperty('data__frontend_data_log_enabled') &&
ctPublicFunctions.data__frontend_data_log_enabled == 1
) {
Expand Down
Loading
Loading