fluent-booking
/
vendor
/
wpfluent
/
framework
/
src
/
WPFluent
/
Foundation
/
Concerns
/
HooksRemovalTrait.php
HooksRemovalTrait.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.3.0, at vendor/wpfluent/framework/src/WPFluent/Foundation/Concerns/HooksRemovalTrait.php
| 1 | <?php |
| 2 | |
| 3 | namespace FluentBooking\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 |