Adding functions that affect all sites?

This may sound like a daft question, but is it possible to add functions code anywhere that will activate on all sites? For instance, I've found a piece of code that searches bbPress posts along with WP posts, but to enable it on all themes, I'd have to add it on all themes, and then again when they update.

Is there a way to do this, or would it be too difficult?