Yes it’s possible. Add a <script>
block to the header or footer that executes the pop up onload. But only if the user just submitted a comment. There’s at least a couple ways to determine this.
The user would have submitted a comment if the current request is a POST type. You can get this from $_SERVER['REQUEST_METHOD']
or if a required field name is set in $_POST
. The problem is you cannot tell if the comment was accepted this way, only that it was submitted. Perhaps it’s OK to thank them either way?
You could query for a recent comment by the current user as a way to determine if a thank you is in order, but this would only work for logged in users. This would not matter if you require being logged in to comment. The advantage here is you are not thanking spammers, FWIW. Spammers don’t stay around to check responses anyway.
A combination of the two methods should work. Grab the email out of $_POST
and use that to query for recent comments that are not spam. Then the thank you is only shown for accepted comments regardless of logged in status. You could tailor the thank you by comment status: spam, moderation queue, or accepted. Even if the user refreshes a POST, the comment will be rejected as duplicate and no thank you will appear.