PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
← All changes | classes/class-fonts.php +322 -305 2.25.03.7.2 View file →
@@ -10,359 +10,376 @@
10 10 /**
11 11 * GhostKit_Fonts
12 12 */
13 13 class GhostKit_Fonts {
14 - /**
15 - * GhostKit_Fonts constructor.
16 - */
17 - public function __construct() {
18 - add_filter( 'gkt_fonts_list', array( $this, 'add_google_fonts' ) );
19 - add_filter( 'gkt_fonts_list', array( $this, 'add_default_site_fonts' ), 9 );
14 + /**
15 + * GhostKit_Fonts constructor.
16 + */
17 + public function __construct() {
18 + add_action( 'init', array( $this, 'enqueue_fonts' ), 20 );
19 + add_filter( 'gkt_fonts_list', array( $this, 'add_default_site_fonts' ), 9 );
20 + add_filter( 'gkt_fonts_list', array( $this, 'add_google_fonts' ) );
21 + }
20 22
21 - // enqueue fonts.
22 - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_all_fonts_assets' ), 12 );
23 - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_all_fonts_assets' ), 12 );
24 - }
23 + /**
24 + * Enqueue fonts.
25 + *
26 + * @return void
27 + */
28 + public function enqueue_fonts() {
29 + add_action( 'enqueue_block_assets', array( $this, 'enqueue_all_fonts_assets' ), 12 );
30 + }
25 31
26 - /**
27 - * Enqueue frontend & editor assets
28 - */
29 - public function enqueue_all_fonts_assets() {
30 - $fonts = $this->get_font_loader_list();
32 + /**
33 + * Enqueue frontend & editor assets
34 + */
35 + public function enqueue_all_fonts_assets() {
36 + $fonts = $this->get_font_loader_list();
31 37
32 - if ( ( is_admin() || ! empty( $fonts ) ) && isset( $fonts['google-fonts'] ) && ! empty( $fonts['google-fonts'] ) ) {
33 - $families = array();
38 + if ( ( is_admin() || ! empty( $fonts ) ) && isset( $fonts['google-fonts'] ) && ! empty( $fonts['google-fonts'] ) ) {
39 + $families = array();
34 40
35 - foreach ( $fonts['google-fonts'] as $font => $font_data ) {
36 - $family = $font;
41 + foreach ( $fonts['google-fonts'] as $font => $font_data ) {
42 + $family = $font;
37 43
38 - if ( isset( $font_data['widths'] ) && ! empty( $font_data['widths'] ) ) {
39 - $weights = array();
44 + if ( isset( $font_data['widths'] ) && ! empty( $font_data['widths'] ) ) {
45 + $weights = array();
40 46
41 - foreach ( $font_data['widths'] as $weight ) {
42 - $weights[] = $weight;
43 - }
47 + foreach ( $font_data['widths'] as $weight ) {
48 + $weights[] = $weight;
49 + }
44 50
45 - $family .= ':' . implode( ',', $weights );
46 - }
51 + $family .= ':' . implode( ',', $weights );
52 + }
47 53
48 - $families[] = $family;
49 - }
54 + $families[] = $family;
55 + }
50 56
51 - $query_args = array(
52 - 'family' => implode( '|', $families ),
53 - 'display' => 'swap',
54 - );
57 + $query_args = array(
58 + 'family' => implode( '|', $families ),
59 + 'display' => 'swap',
60 + );
55 61
56 - wp_enqueue_style( 'ghostkit-fonts-google', add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ), array(), '2.25.0' );
57 - }
58 - }
62 + wp_enqueue_style( 'ghostkit-fonts-google', add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ), array(), GHOSTKIT_VERSION );
63 + }
64 + }
59 65
60 - /**
61 - * Create Font Loader List for webfont-loader.
62 - *
63 - * @return array - Font Loader List.
64 - */
65 - public function get_font_loader_list() {
66 - $post_id = null;
67 - $fonts_list = apply_filters( 'gkt_fonts_list', array() );
68 - $default_typography = apply_filters( 'gkt_custom_typography', array() );
69 - $fonts = array();
70 - $unique_fonts = array();
71 - $webfont_list = array();
72 - $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
73 - $is_admin_editor = is_admin() && $screen && $screen->is_block_editor;
66 + /**
67 + * Create Font Loader List for webfont-loader.
68 + *
69 + * @return array - Font Loader List.
70 + */
71 + public function get_font_loader_list() {
72 + $post_id = null;
73 + $fonts_list = apply_filters( 'gkt_fonts_list', array() );
74 + $default_typography = apply_filters( 'gkt_custom_typography', array() );
75 + $fonts = array();
76 + $unique_fonts = array();
77 + $webfont_list = array();
78 + $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
79 + $is_admin_editor = is_admin() && $screen && $screen->is_block_editor;
74 80
75 - if ( is_singular() ) {
76 - $post_id = get_the_ID();
77 - } elseif ( $is_admin_editor ) {
78 - global $post;
79 - $post_id = isset( $post->ID ) ? $post->ID : null;
80 - }
81 + if ( is_singular() ) {
82 + $post_id = get_the_ID();
83 + } elseif ( $is_admin_editor ) {
84 + global $post;
85 + $post_id = isset( $post->ID ) ? $post->ID : null;
86 + }
81 87
82 - $is_single = is_singular() && $post_id;
83 - $is_admin_editor = $is_admin_editor && $post_id;
84 - $additional_font_weights = array();
88 + $is_single = is_singular() && $post_id;
89 + $is_admin_editor = $is_admin_editor && $post_id;
90 + $additional_font_weights = array();
85 91
86 - // Default Typography.
87 - if ( ! empty( $default_typography ) ) {
88 - // Global Typography.
89 - $global_typography = get_option( 'ghostkit_typography', array() );
90 - if ( isset( $global_typography['ghostkit_typography'] ) && $global_typography['ghostkit_typography'] ) {
91 - $global_typography = json_decode( $global_typography['ghostkit_typography'], true );
92 - }
93 - if ( ! is_array( $global_typography ) ) {
94 - $global_typography = array();
95 - }
92 + // Default Typography.
93 + if ( ! empty( $default_typography ) ) {
94 + // Global Typography.
95 + $global_typography = get_option( 'ghostkit_typography', array() );
96 + if ( isset( $global_typography['ghostkit_typography'] ) && $global_typography['ghostkit_typography'] ) {
97 + $global_typography = json_decode( $global_typography['ghostkit_typography'], true );
98 + }
99 + if ( ! is_array( $global_typography ) ) {
100 + $global_typography = array();
101 + }
96 102
97 - // Meta post Typography.
98 - $meta_typography = array();
99 - if ( $is_single || $is_admin_editor ) {
100 - $meta_typography = get_post_meta( $post_id, 'ghostkit_typography', true );
103 + // Meta post Typography.
104 + $meta_typography = array();
105 + if ( $is_single || $is_admin_editor ) {
106 + $meta_typography = get_post_meta( $post_id, 'ghostkit_typography', true );
101 107
102 - if ( ! empty( $meta_typography ) ) {
103 - $meta_typography = json_decode( $meta_typography, true );
104 - }
105 - if ( ! is_array( $meta_typography ) ) {
106 - $meta_typography = array();
107 - }
108 - }
108 + if ( ! empty( $meta_typography ) ) {
109 + $meta_typography = json_decode( $meta_typography, true );
110 + }
111 + if ( ! is_array( $meta_typography ) ) {
112 + $meta_typography = array();
113 + }
114 + }
109 115
110 - // Go through all defaults and prepare full fonts list.
111 - foreach ( $default_typography as $key => $typography ) {
112 - $result = array();
116 + // Go through all defaults and prepare full fonts list.
117 + foreach ( $default_typography as $key => $typography ) {
118 + $result = array();
113 119
114 - // Default data.
115 - if (
116 - isset( $typography['defaults']['font-family'] ) &&
117 - ! empty( $typography['defaults']['font-family'] ) &&
118 - isset( $typography['defaults']['font-family-category'] ) &&
119 - ! empty( $typography['defaults']['font-family-category'] )
120 - ) {
121 - $weight = '';
122 - if ( isset( $typography['defaults']['font-weight'] ) && ! empty( $typography['defaults']['font-weight'] ) ) {
123 - $weight = $typography['defaults']['font-weight'];
124 - }
120 + // Default data.
121 + if (
122 + isset( $typography['defaults']['font-family'] ) &&
123 + ! empty( $typography['defaults']['font-family'] ) &&
124 + isset( $typography['defaults']['font-family-category'] ) &&
125 + ! empty( $typography['defaults']['font-family-category'] )
126 + ) {
127 + $weight = '';
128 + if ( isset( $typography['defaults']['font-weight'] ) && ! empty( $typography['defaults']['font-weight'] ) ) {
129 + $weight = $typography['defaults']['font-weight'];
130 + }
125 131
126 - // TODO: add additional_font_weights option support for typography React component.
127 - if ( isset( $typography['additional_font_weights'] ) && ! empty( $typography['additional_font_weights'] ) ) {
128 - $additional_font_weights[ $key ] = $typography['additional_font_weights'];
129 - }
132 + // TODO: add additional_font_weights option support for typography React component.
133 + if ( isset( $typography['additional_font_weights'] ) && ! empty( $typography['additional_font_weights'] ) ) {
134 + $additional_font_weights[ $key ] = $typography['additional_font_weights'];
135 + }
130 136
131 - $result = array(
132 - 'family' => $typography['defaults']['font-family-category'],
133 - 'label' => $typography['defaults']['font-family'],
134 - 'weight' => $weight,
135 - 'typography' => $key,
136 - );
137 - }
137 + $result = array(
138 + 'family' => $typography['defaults']['font-family-category'],
139 + 'label' => $typography['defaults']['font-family'],
140 + 'weight' => $weight,
141 + 'typography' => $key,
142 + );
143 + }
138 144
139 - // Global data.
140 - if (
141 - isset( $global_typography[ $key ]['fontFamily'] ) &&
142 - ! empty( $global_typography[ $key ]['fontFamily'] ) &&
143 - isset( $global_typography[ $key ]['fontFamilyCategory'] ) &&
144 - ! empty( $global_typography[ $key ]['fontFamilyCategory'] )
145 - ) {
146 - $weight = '';
147 - if ( isset( $global_typography[ $key ]['fontWeight'] ) && ! empty( $global_typography[ $key ]['fontWeight'] ) ) {
148 - $weight = $global_typography[ $key ]['fontWeight'];
149 - }
145 + // Global data.
146 + if (
147 + isset( $global_typography[ $key ]['fontFamily'] ) &&
148 + ! empty( $global_typography[ $key ]['fontFamily'] ) &&
149 + isset( $global_typography[ $key ]['fontFamilyCategory'] ) &&
150 + ! empty( $global_typography[ $key ]['fontFamilyCategory'] )
151 + ) {
152 + $weight = '';
153 + if ( isset( $global_typography[ $key ]['fontWeight'] ) && ! empty( $global_typography[ $key ]['fontWeight'] ) ) {
154 + $weight = $global_typography[ $key ]['fontWeight'];
155 + }
150 156
151 - $result = array(
152 - 'family' => $global_typography[ $key ]['fontFamilyCategory'],
153 - 'label' => $global_typography[ $key ]['fontFamily'],
154 - 'weight' => $weight,
155 - 'typography' => $key,
156 - );
157 - }
157 + $result = array(
158 + 'family' => $global_typography[ $key ]['fontFamilyCategory'],
159 + 'label' => $global_typography[ $key ]['fontFamily'],
160 + 'weight' => $weight,
161 + 'typography' => $key,
162 + );
163 + }
158 164
159 - // Meta data.
160 - if (
161 - isset( $meta_typography[ $key ]['fontFamily'] ) &&
162 - ! empty( $meta_typography[ $key ]['fontFamily'] ) &&
163 - isset( $meta_typography[ $key ]['fontFamilyCategory'] ) &&
164 - ! empty( $meta_typography[ $key ]['fontFamilyCategory'] )
165 - ) {
166 - $weight = '';
167 - if ( isset( $meta_typography[ $key ]['fontWeight'] ) && ! empty( $meta_typography[ $key ]['fontWeight'] ) ) {
168 - $weight = $meta_typography[ $key ]['fontWeight'];
169 - }
165 + // Meta data.
166 + if (
167 + isset( $meta_typography[ $key ]['fontFamily'] ) &&
168 + ! empty( $meta_typography[ $key ]['fontFamily'] ) &&
169 + isset( $meta_typography[ $key ]['fontFamilyCategory'] ) &&
170 + ! empty( $meta_typography[ $key ]['fontFamilyCategory'] )
171 + ) {
172 + $weight = '';
173 + if ( isset( $meta_typography[ $key ]['fontWeight'] ) && ! empty( $meta_typography[ $key ]['fontWeight'] ) ) {
174 + $weight = $meta_typography[ $key ]['fontWeight'];
175 + }
170 176
171 - $result = array(
172 - 'family' => $meta_typography[ $key ]['fontFamilyCategory'],
173 - 'label' => $meta_typography[ $key ]['fontFamily'],
174 - 'weight' => $weight,
175 - 'typography' => $key,
176 - );
177 - }
177 + $result = array(
178 + 'family' => $meta_typography[ $key ]['fontFamilyCategory'],
179 + 'label' => $meta_typography[ $key ]['fontFamily'],
180 + 'weight' => $weight,
181 + 'typography' => $key,
182 + );
183 + }
178 184
179 - // Save result.
180 - if ( isset( $result['family'] ) && $result['family'] && isset( $result['label'] ) && $result['label'] ) {
181 - $fonts[ $key ] = $result;
182 - }
183 - }
184 - }
185 + // Save result.
186 + if ( isset( $result['family'] ) && $result['family'] && isset( $result['label'] ) && $result['label'] ) {
187 + $fonts[ $key ] = $result;
188 + }
189 + }
190 + }
185 191
186 - // clear array to unique.
187 - $unique_fonts = array_map( 'unserialize', array_unique( array_map( 'serialize', $fonts ) ) );
192 + // clear array to unique.
193 + $unique_fonts = array_map( 'unserialize', array_unique( array_map( 'serialize', $fonts ) ) );
188 194
189 - foreach ( $unique_fonts as $font ) {
190 - if ( isset( $font['family'] ) && ! empty( $font['family'] ) && array_key_exists( $font['family'], $fonts_list ) ) {
191 - foreach ( $fonts_list[ $font['family'] ]['fonts'] as $find_font ) {
192 - if ( $font['label'] === $find_font['name'] ) {
193 - $weights = array();
194 - $weight = ( isset( $font['weight'] ) && ! empty( $font['weight'] ) ) ? $font['weight'] : '';
195 - $widths = ( isset( $find_font['widths'] ) && ! empty( $find_font['widths'] ) ) ? $find_font['widths'] : array();
196 - $category = ( isset( $find_font['category'] ) && ! empty( $find_font['category'] ) ) ? $find_font['category'] : '';
197 - $subsets = ( isset( $find_font['subsets'] ) && ! empty( $find_font['subsets'] ) ) ? $find_font['subsets'] : '';
195 + foreach ( $unique_fonts as $font ) {
196 + if ( isset( $font['family'] ) && ! empty( $font['family'] ) && array_key_exists( $font['family'], $fonts_list ) ) {
197 + foreach ( $fonts_list[ $font['family'] ]['fonts'] as $find_font ) {
198 + if ( $font['label'] === $find_font['name'] ) {
199 + $weights = array();
200 + $weight = ( isset( $font['weight'] ) && ! empty( $font['weight'] ) ) ? $font['weight'] : '';
201 + $widths = ( isset( $find_font['widths'] ) && ! empty( $find_font['widths'] ) ) ? $find_font['widths'] : array();
202 + $category = ( isset( $find_font['category'] ) && ! empty( $find_font['category'] ) ) ? $find_font['category'] : '';
203 + $subsets = ( isset( $find_font['subsets'] ) && ! empty( $find_font['subsets'] ) ) ? $find_font['subsets'] : '';
198 204
199 - if ( isset( $additional_font_weights ) && ! empty( $additional_font_weights ) ) {
200 - foreach ( $additional_font_weights as $key => $additional_font_weight ) {
201 - if ( $key === $font['typography'] ) {
202 - $font_weights = $additional_font_weight;
203 - }
204 - }
205 - }
205 + if ( isset( $additional_font_weights ) && ! empty( $additional_font_weights ) ) {
206 + foreach ( $additional_font_weights as $key => $additional_font_weight ) {
207 + if ( $key === $font['typography'] ) {
208 + $font_weights = $additional_font_weight;
209 + }
210 + }
211 + }
206 212
207 - if ( isset( $font_weights ) && ! empty( $font_weights ) && is_array( $font_weights ) ) {
208 - $insert_weights = array();
209 - if ( '' !== $weight ) {
210 - $weight = str_replace( 'i', '', $weight );
211 - $insert_weights[] = $weight;
212 - $insert_weights[] = $weight . 'i';
213 - }
214 - $insert_weights = array_merge( $insert_weights, $font_weights );
215 - foreach ( $insert_weights as $insert_weight ) {
216 - if ( array_search( $insert_weight, $widths, true ) !== false ) {
217 - $weights[] = $insert_weight;
218 - }
219 - }
220 - } elseif ( '' !== $weight ) {
221 - $weight = str_replace( 'i', '', $weight );
213 + if ( isset( $font_weights ) && ! empty( $font_weights ) && is_array( $font_weights ) ) {
214 + $insert_weights = array();
215 + if ( '' !== $weight ) {
216 + $weight = str_replace( 'i', '', $weight );
217 + $insert_weights[] = $weight;
218 + $insert_weights[] = $weight . 'i';
219 + }
220 + $insert_weights = array_merge( $insert_weights, $font_weights );
221 + foreach ( $insert_weights as $insert_weight ) {
222 + if ( array_search( $insert_weight, $widths, true ) !== false ) {
223 + $weights[] = $insert_weight;
224 + }
225 + }
226 + } elseif ( '' !== $weight ) {
227 + $weight = str_replace( 'i', '', $weight );
222 228
223 - if ( '600' !== $weight &&
224 - '700' !== $weight &&
225 - '800' !== $weight &&
226 - '900' !== $weight ) {
229 + if ( '600' !== $weight &&
230 + '700' !== $weight &&
231 + '800' !== $weight &&
232 + '900' !== $weight ) {
227 233
228 - $insert_weights = array(
229 - $weight,
230 - $weight . 'i',
231 - '700',
232 - '700i',
233 - );
234 + $insert_weights = array(
235 + $weight,
236 + $weight . 'i',
237 + '700',
238 + '700i',
239 + );
234 240
235 - foreach ( $insert_weights as $insert_weight ) {
236 - if ( array_search( $insert_weight, $widths, true ) !== false ) {
237 - $weights[] = $insert_weight;
238 - }
239 - }
240 - } else {
241 - $insert_weights = array(
242 - $weight,
243 - $weight . 'i',
244 - );
241 + foreach ( $insert_weights as $insert_weight ) {
242 + if ( array_search( $insert_weight, $widths, true ) !== false ) {
243 + $weights[] = $insert_weight;
244 + }
245 + }
246 + } else {
247 + $insert_weights = array(
248 + $weight,
249 + $weight . 'i',
250 + );
245 251
246 - foreach ( $insert_weights as $insert_weight ) {
247 - if ( array_search( $insert_weight, $widths, true ) !== false ) {
248 - $weights[] = $insert_weight;
249 - }
250 - }
251 - }
252 - } else {
253 - $insert_weights = array(
254 - '400',
255 - '400i',
256 - '700',
257 - '700i',
258 - );
252 + foreach ( $insert_weights as $insert_weight ) {
253 + if ( array_search( $insert_weight, $widths, true ) !== false ) {
254 + $weights[] = $insert_weight;
255 + }
256 + }
257 + }
258 + } else {
259 + $insert_weights = array(
260 + '400',
261 + '400i',
262 + '700',
263 + '700i',
264 + );
259 265
260 - foreach ( $insert_weights as $insert_weight ) {
261 - if ( array_search( $insert_weight, $widths, true ) !== false ) {
262 - $weights[] = $insert_weight;
263 - }
264 - }
265 - }
266 + foreach ( $insert_weights as $insert_weight ) {
267 + if ( array_search( $insert_weight, $widths, true ) !== false ) {
268 + $weights[] = $insert_weight;
269 + }
270 + }
271 + }
266 272
267 - if (
268 - isset( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'] ) &&
269 - ! empty( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'] ) &&
270 - is_array( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'] )
271 - ) {
272 - $weights = array_values( array_unique( array_merge_recursive( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'], $weights ) ) );
273 - }
273 + if (
274 + isset( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'] ) &&
275 + ! empty( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'] ) &&
276 + is_array( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'] )
277 + ) {
278 + $weights = array_values( array_unique( array_merge_recursive( $webfont_list[ $font['family'] ][ $font['label'] ]['widths'], $weights ) ) );
279 + }
274 280
275 - $webfont_list[ $font['family'] ][ $font['label'] ] = array(
276 - 'widths' => $weights,
277 - 'category' => $category,
278 - 'subsets' => $subsets,
279 - );
280 - }
281 - }
282 - }
283 - }
281 + $webfont_list[ $font['family'] ][ $font['label'] ] = array(
282 + 'widths' => $weights,
283 + 'category' => $category,
284 + 'subsets' => $subsets,
285 + );
286 + }
287 + }
288 + }
289 + }
284 290
285 - return $webfont_list;
286 - }
291 + return $webfont_list;
292 + }
287 293
288 - /**
289 - * Add Default fonts list.
290 - *
291 - * @param array $fonts - fonts list.
292 - *
293 - * @return array
294 - */
295 - public function add_default_site_fonts( $fonts ) {
296 - $fonts['default'] = array(
297 - 'name' => __( 'Default Fonts Site', 'ghostkit' ),
298 - 'fonts' => array(
299 - array(
300 - 'name' => 'Default Site Font',
301 - 'widths' => array(
302 - '',
303 - '400',
304 - '700',
305 - ),
306 - 'category' => 'sans-serif',
307 - ),
308 - ),
309 - );
310 - return $fonts;
311 - }
294 + /**
295 + * Get Default Site Font.
296 + *
297 + * @return array
298 + */
299 + private function get_default_site_font() {
300 + return array(
301 + 'name' => 'Default Site Font',
302 + 'widths' => array(
303 + '',
304 + '400',
305 + '700',
306 + ),
307 + 'category' => 'sans-serif',
308 + );
309 + }
312 310
313 - /**
314 - * Add Google fonts list.
315 - *
316 - * @param array $fonts - fonts list.
317 - *
318 - * @return array
319 - */
320 - public function add_google_fonts( $fonts ) {
321 - $result = get_transient( 'ghostkit_google_fonts_list' );
311 + /**
312 + * Add Default fonts list.
313 + *
314 + * @param array $fonts - fonts list.
315 + *
316 + * @return array
317 + */
318 + public function add_default_site_fonts( $fonts ) {
322 319
323 - // Get new fonts:
324 - // https://developers.google.com/fonts/docs/developer_api?apix_params=%7B%22alt%22%3A%22json%22%2C%22fields%22%3A%22items(family%2Ckind%2Ccategory%2Cvariants%2Csubsets%2Cversion%2ClastModified)%22%2C%22prettyPrint%22%3Afalse%7D .
320 + $fonts['default'] = array(
321 + 'name' => __( 'Default Fonts Site', 'ghostkit' ),
322 + 'fonts' => array(
323 + $this->get_default_site_font(),
324 + ),
325 + );
326 + return $fonts;
327 + }
325 328
326 - if ( ! $result ) {
327 - $result = array();
329 + /**
330 + * Add Google fonts list.
331 + *
332 + * @link https://developers.google.com/fonts/docs/developer_api?apix_params=%7B%22alt%22%3A%22json%22%2C%22fields%22%3A%22items(family%2Ckind%2Ccategory%2Cvariants%2Csubsets%2Cversion%2ClastModified)%22%2C%22prettyPrint%22%3Afalse%7D - get new fonts.
333 + *
334 + * @param array $fonts - fonts list.
335 + *
336 + * @return array
337 + */
338 + public function add_google_fonts( $fonts ) {
339 + $result = get_transient( 'ghostkit_google_fonts_list' );
340 +
341 + if ( ! $result ) {
342 + $result = array();
328 343 $fonts_json = file_get_contents( ghostkit()->plugin_path . 'classes/google-fonts/webfonts.json' ); // phpcs:ignore
329 - $fonts_object = json_decode( $fonts_json, true );
344 + $fonts_object = json_decode( $fonts_json, true );
330 345
331 - foreach ( $fonts_object['items'] as $font ) {
332 - $weights = array();
333 - foreach ( $font['variants'] as $variant ) {
334 - $variant = str_replace( 'italic', 'i', $variant );
346 + foreach ( $fonts_object['items'] as $font ) {
347 + $weights = array();
348 + foreach ( $font['variants'] as $variant ) {
349 + $variant = str_replace( 'italic', 'i', $variant );
335 350
336 - switch ( $variant ) {
337 - case 'i':
338 - $variant = '400i';
339 - break;
340 - case 'regular':
341 - $variant = '400';
342 - break;
343 - }
351 + switch ( $variant ) {
352 + case 'i':
353 + $variant = '400i';
354 + break;
355 + case 'regular':
356 + $variant = '400';
357 + break;
358 + }
344 359
345 - $weights[] = $variant;
346 - }
347 - $result[] = array(
348 - 'name' => $font['family'],
349 - 'widths' => $weights,
350 - 'category' => $font['category'],
351 - 'subsets' => $font['subsets'],
352 - );
353 - }
360 + $weights[] = $variant;
361 + }
362 + $result[] = array(
363 + 'name' => $font['family'],
364 + 'widths' => $weights,
365 + 'category' => $font['category'],
366 + 'subsets' => $font['subsets'],
367 + );
368 + }
354 369
355 - if ( ! empty( $result ) ) {
356 - set_transient( 'ghostkit_google_fonts_list', $result, DAY_IN_SECONDS );
357 - }
358 - }
370 + if ( ! empty( $result ) ) {
371 + set_transient( 'ghostkit_google_fonts_list', $result, DAY_IN_SECONDS );
372 + }
373 + }
359 374
360 - $fonts['google-fonts'] = array(
361 - 'name' => 'Google Fonts',
362 - 'fonts' => $result,
363 - );
375 + $result[] = $this->get_default_site_font();
364 376
365 - return $fonts;
366 - }
377 + $fonts['google-fonts'] = array(
378 + 'name' => esc_attr__( 'Google Fonts', 'ghostkit' ),
379 + 'fonts' => $result,
380 + );
381 +
382 + return $fonts;
383 + }
367 384 }
368 385 new GhostKit_Fonts();