Total Complexity | 9 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | class Filter { |
||
9 | |||
10 | /** |
||
11 | * Remove active filter from $wp_filter |
||
12 | * |
||
13 | * @param string $hook Hook on which the original filter was applied. |
||
14 | * @param string $class Classname. |
||
15 | * @param string $method Method. |
||
16 | * |
||
17 | * @SuppressWarnings(PHPMD.Superglobals) Don't worry, I know what I'm doing. |
||
18 | * @return boolean |
||
19 | */ |
||
20 | public static function remove(string $hook, string $class, string $method): bool { |
||
21 | if (array_key_exists($hook, $GLOBALS['wp_filter']) === true) { |
||
22 | $filters = $GLOBALS['wp_filter'][$hook]; |
||
23 | } else { |
||
24 | return false; |
||
25 | } |
||
26 | $return = false; |
||
27 | foreach ($filters as $priority => $filter) { |
||
28 | foreach ($filter as $function) { |
||
29 | if (self::isFilterFunctionClass($function, $class, $method) === true) { |
||
30 | $return = remove_filter( |
||
31 | $hook, |
||
32 | [ |
||
33 | $function['function'][0], |
||
34 | $method, |
||
35 | ], |
||
36 | $priority |
||
37 | ); |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | return $return; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Checks whether a filter contains the supplied Class and Function |
||
47 | * |
||
48 | * @param array $function The original filter from $wp_filter. |
||
49 | * @param string $class The class in which the method should be called. |
||
50 | * @param string $method The method to check for. |
||
51 | * |
||
52 | * @return boolean |
||
53 | */ |
||
54 | private static function isFilterFunctionClass(array $function, string $class, string $method): bool { |
||
60 | } |
||
61 | } |
||
62 |