Skip to content

Commit 5802e19

Browse files
committed
fix: Fixed hookCallback
1 parent be1970e commit 5802e19

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/Hooks/Hookable.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ abstract class Hookable
357357
];
358358

359359
/**
360-
* Hook name
360+
* Hooks to register
361361
*
362-
* @var string
362+
* @var string|string[]
363363
*/
364-
protected string $hookname;
364+
protected $hooks;
365365

366366
/**
367367
* Hook priority
@@ -375,10 +375,15 @@ abstract class Hookable
375375
*/
376376
public function __construct()
377377
{
378-
if (!in_array($this->hookname, self::$availableHooks)) {
379-
throw new Exception("Invalid hook name: {$this->hookname}");
378+
$hooks = is_array($this->hooks) ? $this->hooks : [$this->hooks];
379+
380+
foreach ($hooks as $hook) {
381+
if (!in_array($hook, self::$availableHooks)) {
382+
throw new Exception("Invalid hook name: {$hook}");
383+
}
384+
385+
add_hook($hook, $this->priority, [$this, 'hookCallback']);
380386
}
381-
add_hook($this->hookname, $this->priority, [$this, 'hookCallback']);
382387
}
383388

384389
/**

0 commit comments

Comments
 (0)