0

From WP codex:

comment_moderation_text: applied to the body of the mail message before sending email notifying the administrator of the need to moderate a new comment. Filter function arguments: mail body text, comment ID.

Nevertheless, when I put in my functions.php:

function x99($textMsg, $comId) {
  if (is_null($comId)) {
    return "empty";
  } else {
    return ($textMsg);
  }
}
add_filter("comment_notification_text", "x99");

the notification message body is "empty". So comment ID is null. Why? How can I retrieve it?

1 Answer 1

1

For the arguments, check the source:

$notify_message  = apply_filters( 'comment_notification_text',       $notify_message,  $comment_id );

You have two parameters. The first is the notification text itself, prior modification by your filter. It is constructed earlier in the same function and is different for comments, trackbacks, and pingbacks. The second parameter, as you might guess from the name, is the comment ID. That is all correct, as per the Codex entry you found.

However, your problem is that only the first parameter is passed by default. If you want any of the others you have to ask for them by means of the fourth parameter of add_filter.

add_filter("comment_notification_text", "x99", 1, 2);

The third parameter is a priority. You can raise that or lower it depending on your needs. 1 should run your filter early.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.