The transition_comment_status action will get called whenever the status of a comment changes from one thing to another thing, regardless of what those things are.
If you don’t want it to take action when going from trashed to approved, you need to recognize when the $old_status is trashed and not take action at that point in time. Right now, you’re only checking that the $new_status is approved, you’re not checking what the old status was.
Related Posts:
- Comments screen in backend, how to disable Quick Edit | Edit | History | Spam | for non admins
- Restore trashed posts with comments
- Deleting the attached “comment replies” when trashing a comment
- What’s the difference with trash_comment and wp_trash_comment?
- Prevent users to delete comments from trash
- wp_trash_post retrashes already trashed comments?
- Conditionally process comments while ignoring replies
- Add option to disable comments on a per posts basis?
- Paginate result set from $wpdb->get_results()
- What should I do to make generated avatars different for anonymous comments?
- Check If comment author is registered
- How do I turn off wordpress comments ability to capture a users ip address?
- Success message in comment form
- How to allow the reply link to remain on the comment form after I have reached my 10 nested comment limit?
- Threaded comments – deleting parent comment leads to orphan comments
- Is there a hook for comment author link?
- How can I edit the email sent when a new comment is received?
- How to remove or replace the log-in link for comment replies?
- Change the HTML output of comments
- How to Block Access to Standard Login Flow and Comment Flow
- Add Comment Custom Field
- Remove link preview in discussion dashboard
- Upload images with comment
- Prevent Contributor to show comment list
- where to modify get_comment_author_link()?
- Does Akismet plugin expose any hooks, functions, class that can work with custom code?
- Change language of comments template
- Comments Feed & Custom Post Statuses
- How to enable comments options?
- WordPress comment count to include attachment comments
- Displaying comments with a walker: how to distinguish between parent and child comments
- Count parent comments & replies separately?
- How to modify comments form using comment_form()?
- Capability for allowing user to post own comments without moderation
- Comment form problem with comment_author_url and HTML5 input placeholders
- How would I count the number of times a comment meta field’s value is in a post’s entire comments?
- stackexchange-like submit comment window
- Cannot get local avatars to show [closed]
- Limit user to one comment
- WordPress comments on users profile
- wordpress threaded comments – customize nested ul / how child ul is displayd
- How to make a secure blog that is completely private?
- identify and delete spam comments from 3000 pending comments
- Hide comments column in WordPress backend
- How unrequire comment text in wordpress post
- Auto delete comment if Contains
- How would I add the comment count to this sub-pages of current page snippet
- How can I test why the comment hook is not working?
- API Hook for After Commenting (for sharing on Facebook)
- How do i remove “Website” field from WordPress comments
- Can comments by a logged-in user be displayed at the top?
- posts comments goes to trash
- Placed on + only date (not time)
- Loading Comments From a Class?
- have_comments not true for logged out visitors?
- WordPress for questions and responses website
- Anonymize comments after one year
- How to get comments other than using wp_list_comments?
- How many members have made comments approved for an article?
- How to get a value from comment meta
- reCaptcha doesnt appear in comment (manual or plugin)
- Add a Comment on/off option in Screen Options for Comments?
- Comment System showing different type of IP
- Pending Comments
- Only Allow post author and “Premium” Role user to comment
- Exclude the word comment from being referenced
- How to open up comments to all visitors
- Limit iframe output in comment-meta commentmetadata
- What is the earliest hook comment meta can be saved?
- Get Comment Author ID on the fly while posting
- Is this a wordpress bug? get_comment_link auto shoots when user visits his dashboard
- Comment as post – understanding wp_list_comments
- Comments and pingbacks issues
- Cannot unapprove a WordPress comment
- How to load new posts from wordpress db into wordpress homepage without refreshing the site?
- how show attachment image in comments query
- Automatically register users with comments
- Comments only displaying when logged in
- Same comment section on every page
- reply comment below the comment box without reload page
- Force to show all fields in comment forms to the logged-in users
- Unable to view comments on my website
- Using WordPress core pop-up comment function, doesn’t popup, maybe an elementor issue
- Comments editor not rendering   and tag
- How to call out the date of user’s first comment?
- Trying to get property of non-object notices in comment-template.php
- comment_moderation_subject is not working for me
- How do you remove the ability for a user to make a comment or post on a page?
- Comments – Ensure the correct field is highlighted for nested replies
- How to hold all comments for moderation, including author’s comments on own post
- Recent comments per tagged post?
- Subscribe to a post’s comments without posting a comment yourself
- WordPress error when sending comment
- WordPress Page Template: Comment Filtering with Querystring
- comments are going to spam
- Why default comment fields don’t show up?
- How to enable truly anonymous posting in bbPress forums? [closed]
- How to disable comments on new blog post, but allow on new products?
- Get approved comments or comments that the author is me
- Show/Hide comments