Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/helpers/dynamic-css.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
function blocksy_has_css_in_files() {
4
+
return apply_filters('blocksy:dynamic-css:has_files_cache', false);
5
+
}
6
+
7
+
function blocksy_get_all_dynamic_styles_for($args = []) {
8
+
$args = wp_parse_args(
9
+
$args,
10
+
[
11
+
'context' => null,
12
+
'fonts_manager' => null
13
+
]
14
+
);
15
+
16
+
$css = new Blocksy_Css_Injector([
17
+
'fonts_manager' => $args['fonts_manager']
18
+
]);
19
+
$mobile_css = new Blocksy_Css_Injector([
20
+
'fonts_manager' => $args['fonts_manager']
21
+
]);
22
+
$tablet_css = new Blocksy_Css_Injector([
23
+
'fonts_manager' => $args['fonts_manager']
24
+
]);
25
+
26
+
blocksy_theme_get_dynamic_styles([
27
+
'name' => 'global',
28
+
'css' => $css,
29
+
'mobile_css' => $mobile_css,
30
+
'tablet_css' => $tablet_css,
31
+
'context' => $args['context'],
32
+
'chunk' => 'global',
33
+
'forced_call' => true
34
+
]);
35
+
36
+
do_action(
37
+
'blocksy:global-dynamic-css:enqueue',
38
+
[
39
+
'context' => $args['context'],
40
+
'css' => $css,
41
+
'tablet_css' => $tablet_css,
42
+
'mobile_css' => $mobile_css
43
+
]
44
+
);
45
+
46
+
return [
47
+
'css' => $css,
48
+
'tablet_css' => $tablet_css,
49
+
'mobile_css' => $mobile_css
50
+
];
51
+
}
52
+
53
+
function blocksy_get_dynamic_css_file_content($args = []) {
54
+
$args = wp_parse_args(
55
+
$args,
56
+
[
57
+
'context' => null,
58
+
]
59
+
);
60
+
61
+
$css_output = blocksy_get_all_dynamic_styles_for([
62
+
'context' => $args['context']
63
+
]);
64
+
65
+
$css = $css_output['css'];
66
+
$tablet_css = $css_output['tablet_css'];
67
+
$mobile_css = $css_output['mobile_css'];
68
+
69
+
// $content = "/* Desktop CSS */";
70
+
$content = '';
71
+
$content .= trim($css->build_css_structure());
72
+
73
+
// $content .= "\n\n/* Tablet CSS */\n";
74
+
$content .= "@media (max-width: 999.98px) {";
75
+
$content .= " " . trim($tablet_css->build_css_structure());
76
+
$content .= "}";
77
+
78
+
// $content .= "\n\n/* Mobile CSS */\n";
79
+
$content .= "@media (max-width: 689.98px) {";
80
+
$content .= trim($mobile_css->build_css_structure());
81
+
$content .= "}";
82
+
83
+
return $content;
84
+
}
85
+
86
+
function blocksy_dynamic_styles_should_call($args = []) {
87
+
$args = wp_parse_args(
88
+
$args,
89
+
[
90
+
'context' => null,
91
+
'chunk' => null,
92
+
'forced_call' => false
93
+
]
94
+
);
95
+
96
+
if (! $args['context']) {
97
+
throw new Error('$context not provided. This is required!');
98
+
}
99
+
100
+
if (! $args['chunk']) {
101
+
throw new Error('$chunk not provided. This is required!');
102
+
}
103
+
104
+
if (! $args['forced_call'] && blocksy_has_css_in_files()) {
105
+
if ($args['context'] === 'inline') {
106
+
if ($args['chunk'] === 'global' || $args['chunk'] === 'woocommerce') {
107
+
return false;
108
+
}
109
+
}
110
+
111
+
if ($args['context'] === 'files:global') {
112
+
if ($args['chunk'] === 'woocommerce') {
113
+
if (! class_exists('WooCommerce')) {
114
+
return false;
115
+
}
116
+
} else {
117
+
if ($args['chunk'] !== 'global') {
118
+
return false;
119
+
}
120
+
}
121
+
}
122
+
}
123
+
124
+
return true;
125
+
}
126
+
127
+
/**
128
+
* Evaluate a file with dynamic styles.
129
+
*
130
+
* @param string $name Name of dynamic CSS file.
131
+
* @param array $variables list of data to pass in file.
132
+
* @throws Error When $css not provided.
133
+
*/
134
+
function blocksy_theme_get_dynamic_styles($args = []) {
135
+
$args = wp_parse_args(
136
+
$args,
137
+
[
138
+
'path' => null,
139
+
'name' => '',
140
+
'css' => null,
141
+
142
+
'context' => null,
143
+
'chunk' => null,
144
+
'forced_call' => false,
145
+
'prefixes' => null
146
+
]
147
+
);
148
+
149
+
if (! isset($args['css'])) {
150
+
throw new Error('$css instance not provided. This is required!');
151
+
}
152
+
153
+
if (! blocksy_dynamic_styles_should_call($args)) {
154
+
return;
155
+
}
156
+
157
+
if (! $args['path']) {
158
+
$args['path'] = get_template_directory() . '/inc/dynamic-styles/' . $args['name'] . '.php';
159
+
}
160
+
161
+
if (! $args['prefixes']) {
162
+
blocksy_get_variables_from_file($args['path'], [], $args);
163
+
} else {
164
+
foreach ($args['prefixes'] as $prefix) {
165
+
blocksy_get_variables_from_file(
166
+
$args['path'],
167
+
[],
168
+
array_merge($args, [
169
+
'prefix' => $prefix
170
+
])
171
+
);
172
+
}
173
+
}
174
+
}
175
+
176
+
function blocksy_has_dynamic_css_in_frontend() {
177
+
$is_site_preview = isset($_REQUEST['wp_site_preview']);
178
+
179
+
// wp_site_preview is a special IFRAME_REQUEST.
180
+
// It is placed in the new Appearanca -> Design view for classic themes.
181
+
if ($is_site_preview) {
182
+
return true;
183
+
}
184
+
185
+
if (defined('IFRAME_REQUEST') && IFRAME_REQUEST) {
186
+
return false;
187
+
}
188
+
189
+
return true;
190
+
}
191
+
192
+