Skip to content

Commit bf87f83

Browse files
committed
Fix: Hide comment cookie consent checkbox if disabled in backend
1 parent d8c90de commit bf87f83

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

inc/comments.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,24 @@ function custom_reply_title($defaults) {
113113

114114
/**
115115
* Comment Cookie Checkbox
116+
* See https://github.com/bootscore/bootscore/issues/921
116117
*/
117-
function wp44138_change_comment_form_cookies_consent($fields) {
118-
$consent = empty($commenter['comment_author_email']) ? '' : ' checked="checked"';
119-
$fields['cookies'] = '<p class="comment-form-cookies-consent custom-control form-check mb-3">' .
120-
'<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" class="form-check-input"' . $consent . ' />' .
121-
'<label for="wp-comment-cookies-consent" class="form-check-label">' . __('Save my name, email, and website in this browser for the next time I comment.', 'bootscore') . '</label>' .
122-
'</p>';
118+
function bootscore_change_comment_form_cookies_consent($fields) {
119+
// Check if the "Show comments cookies opt-in checkbox" setting is enabled
120+
if (get_option('show_comments_cookies_opt_in')) {
121+
$consent = empty($commenter['comment_author_email']) ? '' : ' checked="checked"';
122+
$fields['cookies'] = '<p class="comment-form-cookies-consent form-check mb-3">' .
123+
'<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" class="form-check-input"' . $consent . ' />' .
124+
'<label for="wp-comment-cookies-consent" class="form-check-label">' . __('Save my name, email, and website in this browser for the next time I comment.', 'bootscore') . '</label>' .
125+
'</p>';
126+
} else {
127+
// Remove the 'cookies' field if the setting is disabled
128+
unset($fields['cookies']);
129+
}
123130

124131
return $fields;
125132
}
126-
127-
add_filter('comment_form_default_fields', 'wp44138_change_comment_form_cookies_consent');
133+
add_filter('comment_form_default_fields', 'bootscore_change_comment_form_cookies_consent');
128134

129135

130136
/**

0 commit comments

Comments
 (0)