Which hook do I use to edit pending comment count on wordpress dashboard?

You can manually adjust this number using the following method. function adjust_wp_comments_count( $original_counts ) { $counts = new \stdClass(); $counts->moderated = 99; return $counts; } add_filter( ‘wp_count_comments’, ‘adjust_wp_comments_count’, 100, 1 ); The line: $counts->moderated = 99 is what you will need to adjust if you want to set it to a particular value or calculation … Read more

Only show own comments in admin panel

I believe the below should do the trick, just add to your functions.php file. /** * Prevent non-administrator users from viewing others comments. */ add_filter( ‘comments_list_table_query_args’, function( $args ) { global $pagenow; if ( $pagenow == ‘edit-comments.php’ ) { $user = wp_get_current_user(); $value = !empty( $args[ ‘author__in’ ] ) ? $args[ ‘author__in’ ] : []; … Read more

Counting Comments as Singular and Plural in comments.php Template

This should do the trick… <?php $number_of_parents = comment_counter($post->ID); $number_of_children = $post->comment_count – $number_of_parents; ?> <?php if ( have_comments() ): ?> <h3 class=”comments-title”>Discussion: <?php if ( $number_of_children > 0 ): ?> <?php echo implode( ‘ ‘, [ printf( _n( ‘%d question’, ‘%d questions’, $number_of_parents ), $number_of_parents ), __( ‘and’ ), printf( _n( ‘%d answer’, ‘%d … Read more

WordPress Spam Comment Filter

As said in this comment, WordPress has some possibilities to moderate comments and some good plugins for spam prevention. Nevertheless, if I understand you correctly you would like to prevent the post of comments before it gets to the database. I think I’ve found a solution for that. Check out the code for your functions.php. … Read more

How to make comments private for commentor and post author

You can use the pre_get_comments filter to modify the parameters of the comment query before it fetches the comments. Specifically the author_in parameter. I tried to write an example, though I haven’t tested it, but it would be similar to this: add_action( ‘pre_get_comments’, ‘author_and_self_comment_filter’ ); function author_and_self_filter( \WP_Comment_Query $query ) : void { // We … Read more

Hide comments on specific pages, not just disable future comments

There’s a filter, wp_count_comments, that might do what you need: add_filter( ‘wp_count_comments’, ‘wpse_404619_maybe_disable_comments’, 10, 2 ); /** * Disables comments on certain pages. * * @param array $comments The page’s comments. * @param int $post_id The page’s post_ID. * @return array The filtered comments; empty array to disable. */ function wpse_404619_maybe_disable_comments( $comments, $post_id ) { … Read more

How to get comment images stored as serialized comment meta

What you get is fine, it’s the image id, now you just need to loop them and output the structure that you want, for example. if (!empty($images = get_comment_meta( $comment->comment_ID , ‘reviews-images’, true ))) { foreach ($images as $image_id) { $image_src = wp_get_attachment_image_src($image_id, ‘full’); // Now you have the image src, $image_src, you can do … Read more