diff --git a/newspack-theme/comments.php b/newspack-theme/comments.php
index 2c0ef0ddb..eae01915f 100755
--- a/newspack-theme/comments.php
+++ b/newspack-theme/comments.php
@@ -20,7 +20,7 @@
}
$discussion = newspack_get_discussion_data();
-$collapse_comments = get_theme_mod( 'collapse_comments', false );
+$collapse_comments = get_theme_mod( 'collapse_comments', '' );
$on_first_page = true;
$comments_collapsed = false;
$url_end = '';
@@ -34,9 +34,14 @@
$on_first_page = false;
}
-// Collapse comments if that's set, if there's more than one, and if we're on the first page:
-if ( $collapse_comments && 1 < (int) $discussion->responses && $on_first_page ) {
- $comments_collapsed = true;
+// Collapse comments based on the setting and if we're on the first page:
+if ( $collapse_comments && $on_first_page ) {
+ if ( 'always' === $collapse_comments ) {
+ $comments_collapsed = true;
+ } elseif ( ( true === $collapse_comments || 'more_than_one' === $collapse_comments ) && 1 < (int) $discussion->responses ) {
+ // Backward compat: boolean true treated same as 'more_than_one'.
+ $comments_collapsed = true;
+ }
}
?>
@@ -154,8 +159,20 @@
else :
// Show comment form.
- newspack_comment_form( true );
+ if ( $comments_collapsed ) :
+ ?>
+
+
+
+
+
- endif; // End have_comments check.
- ?>
diff --git a/newspack-theme/inc/customizer.php b/newspack-theme/inc/customizer.php
index 47a8de306..50f24ed77 100755
--- a/newspack-theme/inc/customizer.php
+++ b/newspack-theme/inc/customizer.php
@@ -1205,17 +1205,22 @@ function newspack_customize_register( $wp_customize ) {
$wp_customize->add_setting(
'collapse_comments',
array(
- 'default' => false,
- 'sanitize_callback' => 'newspack_sanitize_checkbox',
+ 'default' => '',
+ 'sanitize_callback' => 'newspack_sanitize_select',
)
);
$wp_customize->add_control(
'collapse_comments',
array(
- 'type' => 'checkbox',
+ 'type' => 'select',
'label' => esc_html__( 'Collapse Comments', 'newspack-theme' ),
- 'description' => esc_html__( 'When using WordPress\'s default comments, checking this option will collapse the comments section when there is more than one comment, and display a button to expand.', 'newspack-theme' ),
+ 'description' => esc_html__( 'When using WordPress\'s default comments, choose when to collapse the comments section and display a button to expand.', 'newspack-theme' ),
'section' => 'comments_options',
+ 'choices' => array(
+ '' => esc_html__( 'Don\'t collapse', 'newspack-theme' ),
+ 'more_than_one' => esc_html__( 'Collapse when more than one comment', 'newspack-theme' ),
+ 'always' => esc_html__( 'Always collapse', 'newspack-theme' ),
+ ),
)
);
@@ -1628,6 +1633,20 @@ function newspack_sanitize_checkbox( $input ) {
}
}
+/**
+ * Sanitize select input.
+ *
+ * @param string $input Value to sanitize.
+ * @param object $setting Setting instance.
+ *
+ * @return string Sanitized value.
+ */
+function newspack_sanitize_select( $input, $setting ) {
+ $input = sanitize_key( $input );
+ $choices = $setting->manager->get_control( $setting->id )->choices;
+ return ( array_key_exists( $input, $choices ) ) ? $input : $setting->default;
+}
+
/**
* Sanitize author avatar image size.
*