diff --git a/cleantalk.php b/cleantalk.php
index defd42bf1..45ecb5539 100644
--- a/cleantalk.php
+++ b/cleantalk.php
@@ -52,7 +52,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;
@@ -125,6 +136,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') ) {
@@ -253,7 +265,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 && $apbct->constants->self_owned_access_key->isDefinedAndTypeOK() ? $wpdb->base_prefix : $wpdb->prefix;
/** @todo HARDCODE FIX */
if ( $apbct->plugin_version === '1.0.0' ) {
@@ -1209,8 +1221,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 ($apbct->constants->sfw_force_direct_update->isDefined()) {
+ $apbct->fw_stats['reason_direct_update_log'] = 'constant exists';
return true;
}
@@ -2771,15 +2783,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 ($apbct->constants->whitelabel_plugin_description->isDefinedAndTypeOK()) {
/** @psalm-suppress PossiblyInvalidArrayAssignment */
- $result['wl_antispam_description'] = APBCT_WHITELABEL_PLUGIN_DESCRIPTION;
+ $result['wl_antispam_description'] = esc_html($apbct->constants->whitelabel_plugin_description->getValue());
}
//todo:temporary solution for FAQ
- if (defined('APBCT_WHITELABEL_FAQ_LINK')) {
+ if ($apbct->constants->whitelabel_faq_link->isDefinedAndTypeOK()) {
/** @psalm-suppress PossiblyInvalidArrayAssignment */
- $result['wl_faq_url'] = APBCT_WHITELABEL_FAQ_LINK;
+ $result['wl_faq_url'] = esc_url($apbct->constants->whitelabel_faq_link->getValue());
}
if ( isset($result['wl_status']) && $result['wl_status'] === 'ON' ) {
diff --git a/inc/cleantalk-common.php b/inc/cleantalk-common.php
index d6fafe165..6678d985d 100644
--- a/inc/cleantalk-common.php
+++ b/inc/cleantalk-common.php
@@ -232,7 +232,7 @@ function apbct_base_call($params = array(), $reg_flag = false)
* @since 6.58.99
*/
if (
- $apbct->service_constants->disable_empty_email_exception->isDefined() &&
+ $apbct->constants->disable_empty_email_exception->isDefined() &&
!$apbct->settings['data__general_postdata_test']
) {
$params['exception_action'] = 0;
@@ -1841,7 +1841,7 @@ function apbct__bot_detector_get_fd_log()
);
// Initialize result array with default values
- if (defined('APBCT_DO_NOT_COLLECT_FRONTEND_DATA_LOGS')) {
+ if ($apbct->constants->do_not_collect_frontend_data_logs->isDefined()) {
$result['plugin_status'] = 'OK';
$result['error_msg'] = 'bot detector logs collection is disabled via constant definition';
return json_encode($result);
diff --git a/inc/cleantalk-pluggable.php b/inc/cleantalk-pluggable.php
index b3fce585e..8cc167201 100644
--- a/inc/cleantalk-pluggable.php
+++ b/inc/cleantalk-pluggable.php
@@ -2001,10 +2001,10 @@ 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'))
+ if ($apbct->constants->set_ajax_route_type->isDefinedAndTypeOK()
+ && in_array($apbct->constants->set_ajax_route_type->getValue(), array('rest','admin_ajax'))
) {
- return $apbct->service_constants->set_ajax_route_type->getValue();
+ return $apbct->constants->set_ajax_route_type->getValue();
}
// Check rest availability
diff --git a/inc/cleantalk-public.php b/inc/cleantalk-public.php
index 651bb72c1..4ba3ed6da 100644
--- a/inc/cleantalk-public.php
+++ b/inc/cleantalk-public.php
@@ -41,7 +41,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 ($apbct->constants->place_public_js_scripts_in_footer->isDefined()) {
add_action('wp_footer', array(LocalizeHandler::class, 'handle'), 1);
add_action('login_footer', array(LocalizeHandler::class, 'handle'), 1);
} else {
@@ -771,7 +771,7 @@ function apbct_comment__wordpress__show_blacklists($notify_message, $comment_id)
*/
function ct_die($_comment_id, $_comment_status)
{
- global $ct_comment, $ct_jp_comments;
+ global $ct_comment, $ct_jp_comments, $apbct;
// JCH Optimize caching preventing
add_filter('jch_optimize_page_cache_set_caching', static function ($_is_cache_active) {
@@ -781,7 +781,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 ( ! $apbct->constants->disable_blocking_title->isDefined() ) {
$message_title = 'CleanTalk. ' . $message_title;
}
if ( Post::get('et_pb_contact_email') ) {
@@ -826,7 +826,7 @@ function ct_die($_comment_id, $_comment_status)
*/
function ct_die_extended($comment_body)
{
- global $ct_jp_comments;
+ global $ct_jp_comments, $apbct;
// JCH Optimize caching preventing
add_filter('jch_optimize_page_cache_set_caching', static function ($_is_cache_active) {
@@ -834,7 +834,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 ( !$apbct->constants->disable_blocking_title->isDefined() ) {
$message_title = 'CleanTalk. ' . $message_title;
}
@@ -1229,7 +1229,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 = $apbct->constants->place_public_js_scripts_in_footer->isDefined();
// Different JS params
$bundle_name = ApbctJsBundleResolver::getBundleName($apbct->settings);
ApbctEnqueue::getInstance()->js($bundle_name, array(), $in_footer);
diff --git a/inc/cleantalk-settings.php b/inc/cleantalk-settings.php
index b45397431..8b09862ef 100644
--- a/inc/cleantalk-settings.php
+++ b/inc/cleantalk-settings.php
@@ -481,7 +481,9 @@ 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
+ $apbct->constants->skip_on_approved_comments_number->isDefinedAndTypeOK()
+ ? $apbct->constants->skip_on_approved_comments_number->getValue()
+ : 3
),
),
'data__use_ajax' => array(
@@ -1139,7 +1141,7 @@ function apbct_settings__set_fields__network($fields)
''
),
'childrens' => array('multisite__white_label__plugin_name'),
- 'disabled' => defined('CLEANTALK_ACCESS_KEY') ||
+ 'disabled' => $apbct->constants->self_owned_access_key->isDefinedAndTypeOK() ||
! isset($apbct->network_settings['multisite__work_mode']) ||
$apbct->network_settings['multisite__work_mode'] != 1,
'parent' => 'multisite__work_mode',
@@ -1605,7 +1607,7 @@ function apbct_settings__error__output($return = false)
$out = '';
- if ( ! empty($apbct->errors) && ! defined('CLEANTALK_ACCESS_KEY') ) {
+ if ( ! empty($apbct->errors) && ! $apbct->constants->self_owned_access_key->isDefinedAndTypeOK() ) {
$errors = $apbct->errors;
$error_texts = array(
@@ -1900,7 +1902,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 ||
+ $apbct->constants->self_owned_access_key->isDefinedAndTypeOK()
+ );
$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"]);
@@ -2231,8 +2236,12 @@ function apbct_settings__validate($settings)
$apbct->data['key_changed'] = $settings['apikey'] !== $apbct->settings['apikey'];
+ $predefined_key = $apbct->constants->self_owned_access_key->isDefinedAndTypeOK()
+ ? $apbct->constants->self_owned_access_key->getValue()
+ : false;
+
$settings['apikey'] = ! empty($settings['apikey']) ? trim($settings['apikey']) : '';
- $settings['apikey'] = defined('CLEANTALK_ACCESS_KEY') ? CLEANTALK_ACCESS_KEY : $settings['apikey'];
+ $settings['apikey'] = $predefined_key ? $predefined_key : $settings['apikey'];
$settings['apikey'] = ! is_main_site() && $apbct->white_label && $apbct->settings['apikey'] ? $apbct->settings['apikey'] : $settings['apikey'];
$settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $settings['apikey'] : $apbct->network_settings['apikey'];
$settings['apikey'] = is_main_site() || ! isset($settings['multisite__white_label']) || ! $settings['multisite__white_label']
diff --git a/lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php b/lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php
index 6784e2414..1c791f986 100644
--- a/lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php
+++ b/lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php
@@ -63,7 +63,9 @@ 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 = $apbct->constants->skip_on_approved_comments_number->isDefinedAndTypeOK()
+ ? $apbct->constants->skip_on_approved_comments_number->getValue()
+ : 3;
/**
* Custom mail notifications processing
@@ -297,7 +299,7 @@ public function doBlock($message)
{
$ct_result = $this->base_call_result['ct_result'];
- global $ct_comment, $ct_stop_words;
+ global $ct_comment, $ct_stop_words, $apbct;
$ct_comment = $message;
$ct_stop_words = $ct_result->stop_words;
/**
@@ -311,9 +313,11 @@ public function doBlock($message)
$err_text =
'
'
- . ((defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE == true)
- ? ''
- : 'CleanTalk. ')
+ . (
+ $apbct->constants->disable_blocking_title->isDefined()
+ ? ''
+ : 'CleanTalk. '
+ )
. __('Spam protection', 'cleantalk-spam-protect')
. "
\n"
. $ct_result->comment;
diff --git a/lib/Cleantalk/Antispam/IntegrationsByClass/BuddyPress.php b/lib/Cleantalk/Antispam/IntegrationsByClass/BuddyPress.php
index 9bb153ae3..04821cc62 100755
--- a/lib/Cleantalk/Antispam/IntegrationsByClass/BuddyPress.php
+++ b/lib/Cleantalk/Antispam/IntegrationsByClass/BuddyPress.php
@@ -78,7 +78,9 @@ 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 = $apbct->constants->skip_on_approved_comments_number->isDefinedAndTypeOK()
+ ? $apbct->constants->skip_on_approved_comments_number->getValue()
+ : 3;
if ( $apbct->settings['comments__check_comments_number'] ) {
$args = array(
diff --git a/lib/Cleantalk/ApbctWP/Activator.php b/lib/Cleantalk/ApbctWP/Activator.php
index f9fb996bb..963e62670 100644
--- a/lib/Cleantalk/ApbctWP/Activator.php
+++ b/lib/Cleantalk/ApbctWP/Activator.php
@@ -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 && ! $apbct->constants->self_owned_access_key->isDefinedAndTypeOK() ) {
$initial_blog = get_current_blog_id();
$blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
foreach ( $blogs as $blog ) {
diff --git a/lib/Cleantalk/ApbctWP/AdminNotices.php b/lib/Cleantalk/ApbctWP/AdminNotices.php
index 13b18a3b3..41c2b7b82 100644
--- a/lib/Cleantalk/ApbctWP/AdminNotices.php
+++ b/lib/Cleantalk/ApbctWP/AdminNotices.php
@@ -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 && !$this->apbct->constants->self_owned_access_key->isDefinedAndTypeOK();
$is_dashboard = is_network_admin() || is_admin();
$is_admin = current_user_can('activate_plugins');
$uid = get_current_user_id();
diff --git a/lib/Cleantalk/ApbctWP/ApbctConstant.php b/lib/Cleantalk/ApbctWP/ApbctConstant.php
index 10cd8ac28..d34787cf9 100644
--- a/lib/Cleantalk/ApbctWP/ApbctConstant.php
+++ b/lib/Cleantalk/ApbctWP/ApbctConstant.php
@@ -18,17 +18,23 @@ class ApbctConstant
*/
public $description;
- public function __construct(array $allowed_public_names, $description = '')
+ private $type;
+
+ private $defined_name = false;
+
+ public function __construct(array $allowed_public_names, $type, $description = '')
{
$this->allowed_public_names = $allowed_public_names;
$this->description = $description;
+ $this->type = $type;
+ $this->defined_name = $this->getDefinedName();
}
/**
* If defined, returns the name of the first defined constant from the allowed names. Return false if none of the constants are defined.
- * @return false|string
+ * @return string|false
*/
- public function isDefined()
+ private function getDefinedName()
{
foreach ($this->allowed_public_names as $name) {
if (defined($name)) {
@@ -38,17 +44,35 @@ public function isDefined()
return false;
}
+ /**
+ * If defined and type is correct.
+ * @return bool
+ */
+ public function isDefinedAndTypeOK()
+ {
+ return $this->defined_name && gettype(constant($this->defined_name)) === $this->type;
+ }
+
+
+ /**
+ * Return the fact of definition
+ * @return bool
+ * @psalm-suppress PossiblyUnusedMethod
+ */
+ public function isDefined()
+ {
+ return (bool)$this->defined_name;
+ }
+
/**
* Returns the value of the first defined constant from the allowed names. Return null if none of the constants are defined.
*
- * @return string|null
+ * @return mixed|null
*/
public function getValue()
{
- foreach ($this->allowed_public_names as $name) {
- if (defined($name)) {
- return (string)constant($name);
- }
+ if ($this->defined_name) {
+ return constant($this->defined_name);
}
return null;
}
@@ -59,7 +83,7 @@ public function getValue()
public function getData()
{
return array(
- 'is_defined' => $this->isDefined(),
+ 'is_defined' => $this->defined_name,
'value' => $this->getValue(),
'description' => $this->description,
);
diff --git a/lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php b/lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
index aa0d3b4a1..076396cab 100644
--- a/lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
+++ b/lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
@@ -563,7 +563,7 @@ private function checkExclusions()
}
// skip for RSS Feed requests
- if ($apbct->service_constants->skip_anticrawler_on_rss_feed->isDefined()) {
+ if ($apbct->constants->skip_anticrawler_on_rss_feed->isDefined()) {
if (Server::getString('REQUEST_URI') &&
preg_match_all('/feed/i', Server::getString('REQUEST_URI'))
) {
diff --git a/lib/Cleantalk/ApbctWP/Localize/CtPublicFunctionsLocalize.php b/lib/Cleantalk/ApbctWP/Localize/CtPublicFunctionsLocalize.php
index 150c02528..53088f922 100644
--- a/lib/Cleantalk/ApbctWP/Localize/CtPublicFunctionsLocalize.php
+++ b/lib/Cleantalk/ApbctWP/Localize/CtPublicFunctionsLocalize.php
@@ -23,7 +23,7 @@ public static function getData()
'data__cookies_type' => $apbct->data['cookies_type'],
'data__ajax_type' => $apbct->data['ajax_type'],
'data__bot_detector_enabled' => $apbct->settings['data__bot_detector_enabled'],
- 'data__frontend_data_log_enabled' => defined('APBCT_DO_NOT_COLLECT_FRONTEND_DATA_LOGS') ? 0 : 1,
+ 'data__frontend_data_log_enabled' => $apbct->constants->do_not_collect_frontend_data_logs->isDefinedAndTypeOK() ? 0 : 1,
'cookiePrefix' => apbct__get_cookie_prefix(),
'wprocket_detected' => apbct_is_plugin_active('wp-rocket/wp-rocket.php'),
'host_url' => Server::get('HTTP_HOST'),
diff --git a/lib/Cleantalk/ApbctWP/RemoteCalls.php b/lib/Cleantalk/ApbctWP/RemoteCalls.php
index 3a9d9943e..6139f67b3 100644
--- a/lib/Cleantalk/ApbctWP/RemoteCalls.php
+++ b/lib/Cleantalk/ApbctWP/RemoteCalls.php
@@ -328,7 +328,7 @@ public static function action__debug() // phpcs:ignore PSR1.Methods.CamelCapsMet
if ($apbct->settings['data__set_cookies'] == 3 && $apbct->data['cookies_type'] === 'alternative') {
$out['alt_sessions_auto_state_reason'] = $apbct->isAltSessionsRequired(true);
}
- $out['active_service_constants'] = $apbct->service_constants->getDefinitionsActive();
+ $out['active_service_constants'] = $apbct->constants->getDefinitionsActive();
if ( APBCT_WPMS ) {
$out['network_settings'] = $apbct->network_settings;
diff --git a/lib/Cleantalk/ApbctWP/ServiceConstants.php b/lib/Cleantalk/ApbctWP/ServiceConstants.php
index 7c8c05288..61878b9ab 100644
--- a/lib/Cleantalk/ApbctWP/ServiceConstants.php
+++ b/lib/Cleantalk/ApbctWP/ServiceConstants.php
@@ -19,6 +19,63 @@ class ServiceConstants
* @psalm-suppress PossiblyUnusedProperty
*/
public $set_ajax_route_type;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $self_owned_access_key;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $place_public_js_scripts_in_footer;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $whitelabel_faq_link;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $whitelabel_plugin_description;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ * @deprecated
+ */
+ public $whitelabel_enabled;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ * @deprecated
+ */
+ public $whitelabel_product_name;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $sfw_force_direct_update;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $disable_blocking_title;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $skip_on_approved_comments_number;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $predefined_api_url;
+ /**
+ * @var ApbctConstant
+ * @psalm-suppress PossiblyUnusedProperty
+ */
+ public $do_not_collect_frontend_data_logs;
public function __construct()
{
@@ -26,6 +83,7 @@ public function __construct()
array(
'APBCT_SERVICE__DISABLE_EMPTY_EMAIL_EXCEPTION',
),
+ 'bool',
'If set, do not skip POST data from check if no email address found'
);
$this->skip_anticrawler_on_rss_feed = new ApbctConstant(
@@ -33,6 +91,7 @@ public function __construct()
'APBCT_SERVICE__SKIP_ANTICRAWLER_ON_RSS_FEED',
'APBCT_ANTICRAWLER_EXLC_FEED',
),
+ 'bool',
'Pass anti-crawler check on RSS feed service'
);
$this->set_ajax_route_type = new ApbctConstant(
@@ -40,55 +99,97 @@ public function __construct()
'APBCT_SERVICE__SET_AJAX_ROUTE_TYPE',
'APBCT_SET_AJAX_ROUTE_TYPE',
),
+ 'string',
'Provides AJAX route type'
);
-// $accepted_constants = array(
-// // needs to be refactored
-// 'APBCT_SERVICE__SELF_OWNED_ACCESS_KEY' => array(
-// 'deprecated_name' => 'CLEANTALK_ACCESS_KEY',
-// 'description' => 'Provides user own access key.',
-// ),
-// 'APBCT_SERVICE__PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER' => array(
-// 'deprecated_name' => 'CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER',
-// 'description' => 'If defined, public scripts will be placed in footer instead of header',
-// ),
-// 'APBCT_SERVICE__WHITELABEL_FAQ_LINK' => array(
-// 'deprecated_name' => 'APBCT_WHITELABEL_FAQ_LINK',
-// 'description' => 'Provides whitelabel-mode FAQ link',
-// ),
-// 'APBCT_SERVICE__WHITELABEL_PLUGIN_DESCRIPTION' => array(
-// 'deprecated_name' => 'APBCT_WHITELABEL_PLUGIN_DESCRIPTION',
-// 'description' => 'Provides whitelabel-mode plugin description',
-// ),
-// 'APBCT_SERVICE__SFW_FORCE_DIRECT_UPDATE' => array(
-// 'deprecated_name' => 'APBCT_SFW_FORCE_DIRECT_UPDATE',
-// 'description' => 'If defined, SFW update mode is always DIRECT',
-// ),
-// 'APBCT_SERVICE__DISABLE_BLOCKING_TITLE' => array(
-// 'deprecated_name' => 'CLEANTALK_DISABLE_BLOCKING_TITLE',
-// 'description' => 'If defined, no title will be provided for blocking page.',
-// ),
-// 'APBCT_SERVICE__CHECK_COMMENTS_NUMBER' => array(
-// 'deprecated_name' => 'CLEANTALK_CHECK_COMMENTS_NUMBER',
-// 'description' => 'Provides how many comments should be approved before skip checking',
-// ),
-// 'APBCT_SERVICE__WHITELABEL' => array(
-// 'deprecated_name' => 'APBCT_WHITELABEL',
-// 'description' => 'If defined, plugin will be in whitelabel mode',
-// ),
-// 'APBCT_SERVICE__WHITELABEL_NAME' => array(
-// 'deprecated_name' => 'APBCT_WHITELABEL_NAME',
-// 'description' => 'Provides product name for whitelabel mode',
-// ),
-// 'APBCT_SERVICE__API_URL' => array(
-// 'deprecated_name' => 'CLEANTALK_API_URL',
-// 'description' => 'Provides own URL of API server',
-// ),
-// 'APBCT_SERVICE__DO_NOT_COLLECT_FRONTEND_DATA_LOGS' => array(
-// 'deprecated_name' => 'APBCT_DO_NOT_COLLECT_FRONTEND_DATA_LOGS',
-// 'description' => 'If defined, no frontend-data logs will be collected. Debugging case usage.',
+ $this->self_owned_access_key = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__SELF_OWNED_ACCESS_KEY',
+ 'CLEANTALK_ACCESS_KEY',
+ ),
+ 'string',
+ 'Provides hardcoded CleanTalk access key to use.'
+ );
+ $this->place_public_js_scripts_in_footer = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER',
+ 'CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER',
+ ),
+ 'bool',
+ 'If isset, any public scripts will be placed in a page footer.'
+ );
+ $this->whitelabel_faq_link = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__WHITELABEL_FAQ_LINK',
+ 'APBCT_WHITELABEL_FAQ_LINK',
+ ),
+ 'string',
+ 'Provides whitelabel-mode FAQ link'
+ );
+ $this->whitelabel_plugin_description = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__WHITELABEL_PLUGIN_DESCRIPTION',
+ 'APBCT_WHITELABEL_PLUGIN_DESCRIPTION',
+ ),
+ 'string',
+ 'Provides whitelabel-mode plugin description.'
+ );
+ $this->sfw_force_direct_update = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__SFW_FORCE_DIRECT_UPDATE',
+ 'APBCT_SFW_FORCE_DIRECT_UPDATE',
+ ),
+ 'bool',
+ 'If defined, SFW update mode is always DIRECT. Helpful if update queue fails due remote calls.'
+ );
+ $this->disable_blocking_title = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__DISABLE_BLOCKING_TITLE',
+ 'CLEANTALK_DISABLE_BLOCKING_TITLE',
+ ),
+ 'bool',
+ 'If defined, no title will be provided for blocking page.'
+ );
+ $this->skip_on_approved_comments_number = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__SKIP_ON_APPROVED_COMMENTS_NUMBER',
+ 'CLEANTALK_CHECK_COMMENTS_NUMBER',
+ ),
+ 'int',
+ 'Redefine how many comments should be approved before skip checking.'
+ );
+ $this->whitelabel_enabled = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__WHITELABEL_ENABLED',
+ 'APBCT_WHITELABEL',
+ ),
+ 'bool',
+ 'If defined, plugin will be in whitelabel mode.'
+ );
+ $this->whitelabel_product_name = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__WHITELABEL_PRODUCT_NAME',
+ 'APBCT_WHITELABEL_NAME',
+ ),
+ 'string',
+ 'Provides product name for whitelabel mode.'
+ );
+// todo this won't work because constant called before State is initialized
+// $this->predefined_cleantalk_server_url= new ApbctConstant(
+// array(
+// 'APBCT_SERVICE__PREDEFINED_CLEANTALK_SERVER_URL',
+// 'CLEANTALK_SERVER',
// ),
+// 'Provides own URL of API server.'
// );
+ $this->do_not_collect_frontend_data_logs = new ApbctConstant(
+ array(
+ 'APBCT_SERVICE__DO_NOT_COLLECT_FRONTEND_DATA_LOGS',
+ 'APBCT_DO_NOT_COLLECT_FRONTEND_DATA_LOGS',
+ ),
+ 'bool',
+ 'If defined, no frontend-data logs will be collected. Debugging case usage.'
+ );
}
/**
diff --git a/lib/Cleantalk/ApbctWP/State.php b/lib/Cleantalk/ApbctWP/State.php
index a160150b1..16ab495bd 100644
--- a/lib/Cleantalk/ApbctWP/State.php
+++ b/lib/Cleantalk/ApbctWP/State.php
@@ -6,7 +6,6 @@
use ArrayObject;
use Cleantalk\ApbctWP\FindSpam\LoginIPKeeper;
use Cleantalk\ApbctWP\Firewall\SFWUpdateSentinel;
-use Cleantalk\ApbctWP\ServiceConstants;
/**
* CleanTalk Anti-Spam State class
@@ -392,7 +391,7 @@ class State extends \Cleantalk\Common\State
/**
* @var ServiceConstants
*/
- public $service_constants;
+ public $constants;
private $auto_save_defaults_list = array();
@@ -536,7 +535,7 @@ protected function setDefinitions()
define('APBCT_SFW_SEND_LOGS_LIMIT', 1000);
}
- $this->service_constants = new ServiceConstants();
+ $this->constants = new ServiceConstants();
}
protected function setOptions()
diff --git a/tests/ApbctWP/TestServiceConstants.php b/tests/ApbctWP/TestServiceConstants.php
index 65467075a..011f9f28a 100644
--- a/tests/ApbctWP/TestServiceConstants.php
+++ b/tests/ApbctWP/TestServiceConstants.php
@@ -53,9 +53,9 @@ public function testGetDefinitionsActiveReturnsOnlyActiveConstantsLive()
$this->assertIsArray($activeDefinitions);
$this->assertCount(1, $activeDefinitions);
$this->assertEquals('APBCT_SERVICE__DISABLE_EMPTY_EMAIL_EXCEPTION', $activeDefinitions[0]['is_defined']);
- $this->assertEquals('APBCT_SERVICE__DISABLE_EMPTY_EMAIL_EXCEPTION', $this->serviceConstants->disable_empty_email_exception->isDefined());
- $this->assertEquals('1', $activeDefinitions[0]['value']);
- $this->assertEquals('1', $this->serviceConstants->disable_empty_email_exception->getValue());
+ $this->assertEquals(true, $this->serviceConstants->disable_empty_email_exception->isDefined());
+ $this->assertEquals(true, $activeDefinitions[0]['value']);
+ $this->assertEquals(true, $this->serviceConstants->disable_empty_email_exception->getValue());
$this->assertNotEmpty($activeDefinitions[0]['description']);
define('APBCT_ANTICRAWLER_EXLC_FEED', true);
@@ -65,8 +65,8 @@ public function testGetDefinitionsActiveReturnsOnlyActiveConstantsLive()
$this->assertCount(2, $activeDefinitions);
$this->assertEquals('APBCT_ANTICRAWLER_EXLC_FEED', $activeDefinitions[1]['is_defined']);
$this->assertEquals('APBCT_ANTICRAWLER_EXLC_FEED', $this->serviceConstants->skip_anticrawler_on_rss_feed->isDefined());
- $this->assertEquals('1', $activeDefinitions[1]['value']);
- $this->assertEquals('1', $this->serviceConstants->skip_anticrawler_on_rss_feed->getValue());
+ $this->assertEquals(true, $activeDefinitions[1]['value']);
+ $this->assertEquals(true, $this->serviceConstants->skip_anticrawler_on_rss_feed->getValue());
$this->assertNotEmpty($activeDefinitions[1]['description']);
define('APBCT_SET_AJAX_ROUTE_TYPE', 'admin_ajax');
@@ -75,9 +75,31 @@ public function testGetDefinitionsActiveReturnsOnlyActiveConstantsLive()
$this->assertIsArray($activeDefinitions);
$this->assertCount(3, $activeDefinitions);
$this->assertEquals('APBCT_SET_AJAX_ROUTE_TYPE', $activeDefinitions[2]['is_defined']);
- $this->assertEquals('APBCT_SET_AJAX_ROUTE_TYPE', $this->serviceConstants->set_ajax_route_type->isDefined());
+ $this->assertEquals(true, $this->serviceConstants->set_ajax_route_type->isDefinedAndTypeOK());
$this->assertEquals('admin_ajax', $activeDefinitions[2]['value']);
$this->assertEquals('admin_ajax', $this->serviceConstants->set_ajax_route_type->getValue());
$this->assertNotEmpty($activeDefinitions[2]['description']);
+
+ define('CLEANTALK_ACCESS_KEY', 'asdasdasd');
+ $this->serviceConstants = new ServiceConstants();
+ $activeDefinitions = $this->serviceConstants->getDefinitionsActive();
+ $this->assertIsArray($activeDefinitions);
+ $this->assertCount(4, $activeDefinitions);
+ $this->assertEquals('CLEANTALK_ACCESS_KEY', $activeDefinitions[3]['is_defined']);
+ $this->assertEquals(true, $this->serviceConstants->self_owned_access_key->isDefinedAndTypeOK());
+ $this->assertEquals('asdasdasd', $activeDefinitions[3]['value']);
+ $this->assertEquals('asdasdasd', $this->serviceConstants->self_owned_access_key->getValue());
+ $this->assertNotEmpty($activeDefinitions[3]['description']);
+
+ define('CLEANTALK_CHECK_COMMENTS_NUMBER', false);
+ $this->serviceConstants = new ServiceConstants();
+ $activeDefinitions = $this->serviceConstants->getDefinitionsActive();
+ $this->assertIsArray($activeDefinitions);
+ $this->assertCount(5, $activeDefinitions);
+ $this->assertEquals('CLEANTALK_CHECK_COMMENTS_NUMBER', $activeDefinitions[4]['is_defined']);
+ $this->assertEquals(false, $this->serviceConstants->skip_on_approved_comments_number->isDefinedAndTypeOK());
+ $this->assertEquals(false, $activeDefinitions[4]['value']);
+ $this->assertEquals(false, $this->serviceConstants->skip_on_approved_comments_number->getValue());
+ $this->assertNotEmpty($activeDefinitions[4]['description']);
}
}