# Kirby Hooks Debugger

**URL:** <https://forum.getkirby.com/t/kirby-hooks-debugger/4982>\
**Category:** Plugins\
**Created:** [August 15, 2016, 12:07pm UTC](https://forum.getkirby.com/t/kirby-hooks-debugger/4982 "2016-08-15T12:07:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 15, 2016, 12:07pm UTC](https://forum.getkirby.com/t/kirby-hooks-debugger/4982/1 "2016-08-15T12:07:01Z")

</div>

# Kirby Hooks Debugger

> **[kirby-deprecated-plugins/kirby-hooks-debugger](https://github.com/kirby-deprecated-plugins/kirby-hooks-debugger)**
>
> Debug Kirby Panel hooks. Contribute to kirby-deprecated-plugins/kirby-hooks-debugger development by creating an account on GitHub.

There are two main problems with hook errors in the panel.

1. The panel hangs.
2. No useful information about the error is displayed.

This plugin presents a useful error message.

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/d/dcc0c23663ff6a088c8c1e01a260a2159434a43a.png)

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/4/446ab87f4c57018640574606bb3ba2c493db49fd.png)

In the future I hope there will be a built in solution, but until then this plugin might be useful.

## 1. Install

### Kirby CLI

Run this command:

```auto
kirby plugin:install jenstornell/kirby-hooks-debugger

```

### Manually

```auto
Add the folder kirby-hooks-debugger into /site/plugins/.

```

## 2. Usage

### 1. Blueprint

It’s recommended to add this field before any other field.

```auto
fields:
  hooksdebugger:
    type: hooksdebugger

```

### 2. Must be loaded first

Kirby Hooks Debugger needs to load before any other plugin that uses hooks in order to work. There are at least two ways to do that:

**Alternative 1 - Rename the plugin**

Rename the folder `kirby-hooks-debugger` to `aaa` and the file `kirby-hooks-debugger.php` to `aaa.php`.

**Alternative 2 - Load the Kirby Hooks Debugger plugin from your plugin**

If you are building a plugin you can add this line to force load the Kirby Hooks Debugger plugin.

```php
kirby()->plugin('kirby-hooks-debugger');

```

### 3. Debug needs to be `true`

You need to set this in `config.php`:

```auto
c::set('debug', true);

```

## Options

Add them to config.php.

### Logfile path

Where the log should be stored.

```php
c::get( 'plugin.hooks.debugger.logfile', kirby()->roots()->index() . DS . 'hooks-debugger.txt' );

```

### Error types

Add an array with error numbers or constants.  
[http://php.net/manual/en/errorfunc.constants.php](http://php.net/manual/en/errorfunc.constants.php)

Default is to only show fatal run-time errors.

```php
c::get('plugin.hooks.debugger.error.types', array(1));

```

### Hooks

Hooks to debug. Default is every built in hook.

```php
c::get('plugin.hooks.debugger.hooks', array(
  'panel.page.create',
  'panel.page.update',
  'panel.page.delete',
  'panel.page.sort',
  'panel.page.hide',
  'panel.page.move',
  'panel.site.update',
  'panel.file.upload',
  'panel.file.replace',
  'panel.file.rename',
  'panel.file.update',
  'panel.file.sort',
  'panel.file.delete',
  'panel.user.create',
  'panel.user.update',
  'panel.user.delete',
  'panel.avatar.upload',
  'panel.avatar.delete'
));

```

## Changelog

0.1

Initial release

## Requirements

Kirby 2.3.2

## License

MIT

---

<div class="post-metadata">

**Author:** ![bastianallgeier](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bastianallgeier/32/7569_2.png) [@bastianallgeier](https://forum.getkirby.com/u/bastianallgeier)\
**Post date:** [August 15, 2016, 5:03pm UTC](https://forum.getkirby.com/t/kirby-hooks-debugger/4982/2 "2016-08-15T17:03:39Z")

</div>

I really like this a lot!! I also agree that we need a better built-in solution, but I’m glad you got us covered in the meantime 🙂

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 16, 2016, 6:46am UTC](https://forum.getkirby.com/t/kirby-hooks-debugger/4982/3 "2016-08-16T06:46:42Z")

</div>

Thanks! 😃

**The key functions in my solution is:**

```php
error_get_last();
register_shutdown_function()

```

With these functions the latest error can be fetched and do something useful with the error message. Maybe you already know that. 🙂

I have also thought about how to solve the problem with that the panel hangs when there are errors. First I figured out that Ajax would be a solution because the request would then be an isolated event and can be taken care of.

When thinking about it some more what is really needed is an extra http request, like calling a route and see if it’s a valid json or not. As far as I know that would be the only thing that can make the panel continue to load even if there are errors.

**Question:** If I or someone solves a problem that in the long run should be solved in the core, will it delay the development of that feature because a solution already exists as a plugin? Or is it the other way around, that because there are one or many plugins to solve something it’s set to a high priority to solve in the core? Or does a plugin don’t have any affect at all on the core directions?

---

<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:** [August 16, 2016, 8:52am UTC](https://forum.getkirby.com/t/kirby-hooks-debugger/4982/4 "2016-08-16T08:52:41Z")

</div>

> [@jenstornell](#):
>
> Question: If I or someone solves a problem that in the long run should be solved in the core, will it delay the development of that feature because a solution already exists as a plugin? Or is it the other way around, that because there are one or many plugins to solve something it’s set to a high priority to solve in the core? Or does a plugin don’t have any affect at all on the core directions?

Everything together. 🙂  
We decide on the features to implement based on the number of users who need the feature. If there’s a plugin that’s used a lot, we of course consider that and prioritize the feature.
