Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ on: # event list
- beta
- master
pull_request:
branches:
- dev
- master

env: # environment variables (available in any part of the action)
PHP_VERSION: 7.4
Expand All @@ -32,6 +29,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
coverage: xdebug

- name: Run MySQL server
run: sudo systemctl start mysql
Expand Down
24 changes: 22 additions & 2 deletions inc/cleantalk-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,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 @@ -1874,7 +1873,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 @@ -1931,3 +1930,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
32 changes: 23 additions & 9 deletions inc/cleantalk-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,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 @@ -584,28 +587,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 @@ -3150,6 +3156,14 @@ 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 Bot Detector is a JavaScript library that runs in the visitor's browser and collects behavioral signals to distinguish real users from bots.", 'cleantalk-spam-protect')
. '<br><br>' . esc_html__("This data is sent to the CleanTalk cloud along with each spam check request, significantly improving detection accuracy for spam on any website forms.", 'cleantalk-spam-protect')
. '<br><br>' . esc_html__("Disabling the Bot Detector will reduce anti-spam effectiveness.", 'cleantalk-spam-protect')
. '<br>' . esc_html__("It can only be disabled by adding the following constant to your wp-config.php: define('APBCT_SERVICE__BOT_DETECTOR_ENABLED', false);", 'cleantalk-spam-protect')
. '<br>' . esc_html__("We do not recommend disabling this functionality.", 'cleantalk-spam-protect')
),
);

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();
}
}
Loading
Loading