From 15e4635fe32ed1efba129a96d31a69b50dea37ba Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Thu, 28 Jul 2022 16:14:28 +0200 Subject: [PATCH] Add hook registration helper methods to registry [MAILPOET-4515] --- mailpoet/lib/Automation/Engine/Registry.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mailpoet/lib/Automation/Engine/Registry.php b/mailpoet/lib/Automation/Engine/Registry.php index c8ed1a130d..8c291eb197 100644 --- a/mailpoet/lib/Automation/Engine/Registry.php +++ b/mailpoet/lib/Automation/Engine/Registry.php @@ -20,6 +20,15 @@ class Registry { /** @var array */ private $actions = []; + /** @var WordPress */ + private $wordPress; + + public function __construct( + WordPress $wordPress + ) { + $this->wordPress = $wordPress; + } + public function addSubject(Subject $subject): void { $key = $subject->getKey(); if (isset($this->subjects[$key])) { @@ -91,4 +100,12 @@ class Registry { public function getActions(): array { return $this->actions; } + + public function onBeforeWorkflowSave(callable $callback, int $priority = 10): void { + $this->wordPress->addAction(Hooks::WORKFLOW_BEFORE_SAVE, $callback, $priority); + } + + public function onBeforeWorkflowStepSave(callable $callback, int $priority = 10): void { + $this->wordPress->addAction(Hooks::WORKFLOW_STEP_BEFORE_SAVE, $callback, $priority); + } }