PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.8.1
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.8.1
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Foundation / Concerns / HooksRemovalTrait.php

HooksRemovalTrait.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.8.1, at vendor/wpfluent/framework/src/WPFluent/Foundation/Concerns/HooksRemovalTrait.php

137 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Foundation\Concerns;
4
5 trait HooksRemovalTrait
6 {
7 /**
8 * Remove filters/Actions
9 *
10 * @param string $action
11 * @param string $class
12 * @param string $method
13 * @param integer $priority
14 * @return bool
15 */
16 public function removeFilter($action, $class = '', $method = '', $priority = 10)
17 {
18 if (is_string($class) && function_exists($class)) {
19 return remove_filter(
20 $action, $class, is_numeric($method) ? $method : $priority
21 );
22 }
23
24 $class = is_object($class) ? get_class($class) : $class;
25
26 if (!str_contains($class, 'class@anonymous')) {
27
28 if (str_contains($class, '@') === false && is_string($method)) {
29 $class = $class . '@' . $method;
30 }
31
32 $handler = $this->parseHookHandler($class);
33
34 } else {
35 $object = $this->make($class);
36 $handler = [$object, $method];
37 }
38
39 return $this->removeHook(
40 $action,
41 get_class($handler[0]),
42 $handler[1],
43 is_numeric($method) ? $method : $priority
44 );
45 }
46
47 /**
48 * Remove filters/Actions
49 *
50 * @param string $action
51 * @param string $class
52 * @param string $method
53 * @param integer $priority
54 * @return bool
55 */
56 public function removeAction($action, $class = '', $method = '', $priority = 10)
57 {
58 return $this->removeFilter($action, $class, $method, $priority);
59 }
60
61 /**
62 * Remove filters/Actions
63 *
64 * @param string $action
65 * @param string $class
66 * @param string $method
67 * @param integer $priority
68 * @return bool
69 */
70 public function removeCustomFilter($action, $class = '', $method = '', $priority = 10)
71 {
72 $prefix = $this->config->get('app.hook_prefix');
73
74 return $this->removeFilter(
75 $this->hook($prefix, $action), $class, $method, $priority
76 );
77 }
78
79 /**
80 * Remove filters/Actions
81 *
82 * @param string $action
83 * @param string $class
84 * @param string $method
85 * @param integer $priority
86 * @return bool
87 */
88 public function removeCustomAction($action, $class = '', $method = '', $priority = 10)
89 {
90 $prefix = $this->config->get('app.hook_prefix');
91
92 return $this->removeAction(
93 $this->hook($prefix, $action), $class, $method, $priority
94 );
95 }
96
97 /**
98 * Remove filters/Actions
99 *
100 * @param string $action
101 * @param string $class
102 * @param string $method
103 * @param integer $priority
104 * @return bool
105 */
106 private function removeHook($action, $class, $method, $priority)
107 {
108 global $wp_filter;
109
110 $isHookRemoved = false;
111
112 if (empty($wp_filter[$action]->callbacks[$priority])) {
113 return $isHookRemoved;
114 }
115
116 $methods = array_filter(wp_list_pluck(
117 $wp_filter[$action]->callbacks[$priority], 'function'
118 ), function ($method) {
119 return is_string($method) || is_array($method);
120 });
121
122 $foundHooks = !empty($methods) ? wp_list_filter($methods, [1 => $method]) : [];
123
124 foreach($foundHooks as $hook) {
125
126 if (!empty($hook[0]) && is_object($hook[0]) && get_class($hook[0]) === $class) {
127
128 $wp_filter[$action]->remove_filter($action, $hook, $priority);
129
130 $isHookRemoved = true;
131 }
132 }
133
134 return $isHookRemoved;
135 }
136 }
137