Hi Mark,
thank you for the code. No errors and it seems to be working. I've tested the comments feature and IP was registered correctly in both Wordfence live log and the comments page. I'll wait today and check if those errors appear again and if not I'll close this one as solved.
Again, thanks for the support and this great plugin - lifesaver for my site.
Regards,
Margareta