PluginProbe
Site Reviews / trunk
Site Reviews vtrunk
8.3.1 8.3.0 8.2.2 8.2.1 8.2.0 8.1.0 8.0.13 8.0.12 8.0.11 trunk 1.2.2 2.17.1 3.5.4 4.7.0 5.25.1 6.11.8 7.0.10 7.0.11 7.0.12 7.0.13 7.0.14 7.0.15 7.0.16 7.0.17 7.0.18 All 54 releases
site-reviews / plugin / Compatibility.php

Compatibility.php in Site Reviews trunk, at plugin/Compatibility.php

49 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace GeminiLabs\SiteReviews;
4
5 use GeminiLabs\SiteReviews\Helpers\Arr;
6
7 class Compatibility
8 {
9 public function findCallback(string $hook, string $fn, string $className, int $priority = 10): array
10 {
11 global $wp_filter;
12 if (!isset($wp_filter[$hook])) {
13 return [];
14 }
15 if (!isset($wp_filter[$hook]->callbacks[$priority])) {
16 return [];
17 }
18 foreach ($wp_filter[$hook]->callbacks[$priority] as $callback) {
19 $callbackFn = [];
20 $function = $callback['function'] ?? null;
21 if (is_a($function, 'Closure')) {
22 $ref = new \ReflectionFunction($function);
23 $callbackFn = Arr::getAs('array', $ref->getStaticVariables(), 'callback');
24 } elseif (is_array($function)) {
25 $callbackFn = $function;
26 }
27 if (2 !== count($callbackFn)) {
28 continue;
29 }
30 list($object, $method) = $callbackFn;
31 if (!is_a($object, $className) || $method !== $fn) {
32 continue;
33 }
34 return $callback;
35 }
36 return [];
37 }
38
39 public function removeHook(string $hook, string $fn, string $className, int $priority = 10): bool
40 {
41 $callback = $this->findCallback($hook, $fn, $className, $priority);
42 if (!empty($callback['function'])) {
43 remove_filter($hook, $callback['function'], $priority);
44 return true;
45 }
46 return false;
47 }
48 }
49