What hook type is running?

Maybe this is more of a PHP question but can I get what hook is running?

kirby()->hook(['panel.page.create', 'panel.page.update'], function($page) {
  // Now the create hook is running
  <?php echo $hook_type; ?>

If not, I think it can be usesful as a second or third optional argument.

1 Like
1 Like

Thanks @Pascalmh.

It does not seems to be possible yet then. I still tried to make it work. It feels like I’m almost there.

// Function with array containing all the hooks, a few in this example
function hooks() {
  return array(

// Loop the hooks array
foreach(hooks() as $hook) {
  kirby()->hook($hook, function($page) use (&$hook) {
    // Save $hook to log file
    // Saves 'panel.avatar.delete', but it's the update hook that runs

Anyone knows why it saves the last item in the array in my log file? I was hoping it would save the current $hook that was used at that moment.

I hope there is a solution. Else I would need to repeat myself 20 times for all the hooks. :confused:

Why do you pass the $hook variable by reference? It should work without

use ($hook)

There is a typo (extra parenthesis) in your hook() function as well, I’ve corrected it.

1 Like

When I save something to my log I also want to save the name of the hook. Thanks for the typo fix, :slight_smile:

Also your fix (removed the &) seems to make it work! :smiley: