Skip to content

Commit

Permalink
fix: Fixed hookCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Sep 30, 2023
1 parent be1970e commit 5802e19
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Hooks/Hookable.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ abstract class Hookable
];

/**
* Hook name
* Hooks to register
*
* @var string
* @var string|string[]
*/
protected string $hookname;
protected $hooks;

/**
* Hook priority
Expand All @@ -375,10 +375,15 @@ abstract class Hookable
*/
public function __construct()
{
if (!in_array($this->hookname, self::$availableHooks)) {
throw new Exception("Invalid hook name: {$this->hookname}");
$hooks = is_array($this->hooks) ? $this->hooks : [$this->hooks];

foreach ($hooks as $hook) {
if (!in_array($hook, self::$availableHooks)) {
throw new Exception("Invalid hook name: {$hook}");
}

add_hook($hook, $this->priority, [$this, 'hookCallback']);
}
add_hook($this->hookname, $this->priority, [$this, 'hookCallback']);
}

/**
Expand Down

0 comments on commit 5802e19

Please sign in to comment.