Test Failed
Push — master ( 0b650e...b4d0bc )
by Chris
19:25
created

LinkManager::enabledLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Leonidas\Framework\Site\Module;
4
5
use Leonidas\Framework\Module\Abstracts\Module;
6
use Leonidas\Hooks\TargetsInitHook;
7
8
class LinkManager extends Module
9
{
10
    use TargetsInitHook;
11
12
    public function hook(): void
13
    {
14
        $this->targetInitHook();
15
    }
16
17
    protected function doInitAction(): void
18
    {
19
        $enabled = $this->enabledLinks();
20
21
        foreach ($this->links() as $link => $args) {
22
            if (!in_array($link, $enabled)) {
23
                $callback = $args[0];
24
                $priority = $args[1] ?? HOOK_DEFAULT_PRIORITY;
25
26
                remove_action('wp_head', $callback, $priority);
27
            }
28
        }
29
    }
30
31
    protected function links(): array
32
    {
33
        return [
34
            'adjacent_posts' => ['adjacent_posts_rel_link_wp_head'],
35
            'canonical' => ['rel_canonical'],
36
            'generator' => ['wp_generator'],
37
            'rsd' => ['rsd_link'],
38
            'shortlink' => ['wp_shortlink_wp_head'],
39
            'wlwmanifest' => ['wlwmanifest_link'],
40
        ];
41
    }
42
43
    protected function enabledLinks(): array
44
    {
45
        return $this->getConfig('view.links', []);
46
    }
47
}
48