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