|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Framework\Theme\Module\Abstracts; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Framework\Module\Abstracts\Module; |
|
6
|
|
|
use Leonidas\Hooks\TargetsAfterSetupThemeHook; |
|
7
|
|
|
|
|
8
|
|
|
abstract class ThemeFeaturesModule extends Module |
|
9
|
|
|
{ |
|
10
|
|
|
use TargetsAfterSetupThemeHook; |
|
11
|
|
|
|
|
12
|
|
|
public const IN_CORE = [ |
|
13
|
|
|
'post-thumbnails', |
|
14
|
|
|
'post-formats', |
|
15
|
|
|
'html5', |
|
16
|
|
|
'custom-logo', |
|
17
|
|
|
'custom-header', |
|
18
|
|
|
'custom-background', |
|
19
|
|
|
'title-tag', |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
public const CORE_DISABLE = [ |
|
23
|
|
|
'disable-custom-colors', |
|
24
|
|
|
'disable-custom-gradients', |
|
25
|
|
|
'disable-custom-font-sizes', |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
public const CORE_BOOL = [ |
|
29
|
|
|
'automatic-feed-links', |
|
30
|
|
|
'custom-background', |
|
31
|
|
|
'custom-header', |
|
32
|
|
|
'custom-logo', |
|
33
|
|
|
'post-thumbnails', |
|
34
|
|
|
'title-tag', |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
public const CORE_BASE = [ |
|
38
|
|
|
'custom-background', |
|
39
|
|
|
'custom-header', |
|
40
|
|
|
'custom-logo', |
|
41
|
|
|
'html5', |
|
42
|
|
|
'post-formats', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
public const CORE_LIST = []; |
|
46
|
|
|
|
|
47
|
|
|
public const EXTRA_BOOL = []; |
|
48
|
|
|
|
|
49
|
|
|
public const EXTRA_BASE = []; |
|
50
|
|
|
|
|
51
|
|
|
public const EXTRA_LIST = []; |
|
52
|
|
|
|
|
53
|
|
|
public function hook(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->targetAfterSetupThemeHook(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function defineAfterSetUpThemePriority(): ?int |
|
59
|
|
|
{ |
|
60
|
|
|
return PHP_INT_MAX; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function doAfterSetupThemeAction(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->addThemeFeatures(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function addThemeFeatures(): void |
|
69
|
|
|
{ |
|
70
|
|
|
foreach ($this->features() as $feature => $args) { |
|
71
|
|
|
if ($this->isSupportedBoolFeature($feature, $args)) { |
|
72
|
|
|
add_theme_support($feature); |
|
|
|
|
|
|
73
|
|
|
} elseif ($this->isSupportedBaseFeature($feature, $args)) { |
|
74
|
|
|
add_theme_support($feature, $args); |
|
75
|
|
|
} elseif ($this->isSupportedListFeature($feature, $args)) { |
|
76
|
|
|
add_theme_support($feature, ...is_array($args) ? $args : [$args]); |
|
77
|
|
|
} elseif ($this->isDisabledFeature($feature, $args)) { |
|
78
|
|
|
remove_theme_support($feature); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
protected function isSupportedBoolFeature(string $feature, $args) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
return true === $args; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function isSupportedBaseFeature(string $feature, $args) |
|
89
|
|
|
{ |
|
90
|
|
|
return !in_array($feature, $this->getVariadicFeatures()) |
|
91
|
|
|
&& !is_bool($args); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
protected function isSupportedListFeature(string $feature, $args) |
|
95
|
|
|
{ |
|
96
|
|
|
return in_array($feature, $this->getVariadicFeatures()) |
|
97
|
|
|
&& !is_bool($args); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
protected function isDisabledFeature(string $feature, $args) |
|
101
|
|
|
{ |
|
102
|
|
|
return current_theme_supports($feature) && false === $args; |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getVariadicFeatures(): array |
|
106
|
|
|
{ |
|
107
|
|
|
return array_merge(static::CORE_LIST, static::EXTRA_LIST); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
abstract protected function features(): array; |
|
111
|
|
|
} |
|
112
|
|
|
|