Plugin importing other plugins code inside
-
Developing a plugin I’ve encoutered a problem on using inside other plugins as a library.
1. I create a plugin with a vendor folder where I put the code of another plugin that I want to reuse. For example a Mobile_User_Agent_Detector.
2. In my plugin I import a class from Mobile_User_Agent_Detector using require_once. Then I use the class contained in that php file.
For example:
require_one ..../my_plugin/vendor/mobile-user-agent-detector.php $detector = new Mobile_User_Agent_Detector()3. In a wordpress I install my plugin and another plugin that it’s using Mobile_User_Agent_Detector as well.
4. It fails. Because when I import the Mobile_User_Agent_Detector it’s already defined.
I’ve seen plugins that wraps any global method or class definitions from the THIRD_PARTY_PLUGIN to check if it’s already defined. Is there a better way to do import another library and not have collissions with other plugins?
How are you approaching this problem?
The topic ‘Plugin importing other plugins code inside’ is closed to new replies.