Reusable functions and tools (Framework)

Since you want to be able to use these functions within your themes AND plugins, and taking into consideration your comment regarding loading, I’d recommend the following approach.

Organize your functions into a library – depending on your methods and approaches, this could be multiple or single files. It could be just functions or as a class.

Wrap your functions or classes with conditional checks to make sure they are not defined already (in case you inadvertently load it twice). if ( function_exists( ... or if ( class_exists( ...

Establish one point in your plugin or theme where you check if a key function or class exists, and if not, use include_once() to load your library file. Hook this to the initialization of your plugin or theme, so that you’re just doing it once (although each theme or plugin would check – but if it’s already loaded, it will only be loaded once). For example:

if ( ! function_exists( 'my_cool_utility' ) ) {
include_once( 'my_function_library.php' );
}

Doing it this way allows you to use your library across multiple themes and plugins that may or may not be used together, while making sure (1) that the code is there and available while (2) avoiding issues of it being loaded more than once.

This is a method that I personally use in developing both free and premium plugins and themes. I have a number of libraries that get reused across different products that may or may not be used together. By packaging the library with the theme or plugin, I know it will be there and the user doesn’t have to load something separate to use it.

Hope I explained that well enough for you. If not, ask questions in the comments and I’ll try to edit for clarity.