How to automatically evaluate comment content without user seeing the delay?


I’m developing a comment plugin that sends the comment’s content to a third party API and based on the response it either approves, trashes the comment or leaves it as pending.

The problem is that the response takes up to 30 seconds to come, so the user clicks “Post Comment” and sees the loading icon moving on his tab for up to 30 seconds, finally the page reloads and he either sees his approved comment posted, sees nothing has changed at all or sees the “awaiting moderation message” (approved, trashed, pending status respectively).

  1. Where should i hook the API request function so the the user
    always sees the “awaiting moderation” message without any delay and then the API request happens and the comment’s status is set
  2. Are there any hooks being activated during “dead time”? meaning the
    API requests can happen without the users experiencing delay and
    without requiring an admin to do anything to manually trigger them

I’ve tried hooking it on the wp_insert_comment action hook and got the results i mentioned above. Then i tried hooking it on the comment_post action hook, same outcome, only difference being that comment_post happens a bit later, after the comment has passed through the settings -> discussion filters the user has set.


BenjaminK 1 year 2021-08-10T06:31:48-05:00 0 Answers 0 views 0

Leave an answer