I’m in the beginning stages of writing a basic MVC WordPress plugin development framework, and I’m realizing I’m going to have a naming conflict issue. If I want to include this framework in several of the plugins and/or themes I’m developing, eventually I’m going to run into an issue that class_exists() isn’t going to solve.
I could create the framework as a stand-alone plugin, but that would require anyone who downloaded one of my plugins or themes to also download the framework, which doesn’t seem realistic (especially for upgrades to existing plugins that don’t have such a dependency currently).
Anyway, I figured many of you out there have probably run into these same issues, and I wanted to see if anyone had developed a good strategy to manage the problem.
If possible, I don’t what to have to have a unique prefix per plugin (that will making updating the framework a nightmare). I’m hoping there’s some clever way to dynamically name each of these classes without having to hard code it.
The solution I ended up choosing was to create a
bootstrap.phpfile, have each instance of the framework register (in a global variable) what version it is and its file path. Then I register an action to run after all plugins/theme are loaded which compares all versions and only loads the classes associated with the most recent version.The only downside I see to this is that I’d have to make sure my framework is backwards compatible, but I planned on doing that anyway.
Here is the code I used in my bootstrap file. Obviously the version number in each instance of the framework would need to correspond to the version number of the framework included.