PluginProbe
Customify / 2.0.2
Customify v2.0.2
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
customify / includes / class-customify-font-palettes.php

class-customify-font-palettes.php in Customify 2.0.2, at includes/class-customify-font-palettes.php

1,474 lines 47.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This is the class that handles the logic for Font Palettes.
4 *
5 * @see https://pixelgrade.com
6 * @author Pixelgrade
7 * @since 1.7.4
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly
12 }
13
14 if ( ! class_exists( 'Customify_Font_Palettes' ) ) :
15
16 class Customify_Font_Palettes {
17
18 /**
19 * Holds the only instance of this class.
20 * @var null|Customify_Font_Palettes
21 * @access protected
22 * @since 1.7.4
23 */
24 protected static $_instance = null;
25
26 /**
27 * Constructor.
28 *
29 * @since 1.7.4
30 */
31 protected function __construct() {
32 $this->init();
33 }
34
35 /**
36 * Initialize this module.
37 *
38 * @since 1.7.4
39 */
40 public function init() {
41 // Hook up.
42 $this->add_hooks();
43 }
44
45 /**
46 * Initiate our hooks
47 *
48 * @since 1.7.4
49 */
50 public function add_hooks() {
51 /*
52 * Handle the font palettes preprocessing.
53 */
54 add_filter( 'customify_get_font_palettes', array( $this, 'preprocess_config' ), 5, 1 );
55
56 /*
57 * Handle the Customizer Style Manager section config.
58 */
59 add_filter( 'customify_filter_fields', array( $this, 'add_style_manager_section_master_fonts_config' ), 12, 1 );
60 // This needs to come after the external theme config has been applied
61 // add_filter( 'customify_filter_fields', array( $this, 'add_current_palette_control' ), 110, 1 );
62 add_filter( 'customify_final_config', array( $this, 'standardize_connected_fields' ), 10, 1 );
63
64 /*
65 * Scripts enqueued in the Customizer.
66 */
67 add_action( 'customize_controls_init', array( $this, 'register_admin_customizer_scripts' ), 10 );
68 add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_admin_customizer_scripts' ), 10 );
69
70 /*
71 * Handle the logic on settings update/save.
72 */
73 add_action( 'customize_save_after', array( $this, 'update_custom_palette_in_use' ), 10, 1 );
74
75 /**
76 * Add font palettes usage to site data.
77 */
78 add_filter( 'customify_style_manager_get_site_data', array( $this, 'add_palettes_to_site_data' ), 10, 1 );
79 }
80
81 /**
82 * Register Customizer admin scripts
83 */
84 public function register_admin_customizer_scripts() {
85 wp_register_script( PixCustomifyPlugin()->get_slug() . '-font-swap-values', plugins_url( 'js/customizer/font-swap-values.js', PixCustomifyPlugin()->get_file() ), array( 'jquery' ), PixCustomifyPlugin()->get_version() );
86 wp_register_script( PixCustomifyPlugin()->get_slug() . '-font-palettes-variations', plugins_url( 'js/customizer/font-palettes-variations.js', PixCustomifyPlugin()->get_file() ), array( 'jquery' ), PixCustomifyPlugin()->get_version() );
87 wp_register_script( PixCustomifyPlugin()->get_slug() . '-font-palettes', plugins_url( 'js/customizer/font-palettes.js', PixCustomifyPlugin()->get_file() ), array(
88 'jquery',
89 PixCustomifyPlugin()->get_slug() . '-font-palettes-variations',
90 PixCustomifyPlugin()->get_slug() . '-swap-values',
91 PixCustomifyPlugin()->get_slug() . '-fontselectfields',
92 ), PixCustomifyPlugin()->get_version() );
93 }
94
95 /**
96 * Enqueue Customizer admin scripts
97 */
98 public function enqueue_admin_customizer_scripts() {
99 // If there is no font palettes support, bail early.
100 if ( ! $this->is_supported() ) {
101 return;
102 }
103
104 wp_enqueue_script( PixCustomifyPlugin()->get_slug() . '-font-palettes' );
105 }
106
107 /**
108 * Preprocess the font palettes configuration.
109 *
110 * Things like transforming font_size_line_height_points to a polynomial function for easy use client side,
111 * or processing the styles intervals and making sure that we get to a state where there are no overlaps and the order is right.
112 *
113 * @since 1.7.4
114 *
115 * @param array $config
116 *
117 * @return array
118 */
119 public function preprocess_config( $config ) {
120 if ( empty( $config ) ) {
121 return $config;
122 }
123
124 foreach ( $config as $palette_id => $palette_config ) {
125 $config[ $palette_id ] = $this->preprocess_palette_config( $palette_config );
126 }
127
128 return $config;
129 }
130
131 /**
132 * Preprocess a font palette config before using it.
133 *
134 * @since 1.7.4
135 *
136 * @param array $palette_config
137 *
138 * @return array
139 */
140 private function preprocess_palette_config( $palette_config ) {
141 if ( empty( $palette_config ) ) {
142 return $palette_config;
143 }
144
145 global $wp_customize;
146 // We only need to do the fonts logic preprocess when we are in the Customizer.
147 if ( ! empty( $wp_customize ) && $wp_customize instanceof WP_Customize_Manager && ! empty( $palette_config['fonts_logic'] ) ) {
148 $palette_config['fonts_logic'] = $this->preprocess_fonts_logic_config( $palette_config['fonts_logic'] );
149 }
150
151 return $palette_config;
152 }
153
154 /**
155 * Before using a font logic config, preprocess it to allow for standardization, fill up of missing info, etc.
156 *
157 * @since 1.7.4
158 *
159 * @param array $fonts_logic_config
160 *
161 * @return array
162 */
163 private function preprocess_fonts_logic_config( $fonts_logic_config ) {
164 if ( empty( $fonts_logic_config ) ) {
165 return $fonts_logic_config;
166 }
167
168 foreach ( $fonts_logic_config as $font_setting_id => $font_logic ) {
169 if ( empty( $font_logic['font_family'] ) ) {
170 // If we don't have a font family we can't do much with this config - remove it.
171 unset( $fonts_logic_config[ $font_setting_id ] );
172 continue;
173 }
174
175 if ( empty( $font_logic['type'] ) ) {
176 // Default to 'google'
177 $fonts_logic_config[ $font_setting_id ]['type'] = 'google';
178 }
179
180 // Process the font_styles_intervals and make sure that they are in the right order and not overlapping.
181 if ( ! empty( $font_logic['font_styles_intervals'] ) && is_array( $font_logic['font_styles_intervals'] ) ) {
182 $font_styles = array( array_shift( $font_logic['font_styles_intervals'] ) );
183 // Make sure that the interval has a start
184 if ( ! isset( $font_styles[0]['start'] ) ) {
185 $font_styles[0]['start'] = 0;
186 }
187
188 foreach ( $font_logic['font_styles_intervals'] as $font_styles_interval ) {
189 // Make sure that the interval has a start
190 if ( ! isset( $font_styles_interval['start'] ) ) {
191 $font_styles_interval['start'] = 0;
192 }
193 // Go through the current font_styles and determine the place where this interval should fit in.
194 for ( $i = 0; $i < count( $font_styles ); $i++ ) {
195 // Determine if the new interval overlaps with this existing one.
196 if ( ! isset( $font_styles[$i]['end'] ) ) {
197 // Since this interval is without end, there is nothing after it.
198 // We need to adjust the old interval end.
199 if ( $font_styles[ $i ]['start'] < $font_styles_interval['start'] ) {
200 $font_styles[ $i ]['end'] = $font_styles_interval['start'];
201 } else {
202 if ( ! isset( $font_styles_interval['end'] ) ) {
203 // We need to delete the old interval altogether.
204 unset($font_styles[ $i ]);
205 $i--;
206 continue;
207 } else {
208 // Adjust the old interval and insert in front of it.
209 $font_styles[ $i ]['end'] = $font_styles_interval['end'];
210 $font_styles = array_slice( $font_styles, 0, $i ) + array( $font_styles_interval );
211 break;
212 }
213 }
214 } else {
215 if ( $font_styles[ $i ]['end'] > $font_styles_interval['start'] ) {
216 // We need to shrink this interval and make room for the new interval.
217 $font_styles[ $i ]['end'] = $font_styles_interval['start'];
218 } else {
219 // There is not overlap. Move to the next one.
220 continue;
221 }
222
223 if ( ! isset( $font_styles_interval['end'] ) ) {
224 // Everything after the existing interval is gone and the new one takes precedence.
225 array_splice( $font_styles, $i + 1, count( $font_styles ), array( $font_styles_interval ) );
226 break;
227 } else {
228 // Now go forward and see where the end of the new interval fits in.
229 for ( $j = $i + 1; $j < count( $font_styles ); $j ++ ) {
230 if ( $font_styles[ $j ]['start'] < $font_styles_interval['end'] ) {
231 // We have an overlapping after-interval.
232 if ( ! isset( $font_styles[ $j ]['end'] ) ) {
233 // Since this interval is without end, there is nothing after it.
234 $font_styles[ $j ]['start'] = $font_styles_interval['end'];
235 break;
236 } elseif ( $font_styles[ $j ]['end'] <= $font_styles_interval['end'] ) {
237 // We need to delete this interval since it is completely overwritten by the new one.
238 unset( $font_styles[ $j ] );
239 $j --;
240 continue;
241 } else {
242 // The new interval partially overlaps with the old one. Adjust.
243 $font_styles[ $j ]['end'] = $font_styles_interval['end'];
244 break;
245 }
246 } else {
247 // We can insert the new interval since this interval is after it
248 break;
249 }
250 }
251
252 // Insert the new interval.
253 array_splice( $font_styles, $j, 0, array( $font_styles_interval ) );
254 break;
255 }
256 }
257 }
258
259 // If we have reached the end of the list, we will insert it at the end.
260 if ( $i === count( $font_styles ) ) {
261 array_push( $font_styles, $font_styles_interval );
262 }
263 }
264
265 // We need to do a last pass and ensure no breaks in the intervals. We need them to be continuous.
266 // We will extend intervals to their next (right-hand) neighbour to achieve continuity.
267 if ( count( $font_styles ) > 1 ) {
268 // The first interval should start at zero, just in case.
269 $font_styles[0]['start'] = 0;
270 for( $i = 1; $i < count( $font_styles ); $i++ ) {
271 // Extend the previous interval, just in case.
272 $font_styles[ $i-1 ]['end'] = $font_styles[ $i ]['start'];
273 }
274 }
275
276 // The last interval should not have an end.
277 unset( $font_styles[ count( $font_styles )-1 ]['end'] );
278
279 // Finally, go through each font style and standardize it.
280 foreach( $font_styles as $key => $value ) {
281 if ( isset( $value['letter_spacing'] ) ) {
282 $font_styles[ $key ]['letter_spacing'] = $this->maybe_standardize_value( $value['letter_spacing'] );
283 }
284 }
285
286 $fonts_logic_config[ $font_setting_id ]['font_styles'] = $font_styles;
287 }
288 }
289
290 return $fonts_logic_config;
291 }
292
293 /**
294 * Get the font palettes configuration.
295 *
296 * @since 1.7.4
297 *
298 * @param bool $skip_cache Optional. Whether to use the cached config or fetch a new one.
299 *
300 * @return array
301 */
302 public function get_palettes( $skip_cache = false ) {
303 // Make sure that the Design Assets class is loaded.
304 require_once 'lib/class-customify-design-assets.php';
305
306 // Get the design assets data.
307 $design_assets = Customify_Design_Assets::instance()->get( $skip_cache );
308 if ( false === $design_assets || empty( $design_assets['font_palettes'] ) ) {
309 $config = $this->get_default_config();
310 } else {
311 $config = $design_assets['font_palettes'];
312 }
313
314 return apply_filters( 'customify_get_font_palettes', $config );
315 }
316
317 /**
318 * Determine if Font Palettes are supported.
319 *
320 * @since 1.7.4
321 *
322 * @return bool
323 */
324 public function is_supported() {
325 // For now we will only use the fact that Style Manager is supported.
326 return apply_filters( 'customify_font_palettes_are_supported', Customify_Style_Manager::instance()->is_supported() );
327 }
328
329 /**
330 * Setup the Style Manager Customizer section master fonts config.
331 *
332 * This handles the base configuration for the controls in the Style Manager section. We expect other parties (e.g. the theme),
333 * to come and fill up the missing details (e.g. connected fields).
334 *
335 * @since 1.7.4
336 *
337 * @param array $config This holds required keys for the plugin config like 'opt-name', 'panels', 'settings'.
338 *
339 * @return array
340 */
341 public function add_style_manager_section_master_fonts_config( $config ) {
342 // If there is no style manager support, bail early.
343 if ( ! $this->is_supported() ) {
344 return $config;
345 }
346
347 if ( ! isset( $config['sections']['style_manager_section'] ) ) {
348 $config['sections']['style_manager_section'] = array();
349 }
350
351 // The section might be already defined, thus we merge, not replace the entire section config.
352 $config['sections']['style_manager_section'] = array_replace_recursive( $config['sections']['style_manager_section'], array(
353 'options' => array(
354 'sm_font_palette' => array(
355 'type' => 'preset',
356 // We will bypass the plugin setting regarding where to store - we will store it cross-theme in wp_options
357 'setting_type' => 'option',
358 // We will force this setting id preventing prefixing and other regular processing.
359 'setting_id' => 'sm_font_palette',
360 // We don't want to refresh the preview window, even though we have no direct effect on it through this field.
361 'live' => true,
362 'priority' => 5,
363 'label' => esc_html__( 'Select a font palette:', 'customify' ),
364 'desc' => esc_html__( 'Conveniently change the design of your site with font palettes. Easy as pie.', 'customify' ),
365 'default' => 'julia',
366 'choices_type' => 'font_palette',
367 'choices' => $this->get_palettes(),
368 ),
369 'sm_font_palette_variation' => array(
370 'type' => 'radio',
371 'setting_type' => 'option',
372 'setting_id' => 'sm_font_palette_variation',
373 'label' => esc_html__( 'Palette Variation', 'customify' ),
374 'default' => 'regular',
375 'live' => true,
376 'priority' => 5.5,
377 'choices' => array(
378 'light' => esc_html__( 'not light', 'customify' ),
379 'regular' => esc_html__( 'not regular', 'customify' ),
380 'big' => esc_html__( 'not big', 'customify' ),
381 ),
382 ),
383 'sm_font_primary' => array(
384 'type' => 'font',
385 // We will bypass the plugin setting regarding where to store - we will store it cross-theme in wp_options
386 'setting_type' => 'option',
387 // We will force this setting id preventing prefixing and other regular processing.
388 'setting_id' => 'sm_font_primary',
389 // We don't want to refresh the preview window, even though we have no direct effect on it through this field.
390 'live' => true,
391 'priority' => 7,
392 'label' => esc_html__( 'Font Primary', 'customify' ),
393 'default' => array(
394 'font-family' => 'Montserrat',
395 'font-weight' => '400',
396 'font-size' => 20,
397 'line-height' => 1.25,
398 'letter-spacing' => 0.029,
399 'text-transform' => 'uppercase'
400 ),
401 // Sub Fields Configuration
402 'fields' => array(
403 // These subfields are disabled because they are calculated through the font palette logic.
404 'font-size' => false,
405 'font-weight' => false,
406 'line-height' => false,
407 'letter-spacing' => false,
408 'text-align' => false,
409 'text-transform' => false,
410 'text-decoration' => false,
411 ),
412 'connected_fields' => array(),
413 ),
414 'sm_font_secondary' => array(
415 'type' => 'font',
416 'setting_type' => 'option',
417 'setting_id' => 'sm_font_secondary',
418 'live' => true,
419 'priority' => 7.1,
420 'label' => esc_html__( 'Font Secondary', 'customify' ),
421 'default' => array(
422 'font-family' => 'Montserrat',
423 'font-weight' => '300',
424 'font-size' => 10,
425 'line-height' => 1.625,
426 'letter-spacing' => 0.029,
427 'text-transform' => 'uppercase'
428 ),
429 // Sub Fields Configuration
430 'fields' => array(
431 // These subfields are disabled because they are calculated through the font palette logic.
432 'font-size' => false,
433 'font-weight' => false,
434 'line-height' => false,
435 'letter-spacing' => false,
436 'text-align' => false,
437 'text-transform' => false,
438 'text-decoration' => false,
439 ),
440 'connected_fields' => array(),
441 ),
442 'sm_font_body' => array(
443 'type' => 'font',
444 'setting_type' => 'option',
445 'setting_id' => 'sm_font_body',
446 'live' => true,
447 'priority' => 7.2,
448 'label' => esc_html__( 'Font Body', 'customify' ),
449 'default' => array(
450 'font-family' => 'Montserrat',
451 'font-weight' => '300',
452 'font-size' => 14,
453 'line-height' => 1.6,
454 'letter-spacing' => 0.029,
455 'text-transform' => 'uppercase'
456 ),
457 // Sub Fields Configuration
458 'fields' => array(
459 // These subfields are disabled because they are calculated through the font palette logic.
460 'font-size' => false,
461 'font-weight' => false,
462 'line-height' => false,
463 'letter-spacing' => false,
464 'text-align' => false,
465 'text-transform' => false,
466 'text-decoration' => false,
467 ),
468 'connected_fields' => array(),
469 ),
470 'sm_swap_fonts' => array(
471 'type' => 'button',
472 'setting_type' => 'option',
473 'setting_id' => 'sm_swap_fonts',
474 'priority' => 9,
475 'label' => esc_html__( 'Swap Fonts', 'customify' ),
476 'action' => 'sm_swap_fonts',
477 ),
478 'sm_swap_primary_secondary_fonts' => array(
479 'type' => 'button',
480 'setting_type' => 'option',
481 'setting_id' => 'sm_swap_primary_secondary_fonts',
482 'priority' => 9.1,
483 'label' => esc_html__( 'Swap Primary ⇆ Secondary', 'customify' ),
484 'action' => 'sm_swap_dark_light',
485 ),
486 ),
487 ) );
488
489 return $config;
490 }
491
492 /**
493 * Add the current font palette control to the Style Manager section.
494 *
495 * @since 1.7.4
496 *
497 * @param array $config
498 *
499 * @return array
500 */
501 public function add_current_palette_control( $config ) {
502 // If there is no style manager support, bail early.
503 if ( ! $this->is_supported() ) {
504 return $config;
505 }
506
507 if ( ! isset( $config['sections']['style_manager_section'] ) ) {
508 $config['sections']['style_manager_section'] = array();
509 }
510
511 $current_palette = '';
512 $current_palette_sets = array( 'current', 'next' );
513
514 $master_font_controls_ids = $this->get_all_master_font_controls_ids( $config['sections']['style_manager_section']['options'] );
515
516 foreach ( $current_palette_sets as $set ) {
517 $current_palette .= '<div class="fonts ' . $set . '">';
518 foreach ( $master_font_controls_ids as $setting_id ) {
519 if ( ! empty( $config['sections']['style_manager_section']['options'][ $setting_id ]['connected_fields'] ) ) {
520 $current_palette .=
521 '<div class="font ' . $setting_id . '" data-setting="' . $setting_id . '">' . PHP_EOL .
522 '<div class="fill"></div>' . PHP_EOL .
523 '<div class="picker"><i></i></div>' . PHP_EOL .
524 '</div>' . PHP_EOL;
525 }
526 }
527 $current_palette .= '</div>';
528 }
529
530 // The section might be already defined, thus we merge, not replace the entire section config.
531 $config['sections']['style_manager_section']['options'] = array(
532 'sm_current_font_palette' => array(
533 'type' => 'html',
534 'html' =>
535 '<div class="font-palette-container">' . PHP_EOL .
536 '<span class="customize-control-title">Current Font Palette:</span>' . PHP_EOL .
537 '<span class="description customize-control-description">Choose a font palette to start with. Adjust its style using the variation buttons below.</span>' . PHP_EOL .
538 '<div class="c-font-palette">' . PHP_EOL .
539 $current_palette .
540 '<div class="c-font-palette__overlay">' . PHP_EOL .
541 '<div class="c-font-palette__label">' .
542 '<div class="c-font-palette__name">' . 'Original Style' . '</div>' .
543 '<div class="c-font-palette__control variation-light active" data-target="#_customize-input-sm_font_palette_variation_control-radio-light">' .
544 '<span class="dashicons dashicons-image-rotate"></span>' .
545 '<div class="c-font-palette__tooltip">Light</div>' .
546 '</div>' .
547 '<div class="c-font-palette__control variation-dark" data-target="#_customize-input-sm_font_palette_variation_control-radio-dark">' .
548 '<span class="dashicons dashicons-image-filter"></span>'.
549 '<div class="c-font-palette__tooltip">Dark</div>' .
550 '</div>' .
551 '<div class="c-font-palette__control variation-fontful" data-target="#_customize-input-sm_font_palette_variation_control-radio-fontful">' .
552 '<span class="dashicons dashicons-admin-appearance"></span>' .
553 '<div class="c-font-palette__tooltip">Fontful</div>' .
554 '</div>' .
555 '</div>' . PHP_EOL .
556 '</div>' . PHP_EOL .
557 '</div>' . PHP_EOL .
558 '</div>' . PHP_EOL .
559 '<svg class="c-font-palette__blur" width="15em" height="15em" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg" version="1.1">' . PHP_EOL .
560 '<defs>' . PHP_EOL .
561 '<filter id="goo">' . PHP_EOL .
562 '<feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />' . PHP_EOL .
563 '<feFontMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 50 -20" result="goo" />' . PHP_EOL .
564 '<feBlend in="SourceGraphic" in2="goo" />' . PHP_EOL .
565 '</filter>' . PHP_EOL .
566 '</defs>' . PHP_EOL .
567 '</svg>',
568 ),
569 ) + $config['sections']['style_manager_section']['options'];
570
571 return $config;
572 }
573
574 /**
575 * Process any configured connected fields that relate to fonts and standardize their config.
576 *
577 * Think things like filling up the default font_size if not present.
578 *
579 * @since 1.7.4
580 *
581 * @param array $config
582 *
583 * @return array
584 */
585 public function standardize_connected_fields( $config ) {
586 // If there is no style manager support, bail early.
587 if ( ! $this->is_supported() ) {
588 return $config;
589 }
590
591 $style_manager_options = $config['sections']['style_manager_section']['options'];
592 $master_font_controls_ids = $this->get_all_master_font_controls_ids( $style_manager_options );
593 if ( empty( $master_font_controls_ids ) ) {
594 return $config;
595 }
596
597 foreach ( $master_font_controls_ids as $id ) {
598 if ( ! empty( $style_manager_options[ $id ]['connected_fields'] ) ) {
599 $connected_fields_config = array();
600 foreach ( $style_manager_options[ $id ]['connected_fields'] as $key => $value ) {
601 // If we have a shorthand connected field config, change it to a standard one.
602 if ( ! is_array( $value ) ) {
603 $key = $value;
604 $value = array();
605 }
606
607 $option_config = $this->get_option_config( $key, $config );
608 if ( empty( $option_config ) ) {
609 continue;
610 }
611
612 // If we didn't get a font_size we will try and grab the default value for the connected field.
613 if ( ! isset( $value['font_size'] ) ) {
614 if ( isset( $option_config['default']['font-size'] ) ) {
615 $value['font_size'] = array( 'value' => $option_config['default']['font-size'] );
616 } else {
617 $value['font_size'] = false;
618 }
619 }
620
621 // Handle the case when the received font_size value is a number with a unit - split them.
622 $value['font_size'] = $this->maybe_standardize_value( $value['font_size'] );
623
624 // If we don't have an unit, maybe we can make an educated guess.
625 // If the value is bellow 9, then probably we are talking about ems, else pxs.
626 if ( ! empty( $value['font_size'] ) && ! empty( $value['font_size']['value'] ) && ! isset( $value['font_size']['unit'] ) ) {
627 if ( $value['font_size']['value'] < 9 ) {
628 $value['font_size']['unit'] = 'em';
629 } else {
630 $value['font_size']['unit'] = 'px';
631 }
632 }
633
634 $connected_fields_config[ $key ] = $value;
635 }
636
637 $config['sections']['style_manager_section']['options'][ $id ]['connected_fields'] = $connected_fields_config;
638 }
639 }
640
641 return $config;
642 }
643
644 /**
645 * Standardize a numerical value for a font CSS property.
646 *
647 * The standard format is an associative array with the following entries:
648 * - 'value': holds the actual numerical value (int or float)
649 * - 'unit : optional; it holds the unit that should be used for the value
650 *
651 * @param mixed $value
652 *
653 * @return array|bool
654 */
655 private function maybe_standardize_value( $value ) {
656 $new_value = false;
657
658 if ( false === $value ) {
659 return $new_value;
660 }
661
662 if ( is_array( $value ) ) {
663 $new_value = $value;
664 }
665
666 if ( is_string( $value ) ) {
667 if ( is_numeric( $value ) ) {
668 $new_value = array( 'value' => (float) $value );
669 } else {
670 // We will get everything in front that is a valid part of a number (float including).
671 preg_match("/^([\d.\-+]+)/i", $value, $match);
672
673 if ( ! empty( $match ) && isset( $match[0] ) ) {
674 $new_value = array(
675 'value' => (float) $match[0],
676 'unit' => substr( $value, strlen( $match[0] ) ),
677 );
678 }
679 }
680 }
681
682 if ( is_numeric( $value ) ) {
683 $new_value = array( 'value' => $value );
684 }
685
686 return $new_value;
687 }
688
689 /**
690 * Get the Customify configuration of a certain option.
691 *
692 * @param string $option_id
693 *
694 * @return array|false The option config or false on failure.
695 */
696 private function get_option_config( $option_id, $config ) {
697 // We need to search for the option configured under the given id (the array key)
698 if ( isset ( $config['panels'] ) ) {
699 foreach ( $config['panels'] as $panel_id => $panel_settings ) {
700 if ( isset( $panel_settings['sections'] ) ) {
701 foreach ( $panel_settings['sections'] as $section_id => $section_settings ) {
702 if ( isset( $section_settings['options'] ) ) {
703 foreach ( $section_settings['options'] as $id => $option_config ) {
704 if ( $id === $option_id ) {
705 return $option_config;
706 }
707 }
708 }
709 }
710 }
711 }
712 }
713
714 if ( isset ( $config['sections'] ) ) {
715 foreach ( $config['sections'] as $section_id => $section_settings ) {
716 if ( isset( $section_settings['options'] ) ) {
717 foreach ( $section_settings['options'] as $id => $option_config ) {
718 if ( $id === $option_id ) {
719 return $option_config;
720 }
721 }
722 }
723 }
724 }
725
726 return false;
727 }
728
729 /**
730 * Get the default (hard-coded) font palettes configuration.
731 *
732 * This is only a fallback config in case we can't communicate with the cloud, the first time.
733 *
734 * @since 1.7.4
735 *
736 * @return array
737 */
738 protected function get_default_config() {
739 $default_config = array(
740 'gema' => array(
741 'label' => esc_html__( 'Gema', 'customify' ),
742 'preview' => array(
743 // Font Palette Name
744 'title' => esc_html__( 'Gema', 'customify' ),
745 'description' => esc_html__( 'A graceful nature, truly tasteful and polished.', 'customify' ),
746 'background_image_url' => 'http://pxgcdn.com/images/style-manager/color-palettes/gema-theme-palette.jpg',
747
748 // Use the following options to style the preview card fonts
749 // Including font-family, size, line-height, weight, letter-spacing and text transform
750 'title_font' => array(
751 'font' => 'font_primary',
752 'size' => 32,
753 ),
754 'description_font' => array(
755 'font' => 'font_body',
756 'size' => 16,
757 ),
758 ),
759
760 'fonts_logic' => array(
761 // Primary is used for main headings [Display, H1, H2, H3]
762 'sm_font_primary' => array(
763 // Define the font type ('google' or 'theme_font'). By default it's 'google'.
764 'type' => 'google',
765 // Font loaded when a palette is selected
766 'font_family' => 'Montserrat',
767 // Load all these fonts weights.
768 'font_weights' => array( 100, 300, 700 ),
769 // "Generate" the graph to be used for font-size and line-height.
770 'font_size_to_line_height_points' => array(
771 array( 17, 1.7 ),
772 array( 20, 1.3 ),
773 array( 32, 1.3 ),
774 array( 48, 1.2 ),
775 ),
776
777 // Define how fonts will look based on the font size.
778 'font_styles_intervals' => array(
779 array(
780 'start' => 10,
781 'font_weight' => 300,
782 'letter_spacing' => '0.03em',
783 'text_transform' => 'uppercase',
784 ),
785 array(
786 'start' => 12,
787 'font_weight' => 700,
788 'letter_spacing' => '0em',
789 'text_transform' => 'uppercase',
790 ),
791 array(
792 'start' => 18,
793 'font_weight' => 100,
794 'letter_spacing' => '0.03em',
795 'text_transform' => 'uppercase',
796 ),
797 ),
798 ),
799
800 // Secondary font is used for smaller headings [H4, H5, H6], including meta details
801 'sm_font_secondary' => array(
802 'font_family' => 'Montserrat',
803 'font_weights' => array( 200, 400 ),
804 'font_size_to_line_height_points' => array(
805 array( 10, 1.6 ),
806 array( 12, 1.5 ),
807 array( 18, 1.5 )
808 ),
809 'font_styles_intervals' => array(
810 array(
811 'start' => 0,
812 'font_weight' => 200,
813 'letter_spacing' => '0.03em',
814 'text_transform' => 'uppercase',
815 ),
816 array(
817 'start' => 13,
818 'font_weight' => 400,
819 'letter_spacing' => '0.015em',
820 'text_transform' => 'uppercase',
821 ),
822 ),
823 ),
824
825 // Used for Body Font [eg. entry-content]
826 'sm_font_body' => array(
827 'font_family' => 'Montserrat',
828 'font_weights' => array( 200, '200italic', 700, '700italic' ),
829 'font_size_to_line_height_points' => array(
830 array( 15, 1.7 ),
831 array( 16, 1.8 ),
832 array( 18, 1.7 ),
833 ),
834
835 // Define how fonts will look based on their size
836 'font_styles_intervals' => array(
837 array(
838 'font_weight' => 200,
839 'letter_spacing' => 0,
840 'text_transform' => 'none',
841 ),
842 ),
843 ),
844 ),
845 ),
846 'julia' => array(
847 'label' => esc_html__( 'Julia', 'customify' ),
848 'preview' => array(
849 // Font Palette Name
850 'title' => esc_html__( 'Julia', 'customify' ),
851 'description' => esc_html__( 'A graceful nature, truly tasteful and polished.', 'customify' ),
852 'background_image_url' => 'http://pxgcdn.com/images/style-manager/color-palettes/julia-theme-palette.jpg',
853
854 // Use the following options to style the preview card fonts
855 // Including font-family, size, line-height, weight, letter-spacing and text transform
856 'title_font' => array(
857 'font' => 'font_primary',
858 'size' => 30,
859 ),
860 'description_font' => array(
861 'font' => 'font_body',
862 'size' => 17,
863 ),
864 ),
865
866 'fonts_logic' => array(
867 // Primary is used for main headings [Display, H1, H2, H3]
868 'sm_font_primary' => array(
869 // Define the font type ('google' or 'theme_font'). By default it's 'google'.
870 'type' => 'google',
871 // Font loaded when a palette is selected
872 'font_family' => 'Lora',
873 // Load all these fonts weights.
874 'font_weights' => array( 700 ),
875 // "Generate" the graph to be used for font-size and line-height.
876 'font_size_to_line_height_points' => array(
877 array( 24, 1.25 ),
878 array( 44, 1.2 ),
879 array( 66, 1.15 ),
880 ),
881
882 // Define how fonts will look based on the font size.
883 'font_styles_intervals' => array(
884 array(
885 'start' => 0,
886 'font_weight' => 700,
887 'letter_spacing' => '0em',
888 'text_transform' => 'none',
889 ),
890 ),
891 ),
892
893 // Secondary font is used for smaller headings [H4, H5, H6], including meta details
894 'sm_font_secondary' => array(
895 'font_family' => 'Montserrat',
896 'font_weights' => array( 'regular', 600 ),
897 'font_size_to_line_height_points' => array(
898 array( 14, 1.2 ),
899 array( 16, 1.2 )
900 ),
901 'font_styles_intervals' => array(
902 array(
903 'start' => 0,
904 'font_weight' => 600,
905 'letter_spacing' => '0.154em',
906 'text_transform' => 'uppercase',
907 ),
908 array(
909 'start' => 13,
910 'font_weight' => 'regular',
911 'letter_spacing' => '0em',
912 'text_transform' => 'uppercase',
913 ),
914 array(
915 'start' => 14,
916 'font_weight' => 'regular',
917 'letter_spacing' => '0.1em',
918 'text_transform' => 'uppercase',
919 ),
920 array(
921 'start' => 16,
922 'font_weight' => 'regular',
923 'letter_spacing' => '0em',
924 'text_transform' => 'uppercase',
925 ),
926 array(
927 'start' => 17,
928 'font_weight' => 'regular',
929 'letter_spacing' => '0em',
930 'text_transform' => 'none',
931 ),
932 ),
933 ),
934
935 // Used for Body Font [eg. entry-content]
936 'sm_font_body' => array(
937 'font_family' => 'PT Serif',
938 'font_weights' => array( 'regular', '400italic', 700, '700italic' ),
939 'font_size_to_line_height_points' => array(
940 array( 15, 1.7 ),
941 array( 17, 1.6 ),
942 array( 18, 1.5 ),
943 ),
944
945 // Define how fonts will look based on their size
946 'font_styles_intervals' => array(
947 array(
948 'start' => 0,
949 'font_weight' => 'regular',
950 'letter_spacing' => 0,
951 'text_transform' => 'none',
952 ),
953 ),
954 ),
955 ),
956 ),
957 'patch' => array(
958 'label' => esc_html__( 'Patch', 'customify' ),
959 'preview' => array(
960 // Font Palette Name
961 'title' => esc_html__( 'Patch', 'customify' ),
962 'description' => esc_html__( 'A graceful nature, truly tasteful and polished.', 'customify' ),
963 'background_image_url' => 'http://pxgcdn.com/images/style-manager/color-palettes/patch-theme-palette.jpg',
964
965 // Use the following options to style the preview card fonts
966 // Including font-family, size, line-height, weight, letter-spacing and text transform
967 'title_font' => array(
968 'font' => 'font_primary',
969 'size' => 26,
970 ),
971 'description_font' => array(
972 'font' => 'font_body',
973 'size' => 16,
974 ),
975 ),
976
977 'fonts_logic' => array(
978 // Primary is used for main headings [Display, H1, H2, H3]
979 'sm_font_primary' => array(
980 // Define the font type ('google' or 'theme_font'). By default it's 'google'.
981 'type' => 'google',
982 // Font loaded when a palette is selected
983 'font_family' => 'Oswald',
984 // Load all these fonts weights.
985 'font_weights' => array( 300, 400, 500 ),
986 // "Generate" the graph to be used for font-size and line-height.
987 'font_size_to_line_height_points' => array(
988 array( 20, 1.15 ),
989 array( 26, 1.45 ),
990 array( 30, 1.25 ),
991 array( 56, 1.25 ),
992 ),
993
994 // Define how fonts will look based on the font size.
995 'font_styles_intervals' => array(
996 array(
997 'start' => 0,
998 'font_weight' => 500,
999 'letter_spacing' => '0.04em',
1000 'text_transform' => 'uppercase',
1001 ),
1002 array(
1003 'start' => 24,
1004 'font_weight' => 300,
1005 'letter_spacing' => '0.06em',
1006 'text_transform' => 'uppercase',
1007 ),
1008 array(
1009 'start' => 25,
1010 'font_weight' => 400,
1011 'letter_spacing' => '0.04em',
1012 'text_transform' => 'uppercase',
1013 ),
1014 array(
1015 'start' => 26,
1016 'font_weight' => 500,
1017 'letter_spacing' => '0.04em',
1018 'text_transform' => 'uppercase',
1019 ),
1020 ),
1021 ),
1022
1023 // Secondary font is used for smaller headings [H4, H5, H6], including meta details
1024 'sm_font_secondary' => array(
1025 'font_family' => 'Oswald',
1026 'font_weights' => array( 200, '200italic', 500, '500italic' ),
1027 'font_size_to_line_height_points' => array(
1028 array( 14, 1.625 ),
1029 array( 22, 1.55 ),
1030 array( 24, 1.625 ),
1031 ),
1032 'font_styles_intervals' => array(
1033 array(
1034 'start' => 0,
1035 'font_weight' => 500,
1036 'letter_spacing' => '0.01em',
1037 'text_transform' => 'uppercase',
1038 ),
1039 array(
1040 'start' => 20,
1041 'font_weight' => 500,
1042 'letter_spacing' => '0em',
1043 'text_transform' => 'uppercase',
1044 ),
1045 array(
1046 'start' => 24,
1047 'font_weight' => 200,
1048 'letter_spacing' => '0em',
1049 'text_transform' => 'none',
1050 ),
1051 ),
1052 ),
1053
1054 // Used for Body Font [eg. entry-content]
1055 'sm_font_body' => array(
1056 'font_family' => 'Roboto',
1057 'font_weights' => array( 300, '300italic', 400, '400italic', 500, '500italic' ),
1058 'font_size_to_line_height_points' => array(
1059 array( 10, 1.6 ),
1060 array( 16, 1.625 ),
1061 array( 18, 1.75 ),
1062 ),
1063
1064 // Define how fonts will look based on their size
1065 'font_styles_intervals' => array(
1066 array(
1067 'start' => 0,
1068 'end' => 10.9,
1069 'font_weight' => 500,
1070 'letter_spacing' => '0.03em',
1071 'text_transform' => 'none',
1072 ),
1073 array(
1074 'start' => 10.9,
1075 'end' => 12,
1076 'font_weight' => 500,
1077 'letter_spacing' => '0.02em',
1078 'text_transform' => 'uppercase',
1079 ),
1080 array(
1081 'start' => 12,
1082 'font_weight' => 300,
1083 'letter_spacing' => 0,
1084 'text_transform' => 'none',
1085 ),
1086 ),
1087 ),
1088 ),
1089 ),
1090 'hive' => array(
1091 'label' => esc_html__( 'Hive', 'customify' ),
1092 'preview' => array(
1093 // Font Palette Name
1094 'title' => esc_html__( 'Hive', 'customify' ),
1095 'description' => esc_html__( 'A graceful nature, truly tasteful and polished.', 'customify' ),
1096 'background_image_url' => 'http://pxgcdn.com/images/style-manager/color-palettes/hive-theme-palette.jpg',
1097
1098 // Use the following options to style the preview card fonts
1099 // Including font-family, size, line-height, weight, letter-spacing and text transform
1100 'title_font' => array(
1101 'font' => 'font_primary',
1102 'size' => 36,
1103 ),
1104 'description_font' => array(
1105 'font' => 'font_body',
1106 'size' => 18,
1107 ),
1108 ),
1109
1110 'fonts_logic' => array(
1111 // Primary is used for main headings [Display, H1, H2, H3]
1112 'sm_font_primary' => array(
1113 // Define the font type ('google' or 'theme_font'). By default it's 'google'.
1114 'type' => 'google',
1115 // Font loaded when a palette is selected
1116 'font_family' => 'Playfair Display',
1117 // Load all these fonts weights.
1118 'font_weights' => array( 400, '400italic', 700, '700italic', 900, '900italic' ),
1119 // "Generate" the graph to be used for font-size and line-height.
1120 'font_size_to_line_height_points' => array(
1121 array( 20, 1.55 ),
1122 array( 28, 1.5 ),
1123 array( 40, 1.35 ),
1124 array( 65, 1.15 ),
1125 ),
1126
1127 // Define how fonts will look based on the font size.
1128 'font_styles_intervals' => array(
1129 array(
1130 'start' => 0,
1131 'font_weight' => 400,
1132 'letter_spacing' => '0em',
1133 'text_transform' => 'none',
1134 ),
1135 ),
1136 ),
1137
1138 // Secondary font is used for smaller headings [H4, H5, H6], including meta details
1139 'sm_font_secondary' => array(
1140 'font_family' => 'Noto Serif',
1141 'font_weights' => array( 400, '400italic', 700, '700italic' ),
1142 'font_size_to_line_height_points' => array(
1143 array( 13, 1.33 ),
1144 array( 18, 1.5 ),
1145 ),
1146 'font_styles_intervals' => array(
1147 array(
1148 'start' => 0,
1149 'font_weight' => 400,
1150 'letter_spacing' => '0em',
1151 'text_transform' => 'none',
1152 ),
1153 ),
1154 ),
1155
1156 // Used for Body Font [eg. entry-content]
1157 'sm_font_body' => array(
1158 'font_family' => 'Noto Serif',
1159 'font_weights' => array( 400, '400italic', 700, '700italic' ),
1160 'font_size_to_line_height_points' => array(
1161 array( 13, 1.4 ),
1162 array( 18, 1.5 ),
1163 ),
1164
1165 // Define how fonts will look based on their size
1166 'font_styles_intervals' => array(
1167 array(
1168 'start' => 0,
1169 'font_weight' => 400,
1170 'letter_spacing' => 0,
1171 'text_transform' => 'none',
1172 ),
1173 ),
1174 ),
1175 ),
1176 ),
1177 'vasco' => array(
1178 'label' => esc_html__( 'Not Vasco', 'customify' ),
1179 'preview' => array(
1180 // Font Palette Name
1181 'title' => esc_html__( 'Not Vasco', 'customify' ),
1182 'description' => esc_html__( 'Just awesome.', 'customify' ),
1183 'background_image_url' => 'http://pxgcdn.com/images/style-manager/color-palettes/vasco-theme-palette.jpg',
1184
1185 // Use the following options to style the preview card fonts
1186 // Including font-family, size, line-height, weight, letter-spacing and text transform
1187 'title_font' => array(
1188 'font' => 'font_primary',
1189 'size' => 26,
1190 ),
1191 'description_font' => array(
1192 'font' => 'font_body',
1193 'size' => 14,
1194 ),
1195 ),
1196
1197 'fonts_logic' => array(
1198 // Primary is used for main headings [Display, H1, H2, H3]
1199 'sm_font_primary' => array(
1200 // Define the font type ('google', 'theme_font', 'system'). By default it's 'google'.
1201 'type' => 'google',
1202 // Font loaded when a palette is selected
1203 'font_family' => 'Playfair Display',
1204 // Load all these fonts weights.
1205 'font_weights' => array( 'regular',700,900 ),
1206 // "Generate" the graph to be used for font-size and line-height.
1207 'font_size_to_line_height_points' => array(
1208 array( 14, 2 ),
1209 array( 40, 1.6 ),
1210 array( 60, 1.1 ),
1211 ),
1212
1213 // These are not used right now.
1214 // 'font_size_min' => 30,
1215 // 'font_size_max' => 100,
1216
1217 // Define how fonts will look based on the font size.
1218 // The current logic is as follows:
1219 // - for an interval, if the start is missing, it is assumed to be 0;
1220 // - for an interval, if the end is missing, it is assumed to be infinity;
1221 // - later intervals overwrite earlier ones and apply their own styles; so the order in which you define intervals might influence things;
1222 // - if there are gaps between intervals, we will "extend" the first interval to the start of it's next neighbour;
1223 // - neighbouring intervals will have, in the end, the same end and start, and on the border, the first interval will apply
1224 // i.e. end takes precedence over start.
1225 'font_styles_intervals' => array(
1226 array(
1227 'start' => 0,
1228 'end' => 20,
1229 'font_weight' => 'regular',
1230 'letter_spacing' => '0em',
1231 'text_transform' => 'none',
1232 ),
1233 array(
1234 'start' => 20,
1235 'end' => 50,
1236 'font_weight' => 700,
1237 'letter_spacing' => '0em',
1238 'text_transform' => 'uppercase',
1239 ),
1240 array(
1241 'start' => 30,
1242 'font_weight' => 900,
1243 'letter_spacing' => '0em',
1244 'text_transform' => 'uppercase',
1245 ),
1246 ),
1247 ),
1248
1249 // Secondary font is used for smaller headings [H4, H5, H6], including meta details
1250 'sm_font_secondary' => array(
1251 'font_family' => 'Noto Serif',
1252 'font_weights' => array( 400, 500, 700 ),
1253 'font_size_to_line_height_points' => array(
1254 array( 14, 1.7 ),
1255 array( 50, 1.3 ),
1256 array( 80, 1 ),
1257 ),
1258 'font_styles_intervals' => array(
1259 array(
1260 'end' => 14,
1261 'font_weight' => 400,
1262 'letter_spacing' => '0.08em',
1263 'text_transform' => 'uppercase',
1264 ),
1265 array(
1266 'start' => 14,
1267 'end' => 19,
1268 'font_weight' => 700,
1269 'letter_spacing' => '0.07em',
1270 'text_transform' => 'uppercase',
1271 ),
1272 array(
1273 'start' => 19,
1274 'font_weight' => 500,
1275 'letter_spacing' => 0,
1276 'text_transform' => 'none',
1277 ),
1278 ),
1279 ),
1280
1281 // Used for Body Font [eg. entry-content]
1282 'sm_font_body' => array(
1283 'type' => 'google',
1284 'font_family' => 'Roboto Slab',
1285 'font_weights' => array( 400, '400italic', 700, '700italic' ),
1286 'font_size_to_line_height_points' => array(
1287 array( 15, 1.7 ),
1288 array( 17, 1.6 ),
1289 array( 18, 1.5 ),
1290 ),
1291
1292 // Define how fonts will look based on their size
1293 'font_styles_intervals' => array(
1294 array(
1295 'start' => 0,
1296 'font_weight' => '400italic',
1297 'letter_spacing' => 0,
1298 'text_transform' => 'none',
1299 ),
1300 ),
1301 ),
1302 ),
1303 ),
1304 );
1305
1306 return apply_filters( 'customify_style_manager_default_font_palettes', $default_config );
1307 }
1308
1309
1310
1311 /**
1312 * Get the current font palette ID or false if none is selected.
1313 *
1314 * @since 1.7.4
1315 *
1316 * @return string|false
1317 */
1318 public function get_current_palette() {
1319 return get_option( 'sm_font_palette', false );
1320 }
1321
1322 /**
1323 * Get the current font palette variation ID or false if none is selected.
1324 *
1325 * @since 1.7.4
1326 *
1327 * @return string|false
1328 */
1329 public function get_current_palette_variation() {
1330 return get_option( 'sm_font_palette_variation', false );
1331 }
1332
1333 /**
1334 * Determine if the selected font palette has been customized and remember this in an option.
1335 *
1336 * @since 1.7.4
1337 *
1338 * @return bool
1339 */
1340 public function update_custom_palette_in_use() {
1341 // If there is no style manager support, bail early.
1342 if ( ! $this->is_supported() ) {
1343 return false;
1344 }
1345
1346 $current_palette = $this->get_current_palette();
1347 if ( empty( $current_palette ) ) {
1348 return false;
1349 }
1350
1351 $font_palettes = $this->get_palettes();
1352 if ( ! isset( $font_palettes[ $current_palette ] ) || empty( $font_palettes[ $current_palette ]['options'] ) ) {
1353 return false;
1354 }
1355
1356 $is_custom_palette = false;
1357 // If any of the current master fonts has a different value than the one provided by the font palette,
1358 // it means a custom font palette is in use.
1359 $current_palette_options = $font_palettes[ $current_palette ]['options'];
1360 foreach ( $current_palette_options as $setting_id => $value ) {
1361 if ( $value != get_option( $setting_id ) ) {
1362 $is_custom_palette = true;
1363 break;
1364 }
1365 }
1366
1367 update_option( 'sm_is_custom_font_palette', $is_custom_palette, true );
1368
1369 do_action( 'customify_style_manager_updated_custom_palette_in_use', $is_custom_palette );
1370
1371 return true;
1372 }
1373
1374 /**
1375 * Determine if a custom font palette is in use.
1376 *
1377 * @since 1.7.4
1378 *
1379 * @return bool
1380 */
1381 public function is_using_custom_palette(){
1382 return (bool) get_option( 'sm_is_custom_font_palette', false );
1383 }
1384
1385 /**
1386 * Get all the defined Style Manager master font field ids.
1387 *
1388 * @since 1.7.4
1389 *
1390 * @param array $options
1391 *
1392 * @return array
1393 */
1394 public function get_all_master_font_controls_ids( $options ) {
1395 $master_font_controls = array();
1396
1397 if ( empty( $options ) ) {
1398 return $master_font_controls;
1399 }
1400
1401 foreach ( $options as $option_id => $option_settings ) {
1402 if ( ! empty( $option_settings['type'] ) && 'font' === $option_settings['type'] ) {
1403 $master_font_controls[] = $option_id;
1404 }
1405 }
1406
1407 return $master_font_controls;
1408 }
1409
1410 /**
1411 * Add font palettes usage data to the site data sent to the cloud.
1412 *
1413 * @since 1.7.4
1414 *
1415 * @param array $site_data
1416 *
1417 * @return array
1418 */
1419 public function add_palettes_to_site_data( $site_data ) {
1420 if ( empty( $site_data['font_palettes'] ) ) {
1421 $site_data['font_palettes'] = array();
1422 }
1423
1424 // If others have added data before us, we will merge with it.
1425 $site_data['font_palettes'] = array_merge( $site_data['font_palettes'], array(
1426 'current' => $this->get_current_palette(),
1427 'variation' => $this->get_current_palette_variation(),
1428 'custom' => $this->is_using_custom_palette(),
1429 ) );
1430
1431 return $site_data;
1432 }
1433
1434 /**
1435 * Main Customify_Font_Palettes Instance
1436 *
1437 * Ensures only one instance of Customify_Font_Palettes is loaded or can be loaded.
1438 *
1439 * @since 1.7.4
1440 * @static
1441 *
1442 * @return Customify_Font_Palettes Main Customify_Font_Palettes instance
1443 */
1444 public static function instance() {
1445
1446 if ( is_null( self::$_instance ) ) {
1447 self::$_instance = new self();
1448 }
1449 return self::$_instance;
1450 } // End instance ()
1451
1452 /**
1453 * Cloning is forbidden.
1454 *
1455 * @since 1.7.4
1456 */
1457 public function __clone() {
1458
1459 _doing_it_wrong( __FUNCTION__,esc_html( __( 'Cheatin&#8217; huh?' ) ), null );
1460 } // End __clone ()
1461
1462 /**
1463 * Unserializing instances of this class is forbidden.
1464 *
1465 * @since 1.7.4
1466 */
1467 public function __wakeup() {
1468
1469 _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cheatin&#8217; huh?' ) ), null );
1470 } // End __wakeup ()
1471 }
1472
1473 endif;
1474