119 lines
3.7 KiB
PHP
119 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* The template for displaying comments
|
|
*
|
|
* This is the template that displays the area of the page that contains both the current comments
|
|
* and the comment form.
|
|
*
|
|
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
|
|
*
|
|
* @package Sophia After Dark
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
/*
|
|
* If the current post is protected by a password and
|
|
* the visitor has not yet entered the password we will
|
|
* return early without loading the comments.
|
|
*/
|
|
if ( post_password_required() ) {
|
|
return;
|
|
}
|
|
|
|
// Remove URL field from comment form
|
|
function sophia_after_dark_remove_url_comments($fields) {
|
|
unset($fields['url']);
|
|
return $fields;
|
|
}
|
|
add_filter('comment_form_default_fields', 'sophia_after_dark_remove_url_comments');
|
|
|
|
// Modify cookie consent field
|
|
function sophia_after_dark_comment_form_change_cookies($fields) {
|
|
$commenter = wp_get_current_commenter();
|
|
$consent = ! empty( $commenter['comment_author_email'] );
|
|
|
|
$fields['cookies'] = sprintf(
|
|
'<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" %s /> <label for="wp-comment-cookies-consent">%s</label></p>',
|
|
checked( $consent, true, false ),
|
|
esc_html__( 'Save my Name & Email for the next time I comment.', 'sophia-after-dark' )
|
|
);
|
|
|
|
return $fields;
|
|
}
|
|
add_filter('comment_form_default_fields', 'sophia_after_dark_comment_form_change_cookies');
|
|
|
|
// Add comment notes above form
|
|
function sophia_after_dark_modify_text_before_comment_form($arg) {
|
|
$arg['comment_notes_before'] = wp_kses_post(
|
|
'<p class="comment-notes">' .
|
|
esc_html__('All comments are manually reviewed and moderated.', 'sophia-after-dark') .
|
|
'<br><span class="required-field-message">' .
|
|
esc_html__('Required fields are marked ', 'sophia-after-dark') .
|
|
'<span class="required">*</span></span></p>'
|
|
);
|
|
return $arg;
|
|
}
|
|
add_filter('comment_form_defaults', 'sophia_after_dark_modify_text_before_comment_form');
|
|
|
|
// Add privacy policy consent note below form
|
|
function sophia_after_dark_modify_text_comment_form($post_id) {
|
|
$link = '<a href="/privacy-policy">' . esc_html__( 'Privacy Policy', 'sophia-after-dark' ) . '</a>';
|
|
printf(
|
|
'<span class="submit-comment-note">%s</span>',
|
|
sprintf(
|
|
wp_kses(
|
|
__( 'By commenting, you consent to our %s.', 'sophia-after-dark' ),
|
|
array( 'a' => array( 'href' => array() ) )
|
|
),
|
|
$link
|
|
)
|
|
);
|
|
}
|
|
add_action('comment_form', 'sophia_after_dark_modify_text_comment_form');
|
|
|
|
?>
|
|
|
|
<div id="comments" class="comments-area">
|
|
<?php if ( have_comments() ) : ?>
|
|
<h2 class="comments-title" aria-label="<?php esc_attr_e( 'Comments Section', 'sophia-after-dark' ); ?>">
|
|
<?php
|
|
$sophia_after_dark_comment_count = get_comments_number();
|
|
if ( '1' === $sophia_after_dark_comment_count ) {
|
|
printf(
|
|
/* translators: %s: Post title */
|
|
esc_html__( 'One Comment on “%s”', 'sophia-after-dark' ),
|
|
'<span>' . esc_html( get_the_title() ) . '</span>'
|
|
);
|
|
} else {
|
|
printf(
|
|
/* translators: 1: Comment count, 2: Post title */
|
|
esc_html( _nx( '%1$s Comment on “%2$s”', '%1$s Comments on “%2$s”', $sophia_after_dark_comment_count, 'comments title', 'sophia-after-dark' ) ),
|
|
number_format_i18n( $sophia_after_dark_comment_count ),
|
|
'<span>' . esc_html( get_the_title() ) . '</span>'
|
|
);
|
|
}
|
|
?>
|
|
</h2>
|
|
|
|
<?php the_comments_navigation(); ?>
|
|
|
|
<ol class="comment-list">
|
|
<?php
|
|
wp_list_comments( array(
|
|
'style' => 'ol',
|
|
'short_ping' => true,
|
|
'reply_text' => __( 'Reply', 'sophia-after-dark' ),
|
|
) );
|
|
?>
|
|
</ol>
|
|
|
|
<?php the_comments_navigation(); ?>
|
|
|
|
<?php if ( ! comments_open() ) : ?>
|
|
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'sophia-after-dark' ); ?></p>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
|
|
<?php comment_form(); ?>
|
|
</div>
|