# Check in plugin if other plugin exists

**URL:** <https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 24, 2016, 3:11pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325 "2016-09-24T15:11:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [September 24, 2016, 3:11pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/1 "2016-09-24T15:11:27Z")

</div>

I am trying to build modular plugins as optional extensions to my plugin. IS there a way to check in one plugin that another exists?

For example load routes only if class exists? it’s problematic because I don’t know if plugins are loaded in a specific order?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 24, 2016, 3:13pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/2 "2016-09-24T15:13:09Z")

</div>

Check out this post as regards load order: [Plugin load order?](https://forum.getkirby.com/t/plugin-load-order/1701/2)

---

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [September 24, 2016, 3:17pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/3 "2016-09-24T15:17:01Z")

</div>

This makes snese, but two new questions come up one I’m gonna play with right now.

1. What happens if I load a plugin that doesnt exist (answer to this in couple of minutes)

Answer: nothing happens - it returns false. very good.

1. how do I prevent my plugin from stopping other plugins from loading? Since I’m using my own router inside the panel - it means that anything that happens after the router doesn’t function.

**EDIT**

Ok, not my “ideal” solution, but what I’m planning to do is copy parts of the kirby plugin loading to load the rest, while at the same time preventing loading the plugin again and again (infinite loops are bad)  
Before I dive into this (Im not at home atm) - would I need to do the same to addons (panel fields for example) not defined in plugins directory?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 24, 2016, 4:13pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/4 "2016-09-24T16:13:29Z")

</div>

> [@LCD344](#):
>
> how do I prevent my plugin from stopping other plugins from loading? Since I’m using my own router inside the panel - it means that anything that happens after the router doesn’t function.

That’s unfortunately not going to work. You can’t “wait” for other plugins to load before registering your router. I see two workarounds:

- Define your router in a plugin like `zzzz_myplugin` to ensure that it always loads last, but: a) not very elegant and b) not compatible with the “load plugin from another plugin” approach
- Make your modular extension modules register themselves at your main plugin; this approach will work if each module needs its own separate routes, you could then register a router for each module

Stopping execution inside plugins (e.g. with routers) is a very difficult topic. Something like a “all plugins are loaded” hook so that plugins can be notified and register their routers could work, but that would still not solve the issue for other Kirby extensions like fields, widgets etc.

---

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [September 24, 2016, 6:34pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/5 "2016-09-24T18:34:50Z")

</div>

Ok, I managed to do it. basically like I said I made a function that skips the current plugin (since the router works after all the plugin is loaded anyway. And just make sure that it skips the plugin that I’m already running (just so it won’t keep loading again and again)

```
function loadPlugins($skip = []){
   $kirby = kirby();
   if (! is_array($kirby->plugins)) {
      $kirby->plugins = [];
   }

   $root = $kirby->roots->plugins();

   // check for an existing plugins dir
   if(!is_dir($root)) return $kirby->plugins;

   foreach(array_diff(scandir($root), array('.', '..')) as $file) {
      if(!in_array($file,$skip)){
         if(is_dir($root . DS . $file)) {
            $kirby->plugin($file, 'dir');
         } else if(\f::extension($file) == 'php') {
            $kirby->plugin(f::name($file), 'file');
         }
      }
   }

}

```

The important thing here is to call this function after I already know my router is going to work, and before calling its function.

seems to work so far. But @lukasbestle - you’re the expert, do you see any reason it won’t? (I don’t wanna do a lot of work and then discover that it’s based on something buggy)

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 24, 2016, 6:50pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/6 "2016-09-24T18:50:27Z")

</div>

Well, it looks like a hack and I wouldn’t depend on it. I don’t know if it will work or not, just try it out. 🙂

---

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [September 24, 2016, 6:55pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/7 "2016-09-24T18:55:04Z")

</div>

it is indeed a hack. but I really want to extend the panel 😛

it does work as far as I can see!

Can we ask for plugins loaded hook for kirby 2.4?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 24, 2016, 7:07pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/8 "2016-09-24T19:07:09Z")

</div>

Not for Kirby 2.4 because of fields, widgets etc. It’s just more complex than it seems, but we will keep this in mind.

---

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [September 24, 2016, 7:10pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/9 "2016-09-24T19:10:03Z")

</div>

Aight, Ill put this a solved for now - We need a hackily solved tag 😉

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:55pm UTC](https://forum.getkirby.com/t/check-in-plugin-if-other-plugin-exists/5325/10 "2025-02-06T16:55:13Z")

</div>


