Created
November 10, 2011 19:28
-
-
Save milohuang/1355876 to your computer and use it in GitHub Desktop.
WordPress Comment Template: Add Role Badge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php function reverie_comments($comment, $args, $depth) { | |
$GLOBALS['comment'] = $comment; ?> | |
<li <?php comment_class(); ?>> | |
<article id="comment-<?php comment_ID(); ?>"> | |
<header class="comment-author vcard"> | |
<?php echo get_avatar($comment,$size='40'); ?> | |
<?php printf(__('<cite class="fn">%s</cite>', 'reverie'), get_comment_author_link()) ?> | |
<?php | |
$commentator_id = get_comment(get_comment_ID())->user_id; | |
$commentator_info = get_userdata($commentator_id); | |
$capabilities = $user_info->wp_capabilities; | |
if (array_key_exists('editor', $capabilities)) { | |
echo 'Editor' ; | |
} | |
?> | |
<time datetime="<?php echo comment_date('c') ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s', 'reverie'), get_comment_date(), get_comment_time()) ?></a></time> | |
<?php edit_comment_link(__('(Edit)', 'reverie'), '', '') ?> | |
</header> | |
<?php if ($comment->comment_approved == '0') : ?> | |
<div class="notice"> | |
<p class="bottom"><?php _e('Your comment is awaiting moderation.', 'reverie') ?></p> | |
</div> | |
<?php endif; ?> | |
<section class="comment"> | |
<?php comment_text() ?> | |
</section> | |
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> | |
</article> | |
<?php } ?> | |
<?php | |
// Do not delete these lines | |
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) | |
die (__('Please do not load this page directly. Thanks!', 'reverie')); | |
if ( post_password_required() ) { ?> | |
<section id="comments"> | |
<div class="notice"> | |
<p class="bottom"><?php _e('This post is password protected. Enter the password to view comments.', 'reverie'); ?></p> | |
</div> | |
</section> | |
<?php | |
return; | |
} | |
?> | |
<?php // You can start editing here. Customize the respond form below ?> | |
<?php if ( have_comments() ) : ?> | |
<section id="comments"> | |
<h3><?php comments_number(__('No Responses to', 'reverie'), __('One Response to', 'reverie'), __('% Responses to', 'reverie') ); ?> “<?php the_title(); ?>”</h3> | |
<ol class="commentlist"> | |
<?php wp_list_comments('type=comment&callback=reverie_comments'); ?> | |
<?php // wp_list_comments(); ?> | |
</ol> | |
<footer> | |
<nav id="comments-nav"> | |
<div class="comments-previous"><?php previous_comments_link( __( '← Older comments', 'reverie' ) ); ?></div> | |
<div class="comments-next"><?php next_comments_link( __( 'Newer comments →', 'reverie' ) ); ?></div> | |
</nav> | |
</footer> | |
</section> | |
<?php else : // this is displayed if there are no comments so far ?> | |
<?php if ( comments_open() ) : ?> | |
<?php else : // comments are closed ?> | |
<section id="comments"> | |
<div class="notice"> | |
<p class="bottom"><?php _e('Comments are closed.', 'reverie') ?></p> | |
</div> | |
</section> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php if ( comments_open() ) : ?> | |
<section id="respond"> | |
<h3><?php comment_form_title( __('Leave a Reply', 'reverie'), __('Leave a Reply to %s', 'reverie') ); ?></h3> | |
<p class="cancel-comment-reply"><?php cancel_comment_reply_link(); ?></p> | |
<?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?> | |
<p><?php printf( __('You must be <a href="%s">logged in</a> to post a comment.', 'reverie'), wp_login_url( get_permalink() ) ); ?></p> | |
<?php else : ?> | |
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" class="nice"> | |
<?php if ( is_user_logged_in() ) : ?> | |
<p><?php printf(__('Logged in as <a href="%s/wp-admin/profile.php">%s</a>.', 'reverie'), get_option('siteurl'), $user_identity); ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php __('Log out of this account', 'reverie'); ?>"><?php _e('Log out »', 'reverie'); ?></a></p> | |
<?php else : ?> | |
<p> | |
<label for="author"><?php _e('Name', 'reverie'); if ($req) _e(' (required)', 'reverie'); ?></label> | |
<input type="text" class="input-text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?>> | |
</p> | |
<p> | |
<label for="email"><?php _e('Email (will not be published)', 'reverie'); if ($req) _e(' (required)', 'reverie'); ?></label> | |
<input type="email" class="input-text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?>> | |
</p> | |
<p> | |
<label for="url"><?php _e('Website', 'reverie'); ?></label> | |
<input type="url" class="input-text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3"> | |
</p> | |
<?php endif; ?> | |
<p> | |
<label for="comment"><?php _e('Comment', 'reverie'); ?></label> | |
<textarea name="comment" id="comment" tabindex="4"></textarea> | |
</p> | |
<p id="allowed_tags" class="small"><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></p> | |
<p><input name="submit" class="blue nice button radius" type="submit" id="submit" tabindex="5" value="<?php _e('Submit Comment', 'reverie'); ?>"></p> | |
<?php comment_id_fields(); ?> | |
<?php do_action('comment_form', $post->ID); ?> | |
</form> | |
<?php endif; // If registration required and not logged in ?> | |
</section> | |
<?php endif; // if you delete this the sky will fall on your head ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment