Title: Plugin importing other plugins code inside
Last modified: November 9, 2017

---

# Plugin importing other plugins code inside

 *  [eduardcot](https://wordpress.org/support/users/eduardcot/)
 * (@eduardcot)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/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?

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/plugin-importing-other-plugins-code-inside/#post-9667616)
 * All publicly available plugins should be visible to WP and not hidden in your
   plugin folder for that very reason. If you must do so for some reason, you need
   to mask it’s references through unique classes or namespaces, so in essence that
   hidden plugin becomes a fork that you’re responsible for.
 * For publicly available plugins, it’s better to leave them as their own entity
   and check if they are active through the “active_plugins” option before doing
   anything dependent upon that plugin. Then other devs that want to depend on that
   plugin can use the same resource instead of creating another fork of the same
   thing.

Viewing 1 replies (of 1 total)

The topic ‘Plugin importing other plugins code inside’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 5 months ago](https://wordpress.org/support/topic/plugin-importing-other-plugins-code-inside/#post-9667616)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
