How to exclude categories from recent posts, recent comments & category widgets?

I use the bellow function (thanks to @helgatheviking!) to exclude categories from the wordpress loop. It works very well – posts of selected categories are excluded from the loop on the main blog listing page, from category listing pages and from archives, but not from Recent Posts and not from Recent Comments in sidebar. How can be extended the action of this code also on them?