Permalink
Browse files

Rewrite comments.php to contain not more than just the comments_form()

call.
  • Loading branch information...
obenland committed Jun 16, 2012
1 parent cd81806 commit 5d1781c8ab417f8d9f386d2ef4ee69723de8175e
Showing with 135 additions and 99 deletions.
  1. +2 −43 comments.php
  2. +131 −54 functions.php
  3. +1 −1 page.php
  4. +1 −1 single.php
View
@@ -5,56 +5,15 @@
*
* The area of the page that contains both current comments
* and the comment form. The actual display of comments is
- * handled by a callback to the_bootstrap_comment() which is
- * located in the functions.php file.
+ * handled by callbacks which are located in the functions.php file.
*
* @author Konstantin Obenland
* @package The Bootstrap
* @since 1.0.0 - 05.02.2012
*/
-if ( post_password_required() ) : ?>
- <div id="comments">
- <p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'the-bootstrap' ); ?></p>
- </div><!-- #comments -->
- <?php
- return;
-endif;
-
-
-if ( have_comments() ) : ?>
- <div id="comments">
- <h2 id="comments-title">
- <?php printf( _n( 'One thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'the-bootstrap' ),
- number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' ); ?>
- </h2>
-
- <?php the_bootstrap_comment_nav(); ?>
-
- <ol class="commentlist unstyled">
- <?php wp_list_comments( array( 'callback' => 'the_bootstrap_comment' ) ); ?>
- </ol><!-- .commentlist .unstyled -->
-
- <?php the_bootstrap_comment_nav(); ?>
-
- </div><!-- #comments -->
-<?php endif;
-
-if ( ! comments_open() AND ! is_page() AND post_type_supports( get_post_type(), 'comments' ) ) : ?>
- <p class="nocomments"><?php _e( 'Comments are closed.', 'the-bootstrap' ); ?></p>
-<?php endif;
-
-comment_form( array(
- 'comment_field' => '<div class="comment-form-comment control-group"><label class="control-label" for="comment">' . _x( 'Comment', 'noun', 'the-bootstrap' ) . '</label><div class="controls"><textarea class="span7" id="comment" name="comment" rows="8" aria-required="true"></textarea></div></div>',
- 'comment_notes_before' => '',
- 'comment_notes_after' => '<div class="form-allowed-tags control-group"><label class="control-label">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s', 'the-bootstrap' ), '</label><div class="controls"><pre>' . allowed_tags() . '</pre></div>' ) . '</div>
- <div class="form-actions">',
- 'title_reply' => '<legend>' . __( 'Leave a reply', 'the-bootstrap' ) . '</legend>',
- 'title_reply_to' => '<legend>' . __( 'Leave a reply to %s', 'the-bootstrap' ). '</legend>',
- 'must_log_in' => '<div class="must-log-in control-group controls">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'the-bootstrap' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( get_the_ID() ) ) ) ) . '</div>',
- 'logged_in_as' => '<div class="logged-in-as control-group controls">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'the-bootstrap' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( get_the_ID() ) ) ) ) . '</div>',
-) );
+comment_form();
/* End of file comments.php */
View
@@ -467,6 +467,88 @@ function the_bootstrap_enhanced_image_navigation( $url, $id ) {
add_filter( 'attachment_link', 'the_bootstrap_enhanced_image_navigation', 10, 2 );
+/**
+ * Displays comment list, when there are any
+ *
+ * @author Konstantin Obenland
+ * @since 1.7.0 - 16.06.2012
+ *
+ * @return void
+ */
+function the_bootstrap_comments_list() {
+ if ( post_password_required() ) : ?>
+ <div id="comments">
+ <p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'the-bootstrap' ); ?></p>
+ </div><!-- #comments -->
+ <?php
+ return;
+ endif;
+
+
+ if ( have_comments() ) : ?>
+ <div id="comments">
+ <h2 id="comments-title">
+ <?php printf( _n( 'One thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'the-bootstrap' ),
+ number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' ); ?>
+ </h2>
+
+ <?php the_bootstrap_comment_nav(); ?>
+
+ <ol class="commentlist unstyled">
+ <?php wp_list_comments( array( 'callback' => 'the_bootstrap_comment' ) ); ?>
+ </ol><!-- .commentlist .unstyled -->
+
+ <?php the_bootstrap_comment_nav(); ?>
+
+ </div><!-- #comments -->
+ <?php endif;
+}
+add_action( 'comment_form_before', 'the_bootstrap_comments_list', 0 );
+add_action( 'comment_form_comments_closed', 'the_bootstrap_comments_list', 1 );
+
+
+/**
+ * Echoes comments-are-closed message when post type supports comments and we're
+ * not on a page
+ *
+ * @author Konstantin Obenland
+ * @since 1.7.0 - 16.06.2012
+ *
+ * @return void
+ */
+function the_bootstrap_comments_closed() {
+ if ( ! is_page() AND post_type_supports( get_post_type(), 'comments' ) ) : ?>
+ <p class="nocomments"><?php _e( 'Comments are closed.', 'the-bootstrap' ); ?></p>
+ <?php endif;
+}
+add_action( 'comment_form_comments_closed', 'the_bootstrap_comments_closed' );
+
+
+/**
+ * Filters comments_form() default arguments
+ *
+ * @author Konstantin Obenland
+ * @since 1.7.0 - 16.06.2012
+ *
+ * @param array $defaults
+ *
+ * @return array
+ */
+function the_bootstrap_comment_form_defaults( $defaults ) {
+ return wp_parse_args( array(
+ 'comment_field' => '<div class="comment-form-comment control-group"><label class="control-label" for="comment">' . _x( 'Comment', 'noun', 'the-bootstrap' ) . '</label><div class="controls"><textarea class="span7" id="comment" name="comment" rows="8" aria-required="true"></textarea></div></div>',
+ 'comment_notes_before' => '',
+ 'comment_notes_after' => '<div class="form-allowed-tags control-group"><label class="control-label">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s', 'the-bootstrap' ), '</label><div class="controls"><pre>' . allowed_tags() . '</pre></div>' ) . '</div>
+ <div class="form-actions">',
+ 'title_reply' => '<legend>' . __( 'Leave a reply', 'the-bootstrap' ) . '</legend>',
+ 'title_reply_to' => '<legend>' . __( 'Leave a reply to %s', 'the-bootstrap' ). '</legend>',
+ 'must_log_in' => '<div class="must-log-in control-group controls">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'the-bootstrap' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( get_the_ID() ) ) ) ) . '</div>',
+ 'logged_in_as' => '<div class="logged-in-as control-group controls">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'the-bootstrap' ), admin_url( 'profile.php' ), wp_get_current_user()->display_name, wp_logout_url( apply_filters( 'the_permalink', get_permalink( get_the_ID() ) ) ) ) . '</div>',
+ ), $defaults );
+}
+add_filter( 'comment_form_defaults', 'the_bootstrap_comment_form_defaults' );
+
+
if ( ! function_exists( 'the_bootstrap_comment' ) ) :
/**
* Template for comments and pingbacks.
@@ -487,62 +569,57 @@ function the_bootstrap_enhanced_image_navigation( $url, $id ) {
*/
function the_bootstrap_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
- switch ( $comment->comment_type ) :
- case 'pingback' :
- case 'trackback' :
- ?>
- <li class="post pingback">
- <p class="row">
- <strong class="ping-label span1"><?php _e( 'Pingback:', 'the-bootstrap' ); ?></strong>
- <span class="span7"><?php comment_author_link(); edit_comment_link( __( 'Edit', 'the-bootstrap' ), '<span class="sep">&nbsp;</span><span class="edit-link label">', '</span>' ); ?></span>
- </p>
- <?php
- break;
- default :
- $offset = $depth - 1;
- $span = 7 - $offset;
- ?>
- <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
- <article id="comment-<?php comment_ID(); ?>" class="comment row">
- <div class="comment-author-avatar span1<?php if ($offset) echo " offset{$offset}"; ?>">
- <?php echo get_avatar( $comment, 70 ); ?>
- </div>
- <footer class="comment-meta span<?php echo $span; ?>">
- <div class="comment-author vcard">
- <?php
- /* translators: 1: comment author, 2: date and time */
- printf( __( '%1$s <span class="says">said</span> on %2$s:', 'the-bootstrap' ),
- sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
- sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
- esc_url( get_comment_link( $comment->comment_ID ) ),
- get_comment_time( 'c' ),
- /* translators: 1: date, 2: time */
- sprintf( __( '%1$s at %2$s', 'the-bootstrap' ), get_comment_date(), get_comment_time() )
- )
- );
- edit_comment_link( __( 'Edit', 'the-bootstrap' ), '<span class="sep">&nbsp;</span><span class="edit-link label">', '</span>' ); ?>
- </div><!-- .comment-author .vcard -->
-
- <?php if ( ! $comment->comment_approved ) : ?>
- <div class="comment-awaiting-moderation alert alert-info"><em><?php _e( 'Your comment is awaiting moderation.', 'the-bootstrap' ); ?></em></div>
- <?php endif; ?>
-
- </footer><!-- .comment-meta -->
+ if ( 'pingback' == $comment->comment_type OR 'trackback' == $comment->comment_type ) : ?>
+
+ <li id="li-comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
+ <p class="row">
+ <strong class="ping-label span1"><?php _e( 'Pingback:', 'the-bootstrap' ); ?></strong>
+ <span class="span7"><?php comment_author_link(); edit_comment_link( __( 'Edit', 'the-bootstrap' ), '<span class="sep">&nbsp;</span><span class="edit-link label">', '</span>' ); ?></span>
+ </p>
+
+ <?php else:
+ $offset = $depth - 1;
+ $span = 7 - $offset; ?>
- <div class="comment-content span<?php echo $span; ?>">
+ <li id="li-comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
+ <article id="comment-<?php comment_ID(); ?>" class="comment row">
+ <div class="comment-author-avatar span1<?php if ($offset) echo " offset{$offset}"; ?>">
+ <?php echo get_avatar( $comment, 70 ); ?>
+ </div>
+ <footer class="comment-meta span<?php echo $span; ?>">
+ <p class="comment-author vcard">
<?php
- comment_text();
- comment_reply_link( array_merge( $args, array(
- 'reply_text' => __( 'Reply <span>&darr;</span>', 'the-bootstrap' ),
- 'depth' => $depth,
- 'max_depth' => $args['max_depth']
- ) ) ); ?>
- </div><!-- .comment-content -->
-
- </article><!-- #comment-<?php comment_ID(); ?> .comment -->
- <?php
- break;
- endswitch;
+ /* translators: 1: comment author, 2: date and time */
+ printf( __( '%1$s <span class="says">said</span> on %2$s:', 'the-bootstrap' ),
+ sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
+ sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
+ esc_url( get_comment_link( $comment->comment_ID ) ),
+ get_comment_time( 'c' ),
+ /* translators: 1: date, 2: time */
+ sprintf( __( '%1$s at %2$s', 'the-bootstrap' ), get_comment_date(), get_comment_time() )
+ )
+ );
+ edit_comment_link( __( 'Edit', 'the-bootstrap' ), '<span class="sep">&nbsp;</span><span class="edit-link label">', '</span>' ); ?>
+ </p><!-- .comment-author .vcard -->
+
+ <?php if ( ! $comment->comment_approved ) : ?>
+ <div class="comment-awaiting-moderation alert alert-info"><em><?php _e( 'Your comment is awaiting moderation.', 'the-bootstrap' ); ?></em></div>
+ <?php endif; ?>
+
+ </footer><!-- .comment-meta -->
+
+ <div class="comment-content span<?php echo $span; ?>">
+ <?php
+ comment_text();
+ comment_reply_link( array_merge( $args, array(
+ 'reply_text' => __( 'Reply <span>&darr;</span>', 'the-bootstrap' ),
+ 'depth' => $depth,
+ 'max_depth' => $args['max_depth']
+ ) ) ); ?>
+ </div><!-- .comment-content -->
+ </article><!-- #comment-<?php comment_ID(); ?> .comment -->
+
+ <?php endif; // comment_type
}
endif; // ends check for the_bootstrap_comment()
View
@@ -21,7 +21,7 @@
<?php
the_post();
get_template_part( '/partials/content', 'page' );
- comments_template( '', true ); ?>
+ comments_template(); ?>
</div><!-- #content -->
</div><!-- #primary -->
View
@@ -16,7 +16,7 @@
<?php while ( have_posts() ) {
the_post();
get_template_part( '/partials/content', 'single' );
- comments_template( '', true );
+ comments_template();
} ?>
<nav id="nav-single" class="pager">

0 comments on commit 5d1781c

Please sign in to comment.