comment_notification_text filter not working

I want to customize notification for post author when comment is posted.

My code in functions.php is :

//add notifications when comment
add_action( 'wp_insert_comment', 'wp_notify_postauthor' );

//change email notification comment
function wpd_comment_notification_text( $notify_message, $comment_id ){
    // get the current comment and post data
    $comment = get_comment( $comment_id );
    $post = get_post( $comment-comment_post_ID );
    // don't modify trackbacks or pingbacks
    if( '' == $comment-comment_type ){
        // build the new message text
        $notify_message  = sprintf( __( 'New comment on your post %s' ), $post-post_title ) . \r\n;
        $notify_message .= sprintf( __('Author : %1$s'), $comment-comment_author ) . \r\n;
        $notify_message .= sprintf( __('E-mail : %s'), $comment-comment_author_email ) . \r\n;
        $notify_message .= __('Comment: ') . \r\n . $comment-comment_content . \r\n\r\n;
        $notify_message .= __('You can see all comments on this post here: ') . \r\n;
        $notify_message .= get_permalink($comment-comment_post_ID) . #comments\r\n\r\n;
        $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . \r\n;

        if ( user_can( $post-post_author, 'edit_comment', $comment_id ) ) {
            if ( EMPTY_TRASH_DAYS )
                $notify_message .= sprintf( __('Trash it: %s'), admin_url(comment.php?action=trashc=$comment_id) ) . \r\n;
            else
                $notify_message .= sprintf( __('Delete it: %s'), admin_url(comment.php?action=deletec=$comment_id) ) . \r\n;
            $notify_message .= sprintf( __('Spam it: %s'), admin_url(comment.php?action=spamc=$comment_id) ) . \r\n;
        }
    }
    // return the notification text
    return $notify_message;
}
add_filter( 'comment_notification_text', 'wpd_comment_notification_text', 1, 2 );
add_filter( 'comment_moderation_text', 'wpd_comment_notification_text', 1, 2 );

Now, notification is send but with default message (I remove URL and whois in mine). I don't understand why my filter is not working.

Thanks a lot

Topic notifications filters comments Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.