From e30d7cfc036c354ee1b6255db287db1c9762b522 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 10 Nov 2018 15:15:46 +0000
Subject: [PATCH 1/4] Add some hook to check if hook should be forked

---
 src/Core/Hook.php | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/Core/Hook.php b/src/Core/Hook.php
index a0200a7db3..d221933dae 100644
--- a/src/Core/Hook.php
+++ b/src/Core/Hook.php
@@ -7,6 +7,7 @@ namespace Friendica\Core;
 use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
+use Friendica\Core\Logger;
 
 /**
  * Some functions to handle hooks
@@ -136,6 +137,22 @@ class Hook extends BaseObject
 	{
 		if (array_key_exists($name, self::$hooks)) {
 			foreach (self::$hooks[$name] as $hook) {
+				// Call a hook to check if this hook call needs to be forked
+				$hookdata = ['name' => $name, 'data' => $data, 'execute' => true];
+
+				if (array_key_exists('hook_fork', self::$hooks)) {
+					foreach (self::$hooks['hook_fork'] as $fork_hook) {
+						if ($hook[0] != $fork_hook[0]) {
+							continue;
+						}
+						self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
+					}
+				}
+
+				if (!$hookdata['execute']) {
+					continue;
+				}
+
 				Worker::add($priority, 'ForkHook', $name, $hook, $data);
 			}
 		}

From 4a59a7ae7f257e7b12b43157622b71c9c8888347 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 10 Nov 2018 15:16:48 +0000
Subject: [PATCH 2/4] Logger is not needed anymore

---
 src/Core/Hook.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/Core/Hook.php b/src/Core/Hook.php
index d221933dae..73aa95ee90 100644
--- a/src/Core/Hook.php
+++ b/src/Core/Hook.php
@@ -7,7 +7,6 @@ namespace Friendica\Core;
 use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
-use Friendica\Core\Logger;
 
 /**
  * Some functions to handle hooks

From 033bf65f2c9c271fb81bccd2c1f259c56a630516 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 10 Nov 2018 15:20:23 +0000
Subject: [PATCH 3/4] Some redesign

---
 src/Core/Hook.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Core/Hook.php b/src/Core/Hook.php
index 73aa95ee90..2d6c945067 100644
--- a/src/Core/Hook.php
+++ b/src/Core/Hook.php
@@ -137,19 +137,19 @@ class Hook extends BaseObject
 		if (array_key_exists($name, self::$hooks)) {
 			foreach (self::$hooks[$name] as $hook) {
 				// Call a hook to check if this hook call needs to be forked
-				$hookdata = ['name' => $name, 'data' => $data, 'execute' => true];
-
 				if (array_key_exists('hook_fork', self::$hooks)) {
+					$hookdata = ['name' => $name, 'data' => $data, 'execute' => true];
+
 					foreach (self::$hooks['hook_fork'] as $fork_hook) {
 						if ($hook[0] != $fork_hook[0]) {
 							continue;
 						}
 						self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
 					}
-				}
 
-				if (!$hookdata['execute']) {
-					continue;
+					if (!$hookdata['execute']) {
+						continue;
+					}
 				}
 
 				Worker::add($priority, 'ForkHook', $name, $hook, $data);

From 3d8a343ab2f6c40187064e29696a678054df2f7e Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 10 Nov 2018 16:55:12 +0000
Subject: [PATCH 4/4] Added documentation

---
 doc/Addons.md | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/Addons.md b/doc/Addons.md
index 50febf7214..bf139aea7f 100644
--- a/doc/Addons.md
+++ b/doc/Addons.md
@@ -693,6 +693,9 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
 
     Addon::callHooks('logged_in', $a->user);
 
+### src/Core/Hook.php
+
+    self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
 
 ### src/Core/Worker.php