Plugin Events/Hooks

Hey!

I am currently working on some Plugins, which are already working on my site, a comment plugin and a rating plugin. Both should use Webmentions. The comments already have a route listening for incomming webmentions, but the rating plugin also needs to listen to webmentions.

So I started building a third plugin, called Tratschtante. The idea behind that plugin was, that I would add a route for incomming webmentions and every other plugins using webmentions can somehow “subscribe” to that route.

My first thought was to a hook for that. But I didn’t find a way to create my own hook. Is this possible? To define a hook in a plugin, so other plugins can listen to that hook?
Or is there any other option to let plugins talk, like with an event system?

Thank you!
Maurice

Yes, you can trigger custom hook and listen like that

Trigger

$kirby->trigger('subscribe', $foo, $bar);

Listen

return [
  'hooks' => [
    'subscribe' => function ($foo, $bar) {
      // do something on subscribed
    }
  ]
];

That’s perfect! Thank you :slight_smile: