Skip to content

Commit 0cd650f

Browse files
committed
Fix. TRP. Cleantalk allowed moderation discussion state.
1 parent da27a89 commit 0cd650f

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

inc/cleantalk-settings.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function apbct_settings_add_page()
6363
global $apbct;
6464

6565
$filtered = ($value === '1' || $value === 1) ? '1' : '0';
66+
//sync discussion and plugin settings
6667
if ($old_value !== $filtered) {
6768
$apbct->settings['cleantalk_allowed_moderation'] = $filtered;
6869
$apbct->saveSettings();
@@ -2101,7 +2102,7 @@ function apbct_discussion_settings__field__moderation()
21012102
name="cleantalk_allowed_moderation"
21022103
id="cleantalk_allowed_moderation"
21032104
value="1" ' .
2104-
checked('1', $apbct->settings['cleantalk_allowed_moderation'], false) .
2105+
checked('1', TT::toString($apbct->settings['cleantalk_allowed_moderation'], '0'), false) .
21052106
'/> ';
21062107
$output .= esc_html__('Skip manual approving for the very first comment if a comment has been allowed by CleanTalk Anti-Spam protection.', 'cleantalk-spam-protect');
21072108
$output .= '</label>';
@@ -2575,6 +2576,11 @@ function apbct_settings__validate($incoming_settings)
25752576
$incoming_settings['data__email_decoder_obfuscation_custom_text'] = ContactsEncoder::getDefaultReplacingText();
25762577
}
25772578

2579+
//sync discussion and plugin settings
2580+
if (isset($incoming_settings['cleantalk_allowed_moderation'])) {
2581+
update_option('cleantalk_allowed_moderation', TT::toString($incoming_settings['cleantalk_allowed_moderation'], '0'));
2582+
}
2583+
25782584
/**
25792585
* Triggered before returning the settings
25802586
*/

lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function allow()
218218
{
219219
$wp_comment_moderation_enabled = get_option('comment_moderation') === '1';
220220
$wp_auto_approve_for_user_who_has_approved_comment = get_option('comment_previously_approved') === '1';
221-
$clentalk_option_skip_moderation_for_first_comment = get_option('cleantalk_allowed_moderation', 1) == 1;
221+
$cleantalk_option_skip_moderation_for_first_comment = self::firstCommentAutoModEnabled();
222222
$is_allowed_because_of_inactive_license = false;
223223

224224
$args = array(
@@ -251,7 +251,7 @@ public function allow()
251251
// if anu of options is disabled - standard WP recheck and exit
252252
if (
253253
!$wp_auto_approve_for_user_who_has_approved_comment ||
254-
!$clentalk_option_skip_moderation_for_first_comment
254+
!$cleantalk_option_skip_moderation_for_first_comment
255255
) {
256256
if (
257257
$this->rerunWPcheckCommentFunction()
@@ -572,4 +572,13 @@ private function setCommentPreStatusAndModifyEmail($status)
572572
2
573573
); // Add two blacklist links: by email and IP
574574
}
575+
576+
/**
577+
* @return bool
578+
*/
579+
public static function firstCommentAutoModEnabled()
580+
{
581+
global $apbct;
582+
return !empty($apbct->settings['cleantalk_allowed_moderation']) && $apbct->settings['cleantalk_allowed_moderation'] == '1';
583+
}
575584
}

lib/Cleantalk/ApbctWP/CleantalkRealPerson.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Cleantalk\ApbctWP;
44

5+
use Cleantalk\Antispam\Integrations\CleantalkPreprocessComment;
6+
57
class CleantalkRealPerson
68
{
79
public static $meta_hash_name__old = 'ct_real_user_badge_hash';
@@ -52,23 +54,14 @@ public function publicCommentAddTrpClass($classes, $_css_class, $comment_id, $co
5254
return $classes;
5355
}
5456

55-
/**
56-
* @return bool
57-
*/
58-
private static function isAutomodEnabled()
59-
{
60-
global $apbct;
61-
return !empty($apbct->settings['cleantalk_allowed_moderation']) && $apbct->settings['cleantalk_allowed_moderation'] == '1';
62-
}
63-
6457
/**
6558
* Check if TRP hash is saved for comment ID. Autodetect if cleantalk_allowed_moderation is enabled.
6659
* @param int|string $comment_id
6760
* @return bool
6861
*/
6962
public static function isTRPHashExist($comment_id)
7063
{
71-
if (self::isAutomodEnabled()) {
64+
if (CleantalkPreprocessComment::firstCommentAutoModEnabled()) {
7265
// Only for auto-moderated
7366
$trp_hash = get_comment_meta((int)$comment_id, self::$meta_hash_name__automod, true);
7467
} else {
@@ -89,7 +82,7 @@ public static function setTRPHash($comment_id)
8982
{
9083
$hash = ct_hash();
9184
if ( ! empty($hash) ) {
92-
if (self::isAutomodEnabled()) {
85+
if (CleantalkPreprocessComment::firstCommentAutoModEnabled()) {
9386
update_comment_meta((int)$comment_id, self::$meta_hash_name__automod, $hash);
9487
} else {
9588
update_comment_meta((int)$comment_id, self::$meta_hash_name__old, $hash);

0 commit comments

Comments
 (0)