PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.1
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.1
4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Utils / Hooks.php
wp-staging / Framework / Utils Last commit date
Cache 1 week ago DBPermissions.php 1 week ago DataEncoder.php 1 week ago DatabaseOptions.php 1 week ago Env.php 1 week ago Escape.php 1 week ago Glob.php 1 week ago Hooks.php 1 week ago Math.php 6 days ago PluginInfo.php 1 week ago Sanitize.php 1 week ago ServerVars.php 1 week ago SlashMode.php 1 week ago Strings.php 1 week ago Times.php 1 week ago Urls.php 1 week ago Version.php 1 week ago WpDefaultDirectories.php 1 week ago
Hooks.php
123 lines
1 <?php
2
3 namespace WPStaging\Framework\Utils;
4
5
6
7
8 class Hooks
9 {
10
11
12
13 private $internalHooks;
14
15
16
17
18
19
20 public function registerInternalHook(string $hookName, $callback)
21 {
22 if (!is_callable($callback)) {
23 return;
24 }
25
26 if (isset($this->internalHooks[$hookName])) {
27 $this->unregisterInternalHook($hookName);
28 }
29
30 $this->internalHooks[$hookName] = $callback;
31 }
32
33
34
35
36
37 public function unregisterInternalHook(string $hookName)
38 {
39 if (isset($this->internalHooks[$hookName])) {
40 unset($this->internalHooks[$hookName]);
41 }
42 }
43
44
45
46
47
48
49
50 public function callInternalHook(string $hookName, array $args = [], $defaultValue = null)
51 {
52 if (isset($this->internalHooks[$hookName]) && is_callable($this->internalHooks[$hookName])) {
53 return call_user_func_array($this->internalHooks[$hookName], $args);
54 }
55
56 return $defaultValue;
57 }
58
59
60
61
62
63
64 public function doAction(string $hookName, ...$args)
65 {
66 if (!function_exists('do_action') || !$this->isHookAllowed($hookName)) {
67 return;
68 }
69
70 do_action($hookName, ...$args);
71 }
72
73
74
75
76
77
78
79 public function applyFilters(string $hookName, $value, ...$args)
80 {
81 if (!function_exists('apply_filters') || !$this->isHookAllowed($hookName)) {
82 return $value;
83 }
84
85 return apply_filters($hookName, $value, ...$args);
86 }
87
88
89
90
91
92 private function isHookAllowed(string $hookName): bool
93 {
94 if (!$this->isWpstgHook($hookName)) {
95 return false;
96 }
97
98
99 if (strpos($hookName, 'wpstg.tests.') === 0 && !$this->isTest()) {
100 return false;
101 }
102
103 return true;
104 }
105
106
107
108
109
110 private function isWpstgHook(string $hookName): bool
111 {
112 return strpos($hookName, 'wpstg.') === 0 || strpos($hookName, 'wpstg_') === 0;
113 }
114
115
116
117
118 protected function isTest(): bool
119 {
120 return defined('WPSTG_TEST') && constant('WPSTG_TEST') === true;
121 }
122 }
123