Passed
Push — main ( 72ff1c...f45cd4 )
by Paul
05:18
created

Compatibility   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 16
c 1
b 0
f 1
dl 0
loc 25
ccs 0
cts 16
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B removeHook() 0 23 8
1
<?php
2
3
namespace GeminiLabs\SiteReviews;
4
5
class Compatibility
6
{
7
    public function removeHook(string $hook, string $fn, string $className, int $priority = 10): bool
8
    {
9
        global $wp_filter;
10
        if (!isset($wp_filter[$hook])) {
11
            return false;
12
        }
13
        if (!isset($wp_filter[$hook]->callbacks[$priority])) {
14
            return false;
15
        }
16
        foreach ($wp_filter[$hook]->callbacks[$priority] as $callback) {
17
            if (!isset($callback['function'][0]) || !isset($callback['function'][1])) {
18
                continue;
19
            }
20
            if (!is_a($callback['function'][0], $className)) {
21
                continue;
22
            }
23
            if ($fn !== $callback['function'][1]) {
24
                continue;
25
            }
26
            remove_filter($hook, [$callback['function'][0], $fn], $priority);
27
            return true;
28
        }
29
        return false;
30
    }
31
}
32