How do I only show comment form to post author while comments is shown to everyone?
How do I only show comment form to post author while comments is shown to everyone?
I think it's possible to query a wordpress post author id of the current post and compare it with the id of the current login user of the current page. Such that, if the IDs is a match, a comment form is shown, otherwise the comment form is hidden.
I did tried to do it. The IDs were retrieved and compared successfully, the criteria were met but, I'm not sure what is still keeping the comment form hidden.
I don't know if the argument to show or hide comments based on the above stated conditions is best to implement in my custom comment template review-comments.php or if it is best to implement the logic in my theme single review page template single-review.php where my custom comment template is included to show comments and comment form?
My trial was done in review-comment.php
<?php
if (have_comments()) :
?>
<div class="escortreviewtext">
<h4 class="rad3">Escort Reply:</h4>
<div class="commentlistall">
<?php wp_list_comments(array('callback' => 'theme_comments', 'style' => 'div', 'type' => 'comment')); ?>
<div class="clear"></div>
</div>
</div>
<?php endif; ?>
<div class="clear30"></div>
<?php
if (is_user_logged_in()) :
$current_user = wp_get_current_user();
$post = get_post(); // Get the current post object
$post_author_id = $post->post_author;
if ($current_user->ID === $post_author_id || current_user_can('administrator')) :
?>
<div class="commform" id="respond">
<form action="<?php echo esc_url(get_option('siteurl') . '/wp-comments-post.php'); ?>" method="post" id="commentform">
<div class="commtext col-100">
<?php _e('', 'escortwp'); ?>
<div class="clear"></div>
<textarea name="comment" id="comment" class="commtextarea" placeholder="Thanks dear❤️" tabindex="1" rows="10" style="width: 96%; border-radius: 5px; padding: 10px; margin-left: 10px; border: 1px solid #FE5ACB99;"></textarea>
</div>
<div class="clear10"></div>
<div class="text-center">
<input type="submit" class="pinkbutton commsubmitbutton rad25" name="submit" value="<?php _e('Reply', 'escortwp'); ?>" tabindex="2" />
</div>
<?php $replytoid = isset($_GET['replytocom']) ? (int)$_GET['replytocom'] : 0; ?>
<input type='hidden' name='comment_parent' id='comment_parent' value='<?php echo $replytoid; ?>' />
<input type="hidden" name="comment_post_ID" value="<?php echo esc_attr($post->ID); ?>" />
<?php do_action('comment_form', $post->ID); ?>
<a rel="nofollow" id="cancel-comment-reply-link" href="#respond" class="cancel-comment-reply-link rad5" style="display: none;"><?php _e('Cancel reply', 'escortwp'); ?></a>
</form>
</div> <!-- COMMENTS FORM -->
<?php endif;
endif; ?>
<!-- Display IDs at the footer for comparison -->
<footer>
<p>Current User ID: <?php echo $current_user->ID; ?></p>
<p>Post Author ID: <?php echo $post_author_id; ?></p>
</footer>
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand