This filter allows you to customize the response shown when a comment is stored as spam or trash. By default, wpDiscuz displays the configured spam or trash message. If a moderation plugin returns a plain-text explanation, you can use this filter to modify or replace the response.
Parameters
- $response (type: string|array) – The default wpDiscuz phrase key or a response returned by a previous filter. Return a valid phrase key or an array containing [“error” => “message”].
- $comment (type: WP_Comment) – The comment that was stored as spam or trash. For a duplicate retry, this is the previously stored comment.
- $commentData (type: array) – The comment data submitted in the current attempt.
- $isDuplicateRetry (type: bool) – true if WordPress rejected the current submission as a duplicate of a previously stored spam comment. In this case, no new comment was stored.
Usage
add_filter("wpdiscuz_comment_rejected_response", "my_rejected_comment_response", 10, 4);
function my_rejected_comment_response($response, $comment, $commentData, $isDuplicateRetry) {
if ($isDuplicateRetry) {
return $response;
}
$reason = get_comment_meta((int)$comment->comment_ID, "_myplugin_public_rejection_reason", true);
if (!is_string($reason) || trim($reason) === "") {
return $response;
}
return ["error" => $reason];
}
Note
The filter runs for main comments, replies, and inline feedback stored as spam or trash. It also runs when a new attempt is refused as a duplicate of an earlier spam comment.
It does not run for comments held for approval, published comments, duplicates of those comments, or requests refused before a comment is stored. wpDiscuz escapes an [“error” =>
“…”] message before displaying it, so return plain text rather than HTML.
Existing callbacks registered for two or three parameters continue to work.
Changelog
Since 7.6.68: The filter can customize the response for comments stored as spam or trash.
Starting from 7.6.71: It also runs for a duplicate retry of a spam comment and receives the fourth parameter, $isDuplicateRetry.
