Get Post ID within wp_set_comment_status hook
You should consider removing the average_ratingfn() function definition out of there and call it with an input argument for the post ID. You can try to fetch the comment object with (untested): $comment = get_comment( $comment_ID ); and then make sure it’s not null or you have an actual comment object with: if( $comment instanceof … Read more