Delete same image with different extension via panel

Hey,

i use the kirby3-webp plugin to create a duplicate an image while uploading it.
E.g: i upload test.png, test.webp will be generated automatically.

When i now delete the test.png via the panel, test.webp wont be deleted.

How can i configure to delete the .webp image too via the panel?

Best
Marvin

The webp images are generated via a file.create:after/file.replace:after hook. In the same way, you can use a file.delete:after hook to get rid of the webp images again.

i tried something like this but it doesnt work.
Says sth like: expects object but gets string. I mean thats obvious, but i dont know how to change that.

'hooks' => [
    'file.delete:before' => function ($file) {

        $file . '.webp' ->delete();

        $toDelete = $file->name()  . '.webp';
        $toDelete->toFile()->delete();
        // do something before a page gets deleted
    }
]

As I said, you need a file.delete:after hook.

‘hooks’ => [
‘file.delete:after’ => function ($status, $file) {

    if ( $toDelete = $file->parent()->image($file->name() . '.webp' ) ){
       $toDelete->delete();
    }

]
2 Likes