PluginProbe
Customify / 2.4.0
Customify v2.4.0
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
← All changes | features/class-Font_Selector.php +318 -175 1.5.2 → 2.4.0 View file →
@@ -17,85 +17,90 @@
17 17
18 18 function __construct() {
19 19 $this->theme_fonts = apply_filters( 'customify_theme_fonts', array() );
20 20
21 - $load_location = PixCustomifyPlugin()->get_plugin_setting( 'style_resources_location', 'wp_head' );
22 - add_action( $load_location, array( $this, 'output_font_dynamic_style' ), 999999999 );
23 - add_action( 'customify_font_family_before_options', array( $this, 'add_customify_theme_fonts' ), 11, 2 );
21 + $load_location = PixCustomifyPlugin()->settings->get_plugin_setting( 'style_resources_location', 'wp_head' );
22 + add_action( $load_location, array( $this, 'output_webfont_script' ), 99 );
23 + add_action( $load_location, array( $this, 'output_fonts_dynamic_style' ), 100 );
24 + add_action( 'customify_font_family_before_options', array( $this, 'add_customify_theme_fonts' ), 11, 1 );
24 25
25 - if ( PixCustomifyPlugin()->get_plugin_setting( 'enable_editor_style', true ) ) {
26 - add_action( 'admin_head', array( $this, 'add_customizer_settings_into_wp_editor' ) );
26 + if ( PixCustomifyPlugin()->settings->get_plugin_setting( 'enable_editor_style', true ) ) {
27 + add_action( 'admin_head', array( $this, 'script_to_add_customizer_settings_into_wp_editor' ) );
27 28 }
28 29
29 30 }
30 31
31 - function add_customizer_settings_into_wp_editor() {
32 + function script_to_add_customizer_settings_into_wp_editor() {
32 33
33 34 ob_start();
34 - $this->output_font_dynamic_style();
35 + $this->output_fonts_dynamic_style();
35 36
36 - $custom_css = ob_get_clean(); ?>
37 - <script type="text/javascript">
38 - /* <![CDATA[ */
39 - (function ($) {
40 - $(window).load(function () {
41 - /**
42 - * @param iframe_id the id of the frame you whant to append the style
43 - * @param style_element the style element you want to append
44 - */
45 - var append_script_to_iframe = function (ifrm_id, scriptEl) {
46 - var myIframe = document.getElementById(ifrm_id);
37 + $custom_css = ob_get_clean();
47 38
48 - var script = myIframe.contentWindow.document.createElement("script");
49 - script.type = "text/javascript";
50 - script.innerHTML = scriptEl.innerHTML;
39 + ob_start(); ?>
40 + (function ($) {
41 + $(window).load(function () {
42 + /**
43 + * @param iframe_id the id of the frame you want to append the style
44 + * @param style_element the style element you want to append
45 + */
46 + var append_script_to_iframe = function (ifrm_id, scriptEl) {
47 + var myIframe = document.getElementById(ifrm_id);
51 48
52 - myIframe.contentWindow.document.head.appendChild(script);
53 - };
49 + var script = myIframe.contentWindow.document.createElement("script");
50 + script.type = "text/javascript";
51 + script.innerHTML = scriptEl.innerHTML;
54 52
55 - var append_style_to_iframe = function (ifrm_id, styleElment) {
56 - var ifrm = window.frames[ifrm_id];
57 - ifrm = ( ifrm.contentDocument || ifrm.contentDocument || ifrm.document );
58 - var head = ifrm.getElementsByTagName('head')[0];
53 + myIframe.contentWindow.document.head.appendChild(script);
54 + };
59 55
60 - if (typeof styleElment !== "undefined") {
61 - head.appendChild(styleElment);
62 - }
63 - };
56 + var append_style_to_iframe = function (ifrm_id, styleElment) {
57 + var ifrm = window.frames[ifrm_id];
58 + if ( typeof ifrm === "undefined" ) {
59 + return;
60 + }
61 + ifrm = ( ifrm.contentDocument || ifrm.document );
62 + var head = ifrm.getElementsByTagName('head')[0];
64 63
65 - var xmlString = <?php echo json_encode( str_replace( "\n", "", $custom_css ) ); ?>,
66 - parser = new DOMParser(),
67 - doc = parser.parseFromString(xmlString, "text/html");
64 + if (typeof styleElment !== "undefined") {
65 + head.appendChild(styleElment);
66 + }
67 + };
68 68
69 - if (typeof window.frames['content_ifr'] !== 'undefined') {
69 + var xmlString = <?php echo json_encode( str_replace( "\n", "", $custom_css ) ); ?>,
70 + parser = new DOMParser(),
71 + doc = parser.parseFromString(xmlString, "text/html");
70 72
71 - $.each(doc.head.childNodes, function (key, el) {
72 - if (typeof el !== "undefined" && typeof el.tagName !== "undefined") {
73 + if (typeof window.frames['content_ifr'] !== 'undefined') {
73 74
74 - switch (el.tagName) {
75 - case 'STYLE' :
76 - append_style_to_iframe('content_ifr', el);
77 - break;
78 - case 'SCRIPT' :
79 - append_script_to_iframe('content_ifr', el);
80 - break;
81 - default:
82 - break;
83 - }
84 - }
85 - });
75 + $.each(doc.head.childNodes, function (key, el) {
76 + if (typeof el !== "undefined" && typeof el.tagName !== "undefined") {
77 +
78 + switch (el.tagName) {
79 + case 'STYLE' :
80 + append_style_to_iframe('content_ifr', el);
81 + break;
82 + case 'SCRIPT' :
83 + append_script_to_iframe('content_ifr', el);
84 + break;
85 + default:
86 + break;
87 + }
86 88 }
87 89 });
88 - })(jQuery);
89 - /* ]]> */
90 - </script>
91 - <?php }
90 + }
91 + });
92 + })(jQuery);
93 + <?php
94 + $script = ob_get_clean();
95 + wp_add_inline_script( 'editor', $script );
96 + }
92 97
93 98 public function get_theme_fonts() {
94 99 return $this->theme_fonts;
95 100 }
96 101
97 - function add_customify_theme_fonts( $active_font_family, $val ) {
102 + function add_customify_theme_fonts( $active_font_family ) {
98 103 //first get all the published custom fonts
99 104 if ( empty( $this->theme_fonts ) ) {
100 105 return;
101 106 }
@@ -103,9 +108,9 @@
103 108 echo '<optgroup label="' . esc_html__( 'Theme Fonts', 'customify' ) . '">';
104 109 foreach ( $this->theme_fonts as $font ) {
105 110 if ( ! empty( $font ) ) {
106 111 //display the select option's HTML
107 - Pix_Customize_Font_Control::output_font_option( $font['family'], $active_font_family, $font, 'theme_font' );
112 + Pix_Customize_Font_Control::output_font_option( $font, $active_font_family, 'theme_font' );
108 113 }
109 114 }
110 115 echo "</optgroup>";
111 116 }
@@ -119,29 +124,27 @@
119 124
120 125 return $to_return;
121 126 }
122 127
123 - function output_font_dynamic_style() {
128 + protected function get_fonts_args() {
124 129
130 + $args = array(
131 + 'google_families' => array(),
132 + 'local_families' => array(),
133 + 'local_srcs' => array(),
134 + );
135 +
125 136 /** @var PixCustomifyPlugin $local_plugin */
126 137 $local_plugin = PixCustomifyPlugin();
127 138
128 - self::$options_list = $local_plugin->get_options();
139 + self::$options_list = $local_plugin->get_options_details();
129 140
130 - $local_plugin->get_typography_fields( self::$options_list, 'type', 'font', self::$typo_settings );
141 + $local_plugin->customizer->get_typography_fields( self::$options_list, 'type', 'font', self::$typo_settings );
131 142
132 143 if ( empty( self::$typo_settings ) ) {
133 - return;
144 + return $args;
134 145 }
135 146
136 - $google_families = $local_families = '';
137 -
138 - $args = array(
139 - 'google_families' => '',
140 - 'local_families' => '',
141 - 'local_srcs' => '',
142 - );
143 -
144 147 foreach ( self::$typo_settings as $id => $font ) {
145 148 if ( isset ( $font['value'] ) ) {
146 149
147 150 $load_all_weights = false;
@@ -152,11 +155,11 @@
152 155 $value = $this->maybe_decode_value( $font['value'] );
153 156
154 157 $value = $this->validate_font_values( $value );
155 158
156 - // in case the value is still null, try default value(mostly for google fonts)
159 + // in case the value is still null, try default value (mostly for google fonts)
157 160 if ( ! is_array( $value ) || $value === null ) {
158 - $value = $local_plugin->get_font_defaults_value( str_replace( '"', '', $font['value'] ) );
161 + $value = $local_plugin->customizer->get_font_defaults_value( str_replace( '"', '', $font['value'] ) );
159 162 }
160 163
161 164 //bail if by this time we don't have a value of some sort
162 165 if ( empty( $value ) ) {
@@ -162,137 +165,177 @@
162 165 if ( empty( $value ) ) {
163 166 continue;
164 167 }
165 168
166 - //Handle special logic for when the $value array is not an associative array
169 + // Handle special logic for when the $value array is not an associative array
167 170 if ( ! $local_plugin->is_assoc( $value ) ) {
168 - $value = $local_plugin->process_a_not_associative_font_default( $value );
171 + $value = $local_plugin->customizer->standardize_non_associative_font_default( $value );
169 172 }
170 173
171 - if ( isset( $value['font_family'] ) && isset( $value['type'] ) && $value['type'] == 'google' ) {
172 - $args['google_families'] .= "'" . $value['font_family'];
174 + // If we have reached this far and we don't have a type, we will assume it's a google font.
175 + if ( ! isset( $value['type'] ) ) {
176 + $value['type'] = 'google';
177 + }
173 178
174 - if ( $load_all_weights && is_array( $value['variants'] ) ) {
175 - $args['google_families'] .= ":" . implode( ',', $value['variants'] );
176 - } elseif ( isset( $value['selected_variants'] ) && ! empty( $value['selected_variants'] ) ) {
179 + if ( isset( $this->theme_fonts[ $value['font_family'] ] ) ) {
180 +
181 +// $value['type'] = 'theme_font';
182 +// $args['local_srcs'] .= $this->theme_fonts[ $value['font_family'] ]['src'] . ',';
183 +// $value['variants'] = $this->theme_fonts[ $value['font_family'] ]['variants'];
184 +
185 + if ( false === array_search( $value['font_family'], $args['local_families'] ) ) {
186 + $args['local_families'][] = "'" . $value['font_family'] . "'";
187 + }
188 +
189 + if ( false === array_search( $this->theme_fonts[ $value['font_family'] ]['src'], $args['local_srcs'] ) ) {
190 + $args['local_srcs'][] = "'" . $this->theme_fonts[ $value['font_family'] ]['src'] . "'";
191 + }
192 + } elseif ( isset( $value['font_family'] ) && isset( $value['type'] ) && $value['type'] === 'google' ) {
193 + $family = "'" . $value['font_family'];
194 +
195 + if ( $load_all_weights && ! empty( $value['variants'] ) && is_array( $value['variants'] ) ) {
196 + $family .= ":" . implode( ',', $value['variants'] );
197 + } elseif ( ! empty( $value['selected_variants'] ) ) {
177 198 if ( is_array( $value['selected_variants'] ) ) {
178 - $args['google_families'] .= ":" . implode( ',', $value['selected_variants'] );
199 + $family .= ":" . implode( ',', $value['selected_variants'] );
179 200 } elseif ( is_string( $value['selected_variants'] ) || is_numeric( $value['selected_variants'] ) ) {
180 - $args['google_families'] .= ":" . $value['selected_variants'];
201 + $family .= ":" . $value['selected_variants'];
181 202 }
182 - } elseif ( isset( $value['variants'] ) && ! empty( $value['variants'] ) ) {
203 + } elseif ( ! empty( $value['variants'] ) ) {
183 204 if ( is_array( $value['variants'] ) ) {
184 - $args['google_families'] .= ":" . implode( ',', $value['variants'] );
205 + $family .= ":" . implode( ',', $value['variants'] );
185 206 } else {
186 - $args['google_families'] .= ":" . $value['variants'];
207 + $family .= ":" . $value['variants'];
187 208 }
188 209 }
189 210
190 - if ( isset( $value['selected_subsets'] ) && ! empty( $value['selected_subsets'] ) ) {
211 + if ( ! empty( $value['selected_subsets'] ) ) {
191 212 if ( is_array( $value['selected_subsets'] ) ) {
192 - $args['google_families'] .= ":" . implode( ',', $value['selected_subsets'] );
213 + $family .= ":" . implode( ',', $value['selected_subsets'] );
193 214 } else {
194 - $args['google_families'] .= ":" . $value['selected_subsets'];
215 + $family .= ":" . $value['selected_subsets'];
195 216 }
196 - } elseif ( isset( $value['subsets'] ) && ! empty( $value['subsets'] ) ) {
217 + } elseif ( ! empty( $value['subsets'] ) ) {
197 218 if ( is_array( $value['subsets'] ) ) {
198 - $args['google_families'] .= ":" . implode( ',', $value['subsets'] );
219 + $family .= ":" . implode( ',', $value['subsets'] );
199 220 } else {
200 - $args['google_families'] .= ":" . $value['subsets'];
221 + $family .= ":" . $value['subsets'];
201 222 }
202 223 }
203 224
204 - $args['google_families'] .= '\',';
205 - } elseif ( isset( $this->theme_fonts[ $value['font_family'] ] ) ) {
225 + $family .= "'";
206 226
207 -// $value['type'] = 'theme_font';
208 -// $args['local_srcs'] .= $this->theme_fonts[ $value['font_family'] ]['src'] . ',';
209 -// $value['variants'] = $this->theme_fonts[ $value['font_family'] ]['variants'];
210 -
211 - if ( false === strpos( $args['local_families'], $value['font_family'] ) ) {
212 - $args['local_families'] .= "'" . $value['font_family'] . "',";
213 - }
214 -
215 - if ( false === strpos( $args['local_srcs'], $this->theme_fonts[ $value['font_family'] ]['src'] ) ) {
216 - $args['local_srcs'] .= "'" . $this->theme_fonts[ $value['font_family'] ]['src'] . "',";
217 - }
227 + $args['google_families'][] = $family;
218 228 }
219 229 }
220 230 }
221 231
222 - if ( ( ! empty ( $args['local_families'] ) || ! empty ( $args['google_families'] ) ) && PixCustomifyPlugin()->get_plugin_setting( 'typography', '1' ) && PixCustomifyPlugin()->get_plugin_setting( 'typography_google_fonts', 1 ) ) {
223 - $this->display_webfont_script( $args );
232 + $args = array(
233 + 'google_families' => array_unique( $args['google_families'] ),
234 + 'local_families' => array_unique( $args['local_families'] ),
235 + 'local_srcs' => array_unique( $args['local_srcs'] ),
236 + );
237 +
238 + return $args;
239 + }
240 +
241 + function output_fonts_dynamic_style() {
242 +
243 + /** @var PixCustomifyPlugin $local_plugin */
244 + $local_plugin = PixCustomifyPlugin();
245 +
246 + self::$options_list = $local_plugin->get_options_details();
247 + $local_plugin->customizer->get_typography_fields( self::$options_list, 'type', 'font', self::$typo_settings );
248 +
249 + if ( empty( self::$typo_settings ) ) {
250 + return;
224 251 }
225 252
253 + $output = '';
254 +
226 255 foreach ( self::$typo_settings as $key => $font ) {
227 - if ( empty( $font['selector'] ) || empty( $font['value'] ) ) {
256 + $font_output = $this->get_font_style( $font );
257 + if ( empty( $font_output ) ) {
228 258 continue;
229 259 }
230 - $value = $this->maybe_decode_value( $font['value'] );
231 260
232 - if ( $value === null ) {
233 - $value = $local_plugin->get_font_defaults_value( $font['value'] );
234 - }
261 + $output .= $font_output . PHP_EOL;
235 262
236 - // shim the old case when the default was only the font name
237 - if ( is_string( $value ) && ! empty( $value ) ) {
238 - $value = array( 'font_family' => $value );
263 + // If we are in a Customizer context we will output CSS rules grouped so we can target them.
264 + // In the frontend we want a whole bulk.
265 + if ( isset( $GLOBALS['wp_customize'] ) ) { ?>
266 + <style id="customify_font_output_for_<?php echo sanitize_html_class( $key ); ?>">
267 + <?php echo $font_output; ?>
268 + </style><?php
239 269 }
240 -
241 - //Handle special logic for when the $value array is not an associative array
242 - if ( ! $local_plugin->is_assoc( $value ) ) {
243 - $value = $local_plugin->process_a_not_associative_font_default( $value );
244 - }
245 -
246 - $this->output_font_style( $key, $font, $value );
247 270 }
248 271
249 272 // in customizer the CSS is printed per option, in front-end we need to print them in bulk
250 273 if ( ! isset( $GLOBALS['wp_customize'] ) ) { ?>
251 -<style id="customify_fonts_output">
252 -<?php echo join( "\n", $this->customify_CSS_output ); ?>
253 -</style><?php
254 - return;
274 + <style id="customify_fonts_output">
275 + <?php echo $output; ?>
276 + </style><?php
255 277 }
256 278 }
257 279
258 - function display_webfont_script( $args ) { ?>
259 - <script type="text/javascript">
260 - var customify_font_loader = function () {
261 - var webfontargs = {
262 - classes: false,
263 - events: false
264 - };
265 - <?php if ( ! empty( $args['google_families'] ) ) { ?>
266 - webfontargs.google = {families: [<?php echo( rtrim( $args['google_families'], ',' ) ); ?>]};
267 - <?php }
268 - if ( ! empty( $args['local_families'] ) && ! empty( $args['local_srcs'] ) ) { ?>
269 - webfontargs.custom = {
270 - families: [<?php echo( rtrim( $args['local_families'], ',' ) ); ?>],
271 - urls: [<?php echo rtrim( $args['local_srcs'], ',' ) ?>]
272 - };
273 - <?php } ?>
274 - WebFont.load(webfontargs);
275 - };
280 + function get_fonts_dynamic_style() {
276 281
277 - if (typeof WebFont !== 'undefined') { <?php // if there is a WebFont object, use it ?>
278 - customify_font_loader();
279 - } else { <?php // basically when we don't have the WebFont object we create the google script dynamically ?>
280 - var tk = document.createElement('script');
281 - tk.src = '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
282 - tk.type = 'text/javascript';
282 + $output = '';
283 283
284 - tk.onload = tk.onreadystatechange = function () {
285 - customify_font_loader();
286 - };
287 - var s = document.getElementsByTagName('script')[0];
288 - s.parentNode.insertBefore(tk, s);
284 + /** @var PixCustomifyPlugin $local_plugin */
285 + $local_plugin = PixCustomifyPlugin();
286 +
287 + self::$options_list = $local_plugin->get_options_details();
288 + $local_plugin->customizer->get_typography_fields( self::$options_list, 'type', 'font', self::$typo_settings );
289 +
290 + if ( empty( self::$typo_settings ) ) {
291 + return $output;
292 + }
293 +
294 + foreach ( self::$typo_settings as $key => $font ) {
295 +
296 + $font_output = $this->get_font_style( $font );
297 + if ( empty( $font_output ) ) {
298 + continue;
289 299 }
290 - </script>
291 - <?php
300 +
301 + $output .= $font_output . PHP_EOL;
302 + }
303 +
304 + return $output;
292 305 }
293 306
294 - function output_font_style( $field, $font, $value ) {
307 + function get_font_style( $font ) {
308 +
309 + if ( ! isset( $font['selector'] ) ) {
310 + return '';
311 + }
312 +
313 + $font['selector'] = apply_filters( 'customify_font_css_selector', $font['selector'], $font );
314 +
315 + if ( empty( $font['selector'] ) || empty( $font['value'] ) ) {
316 + return '';
317 + }
318 +
319 + /** @var PixCustomifyPlugin $local_plugin */
320 + $local_plugin = PixCustomifyPlugin();
321 +
322 + $value = $this->maybe_decode_value( $font['value'] );
323 +
324 + if ( $value === null ) {
325 + $value = $local_plugin->customizer->get_font_defaults_value( $font['value'] );
326 + }
327 +
328 + // shim the old case when the default was only the font name
329 + if ( is_string( $value ) && ! empty( $value ) ) {
330 + $value = array( 'font_family' => $value );
331 + }
332 +
333 + // Handle special logic for when the $value array is not an associative array
334 + if ( ! $local_plugin->is_assoc( $value ) ) {
335 + $value = $local_plugin->customizer->standardize_non_associative_font_default( $value );
336 + }
337 +
295 338 $value = $this->validate_font_values( $value );
296 339 // some sanitizing
297 340 $load_all_weights = false;
298 341 if ( isset( $font['load_all_weights'] ) && $font['load_all_weights'] == 'true' ) {
@@ -311,10 +354,10 @@
311 354
312 355 if ( isset( $font['callback'] ) && function_exists( $font['callback'] ) ) {
313 356 $output = call_user_func( $font['callback'], $value, $font );
314 357 echo $output;
315 - } else {
316 - echo $font['selector'] . " {";
358 + } elseif ( isset( $font['selector'] ) ) {
359 + echo $font['selector'] . " {" . PHP_EOL;
317 360
318 361 // First handle the case where we have the font-family in the selected variant (usually this means a custom font from our Fonto plugin)
319 362 if ( ! empty( $selected_variant ) && is_array( $selected_variant ) && ! empty( $selected_variant['font-family'] ) ) {
320 363 //the variant's font-family
@@ -368,24 +411,73 @@
368 411 $this->display_property( 'font-family', $value['font-family'] );
369 412 }
370 413
371 414 if ( ! empty( $value['font_weight'] ) ) {
372 - $italic_font = $this->display_weight_property( $value['font_weight'] );
415 + $this->display_weight_property( $value['font_weight'] );
373 416 }
374 417
375 418 if ( ! empty( $value['font_size'] ) ) {
376 - $unit = $this->get_field_unit( $font, 'font-size' );
377 - $this->display_property( 'font-size', $value['font_size'], $unit );
419 + // If the value already contains a unit, go with that.
420 + // We also handle receiving the value in a standardized format ( array with 'value' and 'unit').
421 + $font_size = $value['font_size'];
422 + $unit = '';
423 + if ( is_numeric( $value['font_size'] ) ) {
424 + $unit = $this->get_field_unit( $font, 'font-size' );
425 + } elseif ( is_array( $value['font_size'] ) ) {
426 + if ( isset( $value['font_size']['unit'] ) ) {
427 + $unit = $value['font_size']['unit'];
428 + }
429 +
430 + if ( isset( $value['font_size']['value'] ) ) {
431 + $font_size = $value['font_size']['value'];
432 + }
433 + }
434 +
435 + if ( isset( $value['font_size']['unit'] ) && $value['font_size']['unit'] == 'em' && $value['font_size']['value'] >= 9 ) {
436 + $value['font_size']['unit'] = 'px';
437 + }
438 +
439 + $this->display_property( 'font-size', $font_size, $unit );
378 440 }
379 441
380 - if ( ! empty( $value['line_height'] ) ) {
381 - $unit = $this->get_field_unit( $font, 'line-height' );
382 - $this->display_property( 'line-height', $value['line_height'], $unit );
442 + if ( isset( $value['line_height'] ) ) {
443 + // If the value already contains a unit, go with that.
444 + // We also handle receiving the value in a standardized format ( array with 'value' and 'unit').
445 + $line_height = $value['line_height'];
446 + $unit = '';
447 + if ( is_numeric( $value['line_height'] ) ) {
448 + $unit = $this->get_field_unit( $font, 'line-height' );
449 + } elseif ( is_array( $value['line_height'] ) ) {
450 + if ( isset( $value['line_height']['unit'] ) ) {
451 + $unit = $value['line_height']['unit'];
452 + }
453 +
454 + if ( isset( $value['line_height']['value'] ) ) {
455 + $line_height = $value['line_height']['value'];
456 + }
457 + }
458 +
459 + $this->display_property( 'line-height', $line_height, $unit );
383 460 }
384 461
385 - if ( ! empty( $value['letter_spacing'] ) ) {
386 - $unit = $this->get_field_unit( $font, 'letter-spacing' );
387 - $this->display_property( 'letter-spacing', $value['letter_spacing'], $unit );
462 + if ( isset( $value['letter_spacing'] ) ) {
463 + // If the value already contains a unit, go with that.
464 + // We also handle receiving the value in a standardized format ( array with 'value' and 'unit').
465 + $letter_spacing = $value['letter_spacing'];
466 + $unit = '';
467 + if ( is_numeric( $value['letter_spacing'] ) ) {
468 + $unit = $this->get_field_unit( $font, 'letter-spacing' );
469 + } elseif ( is_array( $value['letter_spacing'] ) ) {
470 + if ( isset( $value['letter_spacing']['unit'] ) ) {
471 + $unit = $value['letter_spacing']['unit'];
472 + }
473 +
474 + if ( isset( $value['letter_spacing']['value'] ) ) {
475 + $letter_spacing = $value['letter_spacing']['value'];
476 + }
477 + }
478 +
479 + $this->display_property( 'letter-spacing', $letter_spacing, $unit );
388 480 }
389 481
390 482 if ( ! empty( $value['text_align'] ) ) {
391 483 $this->display_property( 'text-align', $value['text_align'] );
@@ -402,16 +494,67 @@
402 494 }
403 495
404 496 $CSS = ob_get_clean();
405 497
406 - if ( isset( $GLOBALS['wp_customize'] ) ) { ?>
407 - <style id="customify_font_output_for_<?php echo $field; ?>">
408 - <?php echo $CSS ?>
409 - </style><?php
410 - return;
411 - } else {
412 - $this->customify_CSS_output[] = $CSS;
498 + return $CSS;
499 + }
500 +
501 + function output_webfont_script() {
502 + $script = $this->get_fonts_dynamic_script();
503 + if ( ! empty( $script ) ) { ?>
504 + <script type="text/javascript">
505 + <?php echo $script; ?>
506 + </script>
507 + <?php }
508 + }
509 +
510 + function get_fonts_dynamic_script() {
511 + $args = $this->get_fonts_args();
512 +
513 + if ( ( empty ( $args['local_families'] ) && empty ( $args['google_families'] ) )
514 + || ! PixCustomifyPlugin()->settings->get_plugin_setting( 'typography', '1' )
515 + || ! PixCustomifyPlugin()->settings->get_plugin_setting( 'typography_google_fonts', 1 ) ) {
516 + return '';
413 517 }
518 +
519 + ob_start(); ?>
520 +function customify_font_loader() {
521 + var webfontargs = {
522 + classes: false,
523 + events: false
524 + };
525 + <?php if ( ! empty( $args['google_families'] ) ) { ?>
526 + webfontargs.google = {
527 + families: [<?php echo join( ',', $args['google_families'] ); ?>]
528 + };
529 + <?php }
530 + if ( ! empty( $args['local_families'] ) && ! empty( $args['local_srcs'] ) ) { ?>
531 + webfontargs.custom = {
532 + families: [<?php echo join( ',', $args['local_families'] ); ?>],
533 + urls: [<?php echo join( ',', $args['local_srcs'] ) ?>]
534 + };
535 + <?php } ?>
536 + WebFont.load(webfontargs);
537 +};
538 +
539 +if (typeof WebFont !== 'undefined') {
540 + customify_font_loader();
541 +} else {
542 + var tk = document.createElement('script');
543 + tk.src = '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
544 + tk.type = 'text/javascript';
545 +
546 + tk.onload = tk.onreadystatechange = function () {
547 + customify_font_loader();
548 + };
549 +
550 + var s = document.getElementsByTagName('script')[0];
551 + s.parentNode.insertBefore(tk, s);
552 +}
553 + <?php
554 + $output = ob_get_clean();
555 +
556 + return apply_filters( 'customify_fonts_webfont_script', $output );
414 557 }
415 558
416 559 function get_field_unit( $font, $field ) {
417 560
@@ -454,9 +597,9 @@
454 597
455 598 }
456 599
457 600 function display_property( $property, $value, $unit = '' ) {
458 - echo "\n" . $property . ": " . $value . $unit . ";\n";
601 + echo $property . ": " . $value . $unit . ";\n";
459 602 }
460 603
461 604 // well weight sometimes comes from google as 600italic which in CSS syntax should come in two separate properties
462 605 function display_weight_property( $value ) {
@@ -464,13 +607,13 @@
464 607
465 608 if ( strpos( $value, 'italic' ) !== false ) {
466 609
467 610 $value = str_replace( 'italic', '', $value );
468 - echo "\n" . 'font-weight' . ": " . $value . ";\n";
469 - echo "\n" . 'font-style' . ": italic;\n";
611 + echo 'font-weight' . ": " . $value . ";\n";
612 + echo 'font-style' . ": italic;\n";
470 613 $has_style = true;
471 614 } else {
472 - echo "\n" . 'font-weight' . ": " . $value . ";\n";
615 + echo 'font-weight' . ": " . $value . ";\n";
473 616 }
474 617
475 618
476 619 return $has_style;