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

Compatibility::removeHook()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 23
ccs 0
cts 16
cp 0
rs 8.4444
cc 8
nc 7
nop 4
crap 72
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