|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Add theme options to customizer |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Flynt\Customizer; |
|
8
|
|
|
|
|
9
|
|
|
use Flynt\Utils\Asset; |
|
10
|
|
|
use Flynt\Utils\Options; |
|
11
|
|
|
use Flynt\Variables; |
|
|
|
|
|
|
12
|
|
|
use Flynt\CSSVariables; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
add_action('acf/init', function () { |
|
15
|
|
|
$options = Options::getGlobal('Customizer'); |
|
16
|
|
|
|
|
17
|
|
|
if ($options['enabled']) { |
|
18
|
|
|
add_action('customize_register', function ($wp_customize) { |
|
19
|
|
|
$wp_customize->register_control_type('Flynt\Customizer\RangeControl'); |
|
20
|
|
|
addSettings($wp_customize); |
|
21
|
|
|
}); |
|
22
|
|
|
|
|
23
|
|
|
add_action('customize_controls_enqueue_scripts', function () { |
|
24
|
|
|
wp_enqueue_script( |
|
25
|
|
|
'Flynt/customizerControls', |
|
26
|
|
|
Asset::requireUrl('assets/customizerControls.js'), |
|
27
|
|
|
['jquery'], |
|
28
|
|
|
null, |
|
29
|
|
|
true |
|
30
|
|
|
); |
|
31
|
|
|
wp_enqueue_style( |
|
32
|
|
|
'Flynt/customizerControls', |
|
33
|
|
|
Asset::requireUrl('assets/customizerControls.css') |
|
34
|
|
|
); |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
add_action('customize_preview_init', function () { |
|
38
|
|
|
wp_enqueue_script( |
|
39
|
|
|
'Flynt/customizerPreview', |
|
40
|
|
|
Asset::requireUrl('assets/customizerPreview.js'), |
|
41
|
|
|
['jquery','customize-preview'] |
|
42
|
|
|
); |
|
43
|
|
|
$fields = CSSVariables\getFields(); |
|
|
|
|
|
|
44
|
|
|
wp_localize_script('Flynt/customizerPreview', 'FlyntCustomizerFields', $fields); |
|
45
|
|
|
}); |
|
46
|
|
|
} |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
function addSettings($wp_customize) |
|
50
|
|
|
{ |
|
51
|
|
|
$settings = Variables\getVariables(); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
foreach ($settings as $setting) { |
|
54
|
|
|
if ($setting['type'] === 'panel') { |
|
55
|
|
|
$wp_customize->add_panel( |
|
56
|
|
|
"flynt_panel_{$setting['name']}", |
|
57
|
|
|
[ |
|
58
|
|
|
'title' => $setting['label'], |
|
59
|
|
|
'priority' => $setting['priority'] ?? 160, |
|
60
|
|
|
] |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
foreach ($setting['sections'] ?? [] as $section) { |
|
64
|
|
|
addSection($wp_customize, $section, $setting['name']); |
|
65
|
|
|
} |
|
66
|
|
|
} else if ($setting['type'] === 'section') { |
|
67
|
|
|
addSection($wp_customize, $setting); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
function addSection($wp_customize, $section, $panel = '') |
|
73
|
|
|
{ |
|
74
|
|
|
$panelKey = $panel ? "{$panel}_" : ''; |
|
75
|
|
|
$sectionKey = "flynt_section_{$panelKey}{$section['name']}"; |
|
76
|
|
|
$wp_customize->add_section( |
|
77
|
|
|
$sectionKey, |
|
78
|
|
|
[ |
|
79
|
|
|
'title' => $section['label'], |
|
80
|
|
|
'priority' => $section['priority'] ?? 160, |
|
81
|
|
|
'panel' => $panel ? "flynt_panel_{$panel}" : '', |
|
82
|
|
|
] |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
foreach ($section['fields'] ?? [] as $setting) { |
|
86
|
|
|
addSetting($wp_customize, $setting, $sectionKey); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function addSetting($wp_customize, $setting, $sectionKey) |
|
91
|
|
|
{ |
|
92
|
|
|
$settingId = $setting['name']; |
|
93
|
|
|
unset($setting['name']); |
|
94
|
|
|
|
|
95
|
|
|
$wp_customize->add_setting( |
|
96
|
|
|
$settingId, |
|
97
|
|
|
[ |
|
98
|
|
|
'default' => $setting['default'], |
|
99
|
|
|
'transport' => 'postMessage', |
|
100
|
|
|
'sanitize_callback' => getSanitizeCallback($setting['type']), |
|
101
|
|
|
] |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$controllClass = getControllCass($setting['type']); |
|
105
|
|
|
|
|
106
|
|
|
$wp_customize->add_control( |
|
107
|
|
|
new $controllClass( |
|
108
|
|
|
$wp_customize, |
|
109
|
|
|
$settingId, |
|
110
|
|
|
array_merge( |
|
111
|
|
|
$setting, |
|
112
|
|
|
[ |
|
113
|
|
|
'section' => $sectionKey, |
|
114
|
|
|
] |
|
115
|
|
|
) |
|
116
|
|
|
) |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
function getControllCass($type) |
|
121
|
|
|
{ |
|
122
|
|
|
$controls = [ |
|
123
|
|
|
'color' => 'WP_Customize_Color_Control', |
|
124
|
|
|
'flynt-range' => 'Flynt\Customizer\RangeControl', |
|
125
|
|
|
]; |
|
126
|
|
|
|
|
127
|
|
|
return $controls[$type] ?? 'WP_Customize_Control'; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
function getSanitizeCallback($type) |
|
131
|
|
|
{ |
|
132
|
|
|
$sanitize = [ |
|
133
|
|
|
'color' => 'sanitize_hex_color', |
|
134
|
|
|
'flynt-range' => 'Flynt\Customizer\sanitizeNumberRange', |
|
135
|
|
|
]; |
|
136
|
|
|
|
|
137
|
|
|
return $sanitize[$type] ?? ''; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
function sanitizeNumberRange($number, $setting) |
|
141
|
|
|
{ |
|
142
|
|
|
$number = absint($number); |
|
143
|
|
|
$options = $setting->manager->get_control($setting->id)->options; |
|
144
|
|
|
|
|
145
|
|
|
$min = $options['min'] ?? $number; |
|
146
|
|
|
$max = $options['max'] ?? $number; |
|
147
|
|
|
$step = $options['step'] ?? 1; |
|
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
if ($min <= $number && $number <= $max) { |
|
150
|
|
|
return $number; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return $setting->default; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
Options::addGlobal('Customizer', [ |
|
157
|
|
|
[ |
|
158
|
|
|
'label' => __('Status', 'flynt'), |
|
159
|
|
|
'name' => 'enabled', |
|
160
|
|
|
'type' => 'true_false', |
|
161
|
|
|
'ui' => 1, |
|
162
|
|
|
'ui_on_text' => 'Enabled', |
|
163
|
|
|
'ui_off_text' => 'Disabled', |
|
164
|
|
|
'default_value' => true, |
|
165
|
|
|
], |
|
166
|
|
|
]); |
|
167
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths