Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action the comments from user in support forum ( free features ) #14

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
5 changes: 3 additions & 2 deletions admin/comment_form_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ public function register_settings() {
*/
public function sanitize_settings ( $data ){

$data['text_before'] = wp_kses_post( $data['text_before'] );
$data['text_after'] = wp_kses_post( $data['text_after'] );
$data['text_before'] = wp_kses_post( $data['text_before'] );
$data['text_after'] = wp_kses_post( $data['text_after'] );
$data['cookies_text'] = wp_kses_post( $data['cookies_text'] );

return $data;
}
Expand Down
36 changes: 36 additions & 0 deletions admin/views/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public function sc_settings_fields() {
'comment-form-fields',
'comment_form_fields_section'
);

add_settings_field(
'commentform_settings_remove_cookies',
__('Remove consent field', 'commentform'),
array($this, 'render_remove_cookies_field_callback'),
'comment-form-fields',
'comment_form_fields_section'
);
}

/**
Expand Down Expand Up @@ -104,6 +112,34 @@ public function render_remove_email_field_callback() {
?>
<p><?php _e('Removes the "email" field with css. Use this only if the method above doesn’t work. This uses "display:none" on the most common css selectors for the email field. The value might still get submitted by bots and tech-savvy users.', 'commentform') ?></p>
<?php }

/**
* consent field settings
*
* @since 1.2.0
*/
public function render_remove_cookies_field_callback() { ?>
<?php
$this->generate_checkbox(
'commentform_settings[remove_cookies]',
'1',
checked(1, $this->options('remove_cookies'), false),
false,
'Remove consent field'
);
?>
<p><?php _e('Removes the "consent" field from the frontend programmatically.', 'commentform') ?></p>
<?php
$this->generate_checkbox(
'commentform_settings[remove_cookies_css]',
'1',
checked(1, $this->options('remove_cookies_css'), false),
false,
'Remove consent field with css'
);
?>
<p><?php _e('Removes the "consent" field with css. Use this only if the method above doesn’t work. This uses "display:none" on the most common css selectors for the consent field. The value might still get submitted by bots and tech-savvy users.', 'commentform') ?></p>
<?php }
}

new Comment_Form_Admin_Fields();
30 changes: 30 additions & 0 deletions admin/views/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public function sc_settings_text() {
'comment-form-text',
'comment_form_texts_section'
);

add_settings_field(
'commentform_settings_consent_text',
__('Texts for consent', 'commentform'),
array($this, 'render_comment_consent_text_callback'),
'comment-form-text',
'comment_form_texts_section'
);
}

/**
Expand Down Expand Up @@ -96,6 +104,28 @@ public function render_comment_notes_after_callback() { ?>
<textarea rows="5" name="commentform_settings[text_after]" class="mt-4"><?php $this->options('text_after') ?></textarea>
<p><?php _e('This text is inserted after the form when commenting if commiting is allowed to the user.', 'commentform') ?></p>
<?php }

/**
* Change consent text
*
* @since 1.0.0
*/
public function render_comment_consent_text_callback() { ?>
<?php
$this->generate_checkbox(
'commentform_settings[cookies_consent]',
'1',
checked(1, $this->options('cookies_consent'), false),
false,
'Remove consent default text'
);
?>
<p><?php _e('This is currently:', 'commentform') ?></p>
<p><?php _e( 'Save my name, email, and website in this browser for the next time I comment.' ) ?></p>

<textarea rows="5" name="commentform_settings[cookies_text]"><?php $this->options('cookies_text') ?></textarea>
<p><?php _e('If the consent field is enabled, this text will appear beside it.', 'commentform') ?></p>
<?php }
}

new Comment_Form_Admin_Text();
38 changes: 38 additions & 0 deletions frontend/comment_form_frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function __construct() {
add_filter('comment_form_defaults', array($this, 'comment_form_defaults_filter'));
// comment form do before printing the form
add_action('comment_form_top', array($this, 'comment_form_top_action'));
// comment form do at the bottom of the comment form, inside the closing form tag
add_action('comment_form_after_fields', array($this, 'comment_form_cookies_action'));
// comment form do after fields where rendered
add_action('comment_form_after_fields', array($this, 'comment_form_after_fields_action'));
// manipulate the comment form markup on its output
Expand Down Expand Up @@ -49,6 +51,11 @@ public function comment_form_default_fields_filter($fields) {
unset($fields['url']);
}

// remove the consent field
if ($options['remove_cookies'] && isset($fields['cookies'])) {
unset($fields['cookies']);
}

return $fields;
}

Expand All @@ -71,6 +78,11 @@ public function comment_form_defaults_filter($defaults) {
if ($options['hide_notes_after']) {
$defaults['comment_notes_after'] = '';
}

// hide the default text after the form
if ($options['cookies_consent']) {
$defaults['cookies'] = '';
}
return $defaults;
}

Expand All @@ -94,6 +106,27 @@ public function comment_form_top_action() {
}
}

/**
* action to set comment cookies
*
* @since 1.0.0
*/
public function comment_form_cookies_action() {
$options = $this->options();

// Print custom consent text.
if (isset($options['cookies_text']) && $options['cookies_text'] !== '') {
echo "<script>
document.addEventListener('DOMContentLoaded', function() {
var consentLabel = document.querySelector('.comment-form-cookies-consent label');
if (consentLabel) {
consentLabel.textContent = " . json_encode($options['cookies_text']) . ";
}
});
</script>";
}
}

/**
* action to trigger after the fields (username, email, url) where displayed
*
Expand Down Expand Up @@ -165,6 +198,11 @@ public function footer_output() {
if ($options['remove_email_css']) {
echo "<style>.comment-form-email, #email {display:none;}</style>";
}
// css code to hide the consent field
// .comment-form-cookies-consent as in the default comment form in /wp-includes/comment-template.php
if ($options['remove_cookies_css']) {
echo "<style>.comment-form > p.comment-form-cookies-consent {display:none;}</style>";
}
// apply styles for two columns comment form layout
if ($options['two_columns'] && !is_user_logged_in()) {
echo '<style>
Expand Down
4 changes: 4 additions & 0 deletions inc/comment_form_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ public function get_default_options(){
$defaults = array(
'hide_notes_after' => 0,
'hide_notes_before' => 0,
'cookies_consent' => 0,
'remove_email' => false,
'remove_email_css' => false,
'hide_url' => 0,
'hide_url_css' => false,
'remove_cookies' => false,
'remove_cookies_css' => false,
'text_after' => '',
'text_before' => '',
'cookies_text' => '',
'two_columns' => false
);

Expand Down