Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Only post author can reply to comments WordPress

  • SOLVED

Hi, please can someone help me re-write the below function to ensure <strong>comment_reply_link()</strong> is only shown/available to the author of the current post. My own attempt (which doesn't work) is outlined below. Thank you.


if ( ! function_exists( 'mytheme_comment' ) ) :

function mytheme_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<li id="li-comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>

<div id="comment-<?php comment_ID(); ?>">

<div class="comment-meta">
<?php echo get_avatar( $comment, 60 ); ?>
<?php printf(__('%s'), get_comment_author_link()); ?> -
<?php printf( __( '%1$s @ %2$s', 'mytheme' ), get_comment_date('M j'), get_comment_time('G:i A') ); ?>

<?php

global $current_user;
get_currentuserinfo();
if ($current_user->ID == $post->post_author) {
comment_reply_link( array_merge( $args, array( 'reply_text' => ' - Reply', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) );
}

?>

</div>

<div class="comment-body">
<?php if ( $comment->comment_approved == '0' ) : ?><?php _e( '<p class="moderate">Your comment is awaiting moderation.</p>', 'mytheme' ); ?><?php endif; ?>
<div><?php comment_text(); ?></div>
</div>

</div>
<!-- #comment-## -->
<?php
break;
case 'pingback' :
case 'trackback' :
break;
endswitch;
}
endif;

Answers (1)

2010-12-08

Andrzej answers:

Your code seems to be nearly it, just change:
global $current_user;
to
global $current_user, $post;
and let me know if it works any better?

Thanks