1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Output CSS variables in head before the main stylesheet. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Flynt\CSSVariables; |
8
|
|
|
|
9
|
|
|
use Flynt\Variables; |
|
|
|
|
10
|
|
|
use Flynt\Utils\ColorHelpers; |
11
|
|
|
|
12
|
|
|
add_action('wp_head', function () { |
13
|
|
|
$variables = getCssVariables(); |
14
|
|
|
?> |
15
|
|
|
<style type="text/css"> |
16
|
|
|
:root.html { |
17
|
|
|
<?php foreach ($variables as $variable => $value) { |
18
|
|
|
echo "--{$variable}: {$value}; "; |
19
|
|
|
} ?> |
20
|
|
|
} |
21
|
|
|
</style> |
22
|
|
|
<?php |
23
|
|
|
}, 5); |
24
|
|
|
|
25
|
|
|
function getCssVariables() |
26
|
|
|
{ |
27
|
|
|
$fields = getFields(); |
28
|
|
|
$variables = []; |
29
|
|
|
|
30
|
|
|
foreach ($fields as $field) { |
31
|
|
|
$variable = $field['name']; |
32
|
|
|
$value = get_theme_mod($field['name'], $field['default']); |
33
|
|
|
$unit = $field['unit'] ?? ''; |
34
|
|
|
$variables[$variable] = $value . $unit; |
35
|
|
|
|
36
|
|
|
if (isset($field['hsl']) && $field['type'] === 'color') { |
37
|
|
|
$hslCssVariables = generateHslaCssVariables($field, $value); |
38
|
|
|
foreach ($hslCssVariables as $variable => $value) { |
39
|
|
|
$variables[$variable] = $value; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $variables; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function getFields() |
48
|
|
|
{ |
49
|
|
|
$settings = Variables\getVariables(); |
|
|
|
|
50
|
|
|
$fields = []; |
51
|
|
|
|
52
|
|
|
foreach ($settings as $setting) { |
53
|
|
|
if ($setting['type'] === 'panel') { |
54
|
|
|
foreach ($setting['sections'] ?? [] as $section) { |
55
|
|
|
$fields = array_merge($section['fields'] ?? [], $fields); |
56
|
|
|
} |
57
|
|
|
} else if ($setting['type'] === 'section') { |
58
|
|
|
$fields = array_merge($setting['fields'] ?? [], $fields); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $fields; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function generateHslaCssVariables($field, $value) |
66
|
|
|
{ |
67
|
|
|
$colorHsla = ColorHelpers::hexToHsla($value); |
68
|
|
|
return [ |
69
|
|
|
"{$field['name']}-h" => $colorHsla[0], |
70
|
|
|
"{$field['name']}-s" => $colorHsla[1], |
71
|
|
|
"{$field['name']}-l" => $colorHsla[2], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
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