Skip to content
Open
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
29 changes: 21 additions & 8 deletions cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Cleantalk\Antispam\ProtectByShortcode;
use Cleantalk\ApbctWP\Activator;
use Cleantalk\ApbctWP\AdminNotices;
use Cleantalk\ApbctWP\Constant;
use Cleantalk\ApbctWP\ContactsEncoder\ContactsEncoder;
use Cleantalk\ApbctWP\Antispam\ForceProtection;
use Cleantalk\ApbctWP\API;
Expand Down Expand Up @@ -56,7 +57,18 @@
die('Not allowed!');
}

global $apbct, $wpdb, $pagenow;
/**
* @var State $apbct
*/
global $apbct;
/**
* @var \wpdb $wpdb
*/
global $wpdb;
/**
* @var mixed|string $pagenow
*/
global $pagenow;

$cleantalk_executed = false;

Expand Down Expand Up @@ -129,6 +141,7 @@
}
define('APBCT_AGENT', 'wordpress-' . $plugin_version__agent); // Prepared agent

//todo make this as $apbct->service_constants
if ( defined('CLEANTALK_SERVER') ) {
define('APBCT_MODERATE_URL', 'https://moderate.' . CLEANTALK_SERVER);
if ( ! defined('CLEANTALK_API_URL') ) {
Expand Down Expand Up @@ -263,7 +276,7 @@ function apbct_register_my_rest_routes()
// Database prefix
global $wpdb, $wp_version;
$apbct->db_prefix = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $wpdb->prefix : $wpdb->base_prefix;
$apbct->db_prefix = ! $apbct->white_label && defined('CLEANTALK_ACCESS_KEY') ? $wpdb->base_prefix : $wpdb->prefix;
$apbct->db_prefix = ! $apbct->white_label && Constant::is(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY) ? $wpdb->base_prefix : $wpdb->prefix;

/** @todo HARDCODE FIX */
if ( $apbct->plugin_version === '1.0.0' ) {
Expand Down Expand Up @@ -1253,8 +1266,8 @@ function apbct_sfw_update__switch_to_direct()

$apbct->fw_stats['reason_direct_update_log'] = null;

if (defined('APBCT_SFW_FORCE_DIRECT_UPDATE')) {
$apbct->fw_stats['reason_direct_update_log'] = 'const APBCT_SFW_FORCE_DIRECT_UPDATE exists';
if (Constant::is(Constant::APBCT_SERVICE__SFW_FORCE_DIRECT_UPDATE)) {
$apbct->fw_stats['reason_direct_update_log'] = 'constant exists';
return true;
}

Expand Down Expand Up @@ -2808,15 +2821,15 @@ function ct_account_status_check($api_key = null, $process_errors = true)
: 0;

//todo:temporary solution for description, until we found the way to transfer this from cloud
if (defined('APBCT_WHITELABEL_PLUGIN_DESCRIPTION')) {
if (Constant::is(Constant::APBCT_SERVICE__WHITELABEL_PLUGIN_DESCRIPTION)) {
/** @psalm-suppress PossiblyInvalidArrayAssignment */
$result['wl_antispam_description'] = APBCT_WHITELABEL_PLUGIN_DESCRIPTION;
$result['wl_antispam_description'] = esc_html(Constant::getValue(Constant::APBCT_SERVICE__WHITELABEL_PLUGIN_DESCRIPTION));
}

//todo:temporary solution for FAQ
if (defined('APBCT_WHITELABEL_FAQ_LINK')) {
if (Constant::is(Constant::APBCT_SERVICE__WHITELABEL_FAQ_LINK)) {
/** @psalm-suppress PossiblyInvalidArrayAssignment */
$result['wl_faq_url'] = APBCT_WHITELABEL_FAQ_LINK;
$result['wl_faq_url'] = esc_url(Constant::getValue(Constant::APBCT_SERVICE__WHITELABEL_FAQ_LINK));
}

if ( isset($result['wl_status']) && $result['wl_status'] === 'ON' ) {
Expand Down
9 changes: 5 additions & 4 deletions inc/cleantalk-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cleantalk\ApbctWP\API;
use Cleantalk\ApbctWP\BaseCall\DefaultParams;
use Cleantalk\ApbctWP\CleantalkSettingsTemplates;
use Cleantalk\ApbctWP\Constant;
use Cleantalk\ApbctWP\Cron;
use Cleantalk\ApbctWP\DB;
use Cleantalk\ApbctWP\DTO\GetFieldsAnyDTO;
Expand Down Expand Up @@ -218,7 +219,7 @@ function apbct_base_call($params = array(), $reg_flag = false)
* @since 6.58.99
*/
if (
$apbct->service_constants->disable_empty_email_exception->isDefined() &&
Constant::is(Constant::APBCT_SERVICE__DISABLE_EMPTY_EMAIL_EXCEPTION) &&
!$apbct->settings['data__general_postdata_test']
) {
$params['exception_action'] = 0;
Expand Down Expand Up @@ -1858,7 +1859,7 @@ function apbct__bot_detector_get_fd_log()
);
// Initialize result array with default values

if (defined('APBCT_DO_NOT_COLLECT_FRONTEND_DATA_LOGS')) {
if (Constant::is(Constant::APBCT_SERVICE__DO_NOT_COLLECT_FRONTEND_DATA_LOGS)) {
$result['plugin_status'] = 'OK';
$result['error_msg'] = 'bot detector logs collection is disabled via constant definition';
return json_encode($result);
Expand Down Expand Up @@ -1933,8 +1934,8 @@ 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();
if ( Constant::is(Constant::APBCT_SERVICE__BOT_DETECTOR_ENABLED) ) {
return (bool) Constant::getValue(Constant::APBCT_SERVICE__BOT_DETECTOR_ENABLED);
}
// Check by $apbct->data
if ( isset($apbct->data['bot_detector_enabled']) ) {
Expand Down
8 changes: 4 additions & 4 deletions inc/cleantalk-pluggable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Cleantalk\ApbctWP\AJAXService;
use Cleantalk\ApbctWP\Constant;
use Cleantalk\ApbctWP\Helper;
use Cleantalk\ApbctWP\RemoteCalls;
use Cleantalk\ApbctWP\Variables\Get;
Expand Down Expand Up @@ -2129,10 +2130,9 @@ function apbct_settings__get_ajax_type()
global $apbct;

//force ajax route type if constant is defined and compatible
if ($apbct->service_constants->set_ajax_route_type->isDefined()
&& in_array($apbct->service_constants->set_ajax_route_type->getValue(), array('rest','admin_ajax'))
) {
return $apbct->service_constants->set_ajax_route_type->getValue();
$forced_ajax_route_type = Constant::getValue(Constant::APBCT_SERVICE__SET_AJAX_ROUTE_TYPE);
if ( in_array($forced_ajax_route_type, array('rest', 'admin_ajax'), true) ) {
return $forced_ajax_route_type;
}

// Check rest availability
Expand Down
9 changes: 5 additions & 4 deletions inc/cleantalk-public.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Cleantalk\ApbctWP\ApbctEnqueue;
use Cleantalk\ApbctWP\Constant;
use Cleantalk\ApbctWP\Escape;
use Cleantalk\ApbctWP\Localize\LocalizeHandler;
use Cleantalk\ApbctWP\Sanitize;
Expand Down Expand Up @@ -41,7 +42,7 @@ function apbct_init()

// Localize data
if ( ! apbct_exclusions_check__url() ) {
if (defined('CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER') && CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER) {
if (Constant::is(Constant::APBCT_SERVICE__PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER, true)) {
add_action('wp_footer', array(LocalizeHandler::class, 'handle'), 1);
add_action('login_footer', array(LocalizeHandler::class, 'handle'), 1);
} else {
Comment on lines 44 to 48

@alexander-b-clean alexander-b-clean Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Expand Down Expand Up @@ -821,7 +822,7 @@ function ct_die($_comment_id, $_comment_status)
do_action('apbct_pre_block_page', $ct_comment);

$message_title = __('Spam protection', 'cleantalk-spam-protect');
if ( defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE != true ) {
if ( ! Constant::is(Constant::APBCT_SERVICE__DISABLE_BLOCKING_TITLE, true) ) {
$message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
}
if ( Post::get('et_pb_contact_email') ) {
Expand Down Expand Up @@ -878,7 +879,7 @@ function ct_die_extended($comment_body)
}, 999, 1);

$message_title = __('Spam protection', 'cleantalk-spam-protect');
if ( defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE != true ) {
if ( ! Constant::is(Constant::APBCT_SERVICE__DISABLE_BLOCKING_TITLE, true) ) {
$message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
}

Expand Down Expand Up @@ -1263,7 +1264,7 @@ function apbct_enqueue_and_localize_public_scripts()
{
global $apbct;

$in_footer = defined('CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER') && CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER;
$in_footer = Constant::is(Constant::APBCT_SERVICE__PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER, true);
// Different JS params
$bundle_name = ApbctJsBundleResolver::getBundleName($apbct->settings);
ApbctEnqueue::getInstance()->js($bundle_name, array(), $in_footer);
Expand Down
16 changes: 11 additions & 5 deletions inc/cleantalk-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Cleantalk\ApbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentHandler;
use Cleantalk\ApbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentSettings;
use Cleantalk\ApbctWP\AJAXService;
use Cleantalk\ApbctWP\Constant;
use Cleantalk\ApbctWP\ContactsEncoder\ContactsEncoder;
use Cleantalk\ApbctWP\Escape;
use Cleantalk\ApbctWP\Helper;
Expand Down Expand Up @@ -492,7 +493,7 @@ function apbct_settings__set_fields()
'title' => __("Don't check trusted user's comments", 'cleantalk-spam-protect'),
'description' => sprintf(
__("Don't check comments for users with above %d comments.", 'cleantalk-spam-protect'),
defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3
Constant::getValue(Constant::APBCT_SERVICE__SKIP_ON_APPROVED_COMMENTS_NUMBER, 3)
),
),
'data__use_ajax' => array(
Expand Down Expand Up @@ -1148,7 +1149,7 @@ function apbct_settings__set_fields__network($fields)
'</a>'
),
'childrens' => array('multisite__white_label__plugin_name'),
'disabled' => defined('CLEANTALK_ACCESS_KEY') ||
'disabled' => Constant::is(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY) ||
! isset($apbct->network_settings['multisite__work_mode']) ||
$apbct->network_settings['multisite__work_mode'] != 1,
'parent' => 'multisite__work_mode',
Expand Down Expand Up @@ -1757,7 +1758,7 @@ function apbct_settings__error__output($return = false)

$out = '';

if ( ! empty($apbct->errors) && ! defined('CLEANTALK_ACCESS_KEY') ) {
if ( ! empty($apbct->errors) && ! Constant::is(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY) ) {
$errors = $apbct->errors;

$error_texts = array(
Expand Down Expand Up @@ -2051,7 +2052,10 @@ function apbct_settings__field__apikey()

$template = @file_get_contents(CLEANTALK_PLUGIN_DIR . 'templates/settings/settings_key_wrapper.html');

$define_key_is_provided_by_admin = APBCT_WPMS && ! is_main_site() && ( ! $apbct->allow_custom_key || defined('CLEANTALK_ACCESS_KEY'));
$define_key_is_provided_by_admin = APBCT_WPMS && ! is_main_site() && (
! $apbct->allow_custom_key ||
Constant::is(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY)
);
$define_show_key_field = ! (apbct_api_key__is_correct($apbct->api_key) && isset($apbct->data["key_changed"]) && $apbct->data["key_changed"]);
$define_show_deobfuscating_href = apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok && (!isset($apbct->data["key_changed"]) || !$apbct->data["key_changed"]);

Expand Down Expand Up @@ -2424,8 +2428,10 @@ function apbct_settings__validate($incoming_settings)

$apbct->data['key_changed'] = $incoming_settings['apikey'] !== $apbct->settings['apikey'];

$predefined_key = Constant::getValue(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY, false);

$incoming_settings['apikey'] = ! empty($incoming_settings['apikey']) ? trim($incoming_settings['apikey']) : '';
$incoming_settings['apikey'] = defined('CLEANTALK_ACCESS_KEY') ? CLEANTALK_ACCESS_KEY : $incoming_settings['apikey'];
$incoming_settings['apikey'] = $predefined_key !== false ? $predefined_key : $incoming_settings['apikey'];
$incoming_settings['apikey'] = ! is_main_site() && $apbct->white_label && $apbct->settings['apikey'] ? $apbct->settings['apikey'] : $incoming_settings['apikey'];
$incoming_settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $incoming_settings['apikey'] : $apbct->network_settings['apikey'];
$incoming_settings['apikey'] = is_main_site() || ! isset($incoming_settings['multisite__white_label']) || ! $incoming_settings['multisite__white_label']
Expand Down
14 changes: 10 additions & 4 deletions lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cleantalk\Antispam\Integrations;

use Cleantalk\ApbctWP\CleantalkRealPerson;
use Cleantalk\ApbctWP\Constant;
use Cleantalk\ApbctWP\Sanitize;
use Cleantalk\ApbctWP\Variables\AltSessions;
use Cleantalk\ApbctWP\Variables\Cookie;
Expand Down Expand Up @@ -64,7 +65,10 @@ public function doPrepareActions($argument)
$this->wp_comment_post_id = $comment_post_id;

$this->post_info = array();
$this->comments_check_number_needs_to_skip_request = defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3;
$this->comments_check_number_needs_to_skip_request = Constant::getValue(
Constant::APBCT_SERVICE__SKIP_ON_APPROVED_COMMENTS_NUMBER,
3
);

/**
* Custom mail notifications processing
Expand Down Expand Up @@ -329,9 +333,11 @@ public function doBlock($message)

$err_text =
'<center>'
. ((defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE == true)
? ''
: '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ')
. (
Constant::is(Constant::APBCT_SERVICE__DISABLE_BLOCKING_TITLE, true)
? ''
: '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> '
)
. __('Spam protection', 'cleantalk-spam-protect')
. "</center><br><br>\n"
. $ct_result->comment;
Expand Down
3 changes: 2 additions & 1 deletion lib/Cleantalk/Antispam/IntegrationsByClass/BuddyPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleantalk\Antispam\IntegrationsByClass;

use Cleantalk\ApbctWP\Constant;
use Cleantalk\ApbctWP\Escape;
use Cleantalk\ApbctWP\Variables\Post;
use Cleantalk\ApbctWP\Variables\Server;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function privateMsgCheck($bp_message_obj)
}

// Check for quantity of comments
$comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3;
$comments_check_number = Constant::getValue(Constant::APBCT_SERVICE__SKIP_ON_APPROVED_COMMENTS_NUMBER, 3);

if ( $apbct->settings['comments__check_comments_number'] ) {
$args = array(
Expand Down
2 changes: 1 addition & 1 deletion lib/Cleantalk/ApbctWP/Activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function activation($network_wide, $concrete_blog_id = null)
$apbct->stats['plugin']['activation__times'] += 1;
$apbct->save('stats');

if ( $network_wide && ! defined('CLEANTALK_ACCESS_KEY') ) {
if ( $network_wide && ! Constant::is(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY) ) {
$initial_blog = get_current_blog_id();
$blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
foreach ( $blogs as $blog ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cleantalk/ApbctWP/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function __construct()
in_array(Get::get('page'), array('cleantalk', 'ct_check_spam', 'ct_check_users'));
$this->user_token = $this->apbct->user_token ?: '';

$self_owned_key = $this->apbct->moderate_ip == 0 && ! defined('CLEANTALK_ACCESS_KEY');
$self_owned_key = $this->apbct->moderate_ip == 0 && ! Constant::is(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY);
$is_dashboard = is_network_admin() || is_admin();
$is_admin = current_user_can('activate_plugins');
$uid = get_current_user_id();
Expand Down
67 changes: 0 additions & 67 deletions lib/Cleantalk/ApbctWP/ApbctConstant.php

This file was deleted.

Loading
Loading