This is why I strongly believe in writing framework-agnostic code. The extra effort of splitting even small bits functionality into decoupled components can save so many headaches in the future.
When I'm writing a new feature, I always try and code it as if I'm going to release it as a standalone library that could easily work for other people regardless of what framework they're using.
Stuart Herbert wrote a lot about this: http://blog.stuartherbert.com/php/php-components/