PluginProbe
BlockArt Blocks – Gutenberg Blocks, Page Builder Blocks ,WordPress Block Plugin, Sections & Template Library / trunk
BlockArt Blocks – Gutenberg Blocks, Page Builder Blocks ,WordPress Block Plugin, Sections & Template Library vtrunk
2.4.1 2.0.0 2.0.0.1 2.0.1 2.0.10 2.0.11 2.0.2 2.0.3 2.0.4 2.0.5 2.0.5.1 2.0.5.2 2.0.6 2.0.7 2.0.7.1 2.0.7.2 2.0.7.3 2.0.7.4 2.0.7.5 2.0.8 2.0.9 2.0.9.1 2.1.0 2.1.1 2.1.2 All 69 releases
blockart-blocks / includes / Setting.php

Setting.php in BlockArt Blocks – Gutenberg Blocks, Page Builder Blocks ,WordPress Block Plugin, Sections & Template Library trunk, at includes/Setting.php

361 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Setting API class.
4 *
5 * @package BlockArt
6 */
7
8 namespace BlockArt;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Setting class.
14 */
15 class Setting {
16
17 /**
18 * Default data.
19 *
20 * @var array
21 */
22 private static $data = array(
23 'blocks' => array(
24 'advertisement' => true,
25 'banner-posts' => true,
26 'breadcrumbs' => true,
27 'category-list' => true,
28 'chart' => true,
29 'date-weather' => true,
30 'featured-posts' => true,
31 'featured-categories' => true,
32 'grid-module' => true,
33 'heading' => true,
34 'icon' => true,
35 'image' => true,
36 'latest-posts' => true,
37 'modal' => true,
38 'news-ticker' => true,
39 'post-list' => true,
40 'post-video' => true,
41 'section' => true,
42 'slider' => true,
43 'social-icons' => true,
44 'split-content' => true,
45 'tab-post' => true,
46 'video-scrolling' => true,
47 'video-popup' => true,
48 'button' => true,
49 'paragraph' => true,
50 'spacing' => true,
51 'socials' => true,
52 'tabs' => true,
53 'toc' => true,
54 'counter' => true,
55 'lottie' => true,
56 'team' => true,
57 'countdown' => true,
58 'info' => true,
59 'blockquote' => true,
60 'timeline' => true,
61 'notice' => true,
62 'progress' => true,
63 'call-to-action' => true,
64 'map' => true,
65 'testimonial' => true,
66 'imageComparison' => true,
67 'faq' => true,
68 'price-list' => true,
69 'image-gallery' => true,
70 'icon-list' => true,
71 'query-loop' => true,
72 'image-comparison' => true,
73 ),
74 'editor' => array(
75 'section-width' => 1170,
76 'editor-blocks-spacing' => 24,
77 'design-library' => true,
78 'responsive-breakpoints' => array(
79 'tablet' => 992,
80 'mobile' => 768,
81 ),
82 'copy-paste-styles' => true,
83 'auto-collapse-panels' => true,
84 ),
85 'performance' => array(
86 'local-google-fonts' => false,
87 'preload-local-fonts' => false,
88 'allow-only-selected-fonts' => false,
89 'allowed-fonts' => array(),
90 ),
91 'asset-generation' => array(
92 'external-file' => false,
93 ),
94 'version-control' => array(
95 'beta-tester' => false,
96 ),
97 'maintenance-mode' => array(
98 'mode' => 'none',
99 'maintenance-page' => null,
100 ),
101 'integrations' => array(
102 'google-maps-embed-api-key' => '',
103 ),
104 'global-styles' => '',
105 );
106
107 /**
108 * Sanitize callbacks.
109 *
110 * @var array
111 */
112 private static $sanitize_callbacks = array(
113 'blocks' => array(
114 'section' => 'blockart_string_to_bool',
115 'heading' => 'blockart_string_to_bool',
116 'paragraph' => 'blockart_string_to_bool',
117 'button' => 'blockart_string_to_bool',
118 'image' => 'blockart_string_to_bool',
119 'spacing' => 'blockart_string_to_bool',
120 'socials' => 'blockart_string_to_bool',
121 'tabs' => 'blockart_string_to_bool',
122 'toc' => 'blockart_string_to_bool',
123 'counter' => 'blockart_string_to_bool',
124 'lottie' => 'blockart_string_to_bool',
125 'team' => 'blockart_string_to_bool',
126 'countdown' => 'blockart_string_to_bool',
127 'info' => 'blockart_string_to_bool',
128 'blockquote' => 'blockart_string_to_bool',
129 'timeline' => 'blockart_string_to_bool',
130 'notice' => 'blockart_string_to_bool',
131 'progress' => 'blockart_string_to_bool',
132 'call-to-action' => 'blockart_string_to_bool',
133 'slider' => 'blockart_string_to_bool',
134 'map' => 'blockart_string_to_bool',
135 'testimonial' => 'blockart_string_to_bool',
136 'imageComparison' => 'blockart_string_to_bool',
137 'faq' => 'blockart_string_to_bool',
138 'image-gallery' => 'blockart_string_to_bool',
139 'price-list' => 'blockart_string_to_bool',
140 'icon-list' => 'blockart_string_to_bool',
141 'query-loop' => 'blockart_string_to_bool',
142 'image-comparison' => 'blockart_string_to_bool',
143 ),
144 'editor' => array(
145 'section-width' => 'absint',
146 'editor-blocks-spacing' => 'absint',
147 'design-library' => 'blockart_string_to_bool',
148 'copy-paste-styles' => 'blockart_string_to_bool',
149 'auto-collapse-panels' => 'blockart_string_to_bool',
150 'responsive-breakpoints' => array(
151 'tablet' => 'absint',
152 'mobile' => 'absint',
153 ),
154 ),
155 'performance' => array(
156 'local-google-fonts' => 'blockart_string_to_bool',
157 'preload-local-fonts' => 'blockart_string_to_bool',
158 'allow-only-selected-fonts' => 'blockart_string_to_bool',
159 ),
160 'asset-generation' => array(
161 'external-file' => 'blockart_string_to_bool',
162 ),
163 'version-control' => array(
164
165 'beta-tester' => 'blockart_string_to_bool',
166 ),
167 'integrations' => array(
168 'google-maps-embed-api-key' => 'sanitize_text_field',
169 ),
170 'maintenance-mode' => array(
171 'mode' => 'sanitize_text_field',
172 'maintenance-page' => array(
173 'id' => 'absint',
174 'title' => 'sanitize_text_field',
175 ),
176 ),
177 );
178
179 /**
180 * Undocumented function
181 *
182 * @return void
183 */
184 public static function read() {
185 self::set_default_global_styles();
186 self::$data = apply_filters( 'blockart_default_settings', self::$data );
187 $settings = get_option( '_blockart_settings', self::$data );
188 self::$data = blockart_parse_args( $settings, self::$data );
189 return self::$data;
190 }
191
192 /**
193 * Get all data.
194 *
195 * @return array
196 */
197 public static function all() {
198 return self::read();
199 }
200
201 /**
202 * Get setting.
203 *
204 * @param string $key
205 * @param mixed $default_value
206 * @return mixed
207 */
208 public static function get( $key, $default_value = null ) {
209 self::read();
210 return blockart_array_get( self::$data, $key, $default_value );
211 }
212
213 /**
214 * Set multiple data.
215 *
216 * @param array $data
217 * @return void
218 */
219 public static function set_data( $data ) {
220 $data = blockart_array_dot( $data );
221 array_walk(
222 $data,
223 function ( &$value, $key ) {
224 $value = self::sanitize( $key, $value );
225 }
226 );
227 $data = blockart_array_undot( $data );
228 self::$data = blockart_parse_args( $data, self::$data );
229 }
230
231 /**
232 * Set default global styles.
233 *
234 * @return void
235 */
236 private static function set_default_global_styles() {
237 $styles = array(
238 'colors' => array(
239 array(
240 'id' => 'primary',
241 'name' => 'Primary',
242 'value' => '#2563eb',
243 ),
244 array(
245 'id' => 'secondary',
246 'name' => 'Secondary',
247 'value' => '#54595F',
248 ),
249 array(
250 'id' => 'text',
251 'name' => 'Text',
252 'value' => '#7A7A7A',
253 ),
254 array(
255 'id' => 'accent',
256 'name' => 'Accent',
257 'value' => '#61CE70',
258 ),
259 ),
260 'typographies' => array(
261 array(
262 'id' => 'primary',
263 'name' => 'Primary',
264 'value' => array(
265 'fontFamily' => 'Default',
266 'weight' => 600,
267 ),
268 ),
269 array(
270 'id' => 'secondary',
271 'name' => 'Secondary',
272 'value' => array(
273 'fontFamily' => 'Default',
274 'weight' => 400,
275 ),
276 ),
277 array(
278 'id' => 'text',
279 'name' => 'Text',
280 'value' => array(
281 'fontFamily' => 'Default',
282 'weight' => 600,
283 ),
284 ),
285 array(
286 'id' => 'accent',
287 'name' => 'Accent',
288 'value' => array(
289 'fontFamily' => 'Default',
290 'weight' => 500,
291 ),
292 ),
293 ),
294 );
295 self::$data['global-styles'] = wp_json_encode( $styles );
296 }
297
298 /**
299 * Set setting data.
300 *
301 * @param string $key Key to set.
302 * @param mixed $value Value to set.
303 * @return void
304 */
305 public static function set( $key, $value ) {
306 $value = self::sanitize( $key, $value );
307 self::$data = blockart_array_set( self::$data, $key, $value );
308 }
309
310 /**
311 * Sanitize value.
312 *
313 * @param string $key Key to sanitize.
314 * @param mixed $value Value to sanitize.
315 * @return mixed Sanitized value.
316 */
317 private static function sanitize( $key, $value ) {
318 $sanitize_callback = blockart_array_get(
319 (array) apply_filters(
320 'blockart_setting_sanitize_callbacks',
321 self::$sanitize_callbacks
322 ),
323 $key
324 );
325 if ( is_callable( $sanitize_callback ) || ( is_string( $sanitize_callback ) && function_exists( $sanitize_callback ) ) ) {
326 return call_user_func_array( $sanitize_callback, array( $value ) );
327 }
328 return $value;
329 }
330
331 /**
332 * Save setting data after sanitization.
333 *
334 * @return void
335 */
336 public static function save() {
337 self::watch_responsive_breakpoints();
338 update_option( '_blockart_settings', self::$data );
339 }
340
341 /**
342 * Watch responsive breakpoints.
343 *
344 * @return void
345 */
346 private static function watch_responsive_breakpoints() {
347 $new_breakpoints = blockart_array_get( self::$data, 'editor.responsive-breakpoints', array() );
348 $old_breakpoints = wp_parse_args(
349 blockart_array_get( get_option( '_blockart_settings', array() ), 'editor.responsive-breakpoints', array() ),
350 blockart_array_get( self::$data, 'editor.responsive-breakpoints', array() )
351 );
352
353 ksort( $new_breakpoints );
354 ksort( $old_breakpoints );
355
356 if ( $new_breakpoints !== $old_breakpoints ) {
357 do_action( 'blockart_responsive_breakpoints_changed', $new_breakpoints, $old_breakpoints );
358 }
359 }
360 }
361