|
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 WP_Customize_Color_Control; |
|
12
|
|
|
use Flynt\Variables; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
add_action('acf/init', function () { |
|
15
|
|
|
$options = Options::getGlobal('Customizer'); |
|
16
|
|
|
if ($options['enabled']) { |
|
17
|
|
|
add_action('customize_register', function ($wp_customize) { |
|
18
|
|
|
$wp_customize->register_control_type('Flynt\Customizer\RangeControl'); |
|
19
|
|
|
|
|
20
|
|
|
addSizesSettings($wp_customize); |
|
21
|
|
|
addColorsSettings($wp_customize); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
add_action('customize_controls_enqueue_scripts', function () { |
|
25
|
|
|
wp_enqueue_script( |
|
26
|
|
|
'Flynt/customizerControls', |
|
27
|
|
|
Asset::requireUrl('assets/customizerControls.js'), |
|
28
|
|
|
['jquery','customize-preview'] |
|
29
|
|
|
); |
|
30
|
|
|
wp_enqueue_style( |
|
31
|
|
|
'Flynt/customizerControls', |
|
32
|
|
|
Asset::requireUrl('assets/customizerControls.css') |
|
33
|
|
|
); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
add_action('customize_preview_init', function () { |
|
37
|
|
|
wp_enqueue_script( |
|
38
|
|
|
'Flynt/customizerPreview', |
|
39
|
|
|
Asset::requireUrl('assets/customizerPreview.js'), |
|
40
|
|
|
['jquery','customize-preview'] |
|
41
|
|
|
); |
|
42
|
|
|
$themes = Variables\getColors(); |
|
|
|
|
|
|
43
|
|
|
$config = array_map(function ($theme) { |
|
44
|
|
|
return $theme['colors']; |
|
45
|
|
|
}, $themes); |
|
46
|
|
|
wp_localize_script('Flynt/customizerPreview', 'FlyntCustomizerData', $config); |
|
47
|
|
|
}); |
|
48
|
|
|
} |
|
49
|
|
|
}); |
|
50
|
|
|
|
|
51
|
|
|
function addSizesSettings($wp_customize) |
|
52
|
|
|
{ |
|
53
|
|
|
$sizes = Variables\getSizes(); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$wp_customize->add_section( |
|
56
|
|
|
"sizes_section", |
|
57
|
|
|
[ |
|
58
|
|
|
'title' => __('Sizes', 'flynt'), |
|
59
|
|
|
'priority' => 150, |
|
60
|
|
|
] |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
foreach ($sizes as $sizeKey => $size) { |
|
64
|
|
|
$sizeKey = str_replace('-', '_', $sizeKey); |
|
65
|
|
|
|
|
66
|
|
|
$wp_customize->add_setting( |
|
67
|
|
|
"size_{$sizeKey}", |
|
68
|
|
|
[ |
|
69
|
|
|
'default' => $size['default'], |
|
70
|
|
|
'transport' => 'postMessage', |
|
71
|
|
|
'sanitize_callback' => "Flynt\\Customizer\\sanitizeNumberRange", |
|
72
|
|
|
] |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$wp_customize->add_control( |
|
76
|
|
|
new RangeControl( |
|
77
|
|
|
$wp_customize, |
|
78
|
|
|
"size_{$sizeKey}", |
|
79
|
|
|
[ |
|
80
|
|
|
'section' => "sizes_section", |
|
81
|
|
|
'label' => $size['label'], |
|
82
|
|
|
'description' => $size['description'] ?? '', |
|
83
|
|
|
'unit' => $size['unit'], |
|
84
|
|
|
'options' => $size['options'], |
|
85
|
|
|
] |
|
86
|
|
|
) |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
function addColorsSettings($wp_customize) |
|
92
|
|
|
{ |
|
93
|
|
|
$themes = Variables\getColors(); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$wp_customize->add_panel( |
|
96
|
|
|
'theme_colors_panel', |
|
97
|
|
|
[ |
|
98
|
|
|
'title' => __('Colors', 'flynt'), |
|
99
|
|
|
'priority' => 160, |
|
100
|
|
|
] |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
foreach ($themes as $key => $theme) { |
|
104
|
|
|
$wp_customize->add_section( |
|
105
|
|
|
"theme_{$key}_colors", |
|
106
|
|
|
[ |
|
107
|
|
|
'title' => $theme['label'], |
|
108
|
|
|
'priority' => 20, |
|
109
|
|
|
'panel' => 'theme_colors_panel', |
|
110
|
|
|
] |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
foreach ($themes as $themeKey => $theme) { |
|
115
|
|
|
foreach ($theme['colors'] as $colorName => $colorConfig) { |
|
116
|
|
|
$wp_customize->add_setting( |
|
117
|
|
|
"theme_{$themeKey}_color_{$colorName}", |
|
118
|
|
|
[ |
|
119
|
|
|
'default' => $colorConfig['default'], |
|
120
|
|
|
'transport' => 'postMessage', |
|
121
|
|
|
'sanitize_callback' => 'sanitize_hex_color', |
|
122
|
|
|
] |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
$wp_customize->add_control( |
|
126
|
|
|
new WP_Customize_Color_Control( |
|
127
|
|
|
$wp_customize, |
|
128
|
|
|
"theme_{$themeKey}_color_{$colorName}", |
|
129
|
|
|
[ |
|
130
|
|
|
'section' => "theme_{$themeKey}_colors", |
|
131
|
|
|
'label' => $colorConfig['label'], |
|
132
|
|
|
'description' => $colorConfig['description'] ?? '', |
|
133
|
|
|
] |
|
134
|
|
|
) |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
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