PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / trunk
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! vtrunk
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / elementor-kit-settings / Utils / KitApplier.php

KitApplier.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! trunk, at modules/elementor-kit-settings/Utils/KitApplier.php

80 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Modules\ElementorKitSettings\Utils;
4
5 use Elementor\Core\Files\Fonts\Google_Font;
6 use Elementor\Plugin;
7
8 /**
9 * Writes customizer-output color/font/logo assignments into the active
10 * Elementor kit document, matching entries by `_id`. Updates BOTH the
11 * `system_*` and `custom_*` buckets (`system_colors`/`custom_colors`,
12 * `system_typography`/`custom_typography`) — Elementor's own default
13 * swatches live in the `system_*` buckets, so a matching `_id` there is
14 * updated too.
15 *
16 * Extracted from modules/settings/REST/Settings.php::update_elementor_settings()
17 * — behavior byte-identical.
18 */
19 class KitApplier {
20
21 public static function apply( $_settings ) {
22 $colors = $_settings['colors'] ?? [];
23 $typography = $_settings['typography'] ?? [];
24
25 $kit = Plugin::$instance->kits_manager->get_active_kit();
26 // `get_active_kit()` never returns falsy: with no valid kit it hands back an
27 // EMPTY Kit instance (post id 0), and calling update_settings() on that throws
28 // `Exception( 'Invalid post.' )` from Elementor's page settings manager —
29 // validating post ID 0. `get_id()` is the check that means "a real kit".
30 if ( $kit && $kit->get_id() ) {
31 $settings = $kit->get_settings();
32 $settings['site_logo'] = $_settings['logoImage'];
33
34 if ( ! empty( $colors ) ) {
35 if ( ! empty( $settings['system_colors'] ) ) {
36 foreach ( $settings['system_colors'] as $key => $color ) {
37 $settings['system_colors'][ $key ]['color'] = $colors[ $color['_id'] ] ?? $color['color'];
38 }
39 }
40 if ( ! empty( $settings['custom_colors'] ) ) {
41 foreach ( $settings['custom_colors'] as $key => $color ) {
42 $settings['custom_colors'][ $key ]['color'] = $colors[ $color['_id'] ] ?? $color['color'];
43 }
44 }
45 }
46
47
48
49 if ( ! empty( $typography ) ) {
50 if ( ! empty( $settings['system_typography'] ) ) {
51 foreach ( $settings['system_typography'] as $key => $typo ) {
52 if ( ! empty( $typography[ $typo['_id'] ] ) ) {
53 $settings['system_typography'][ $key ] = array_merge( $typo, $typography[ $typo['_id'] ] );
54 if ( class_exists( 'Elementor\Core\Files\Fonts\Google_Font' ) && ! empty( $typo['typography_font_family'] ) ) {
55 Google_Font::enqueue( $typo['typography_font_family'] );
56 }
57 }
58 }
59 }
60 if ( ! empty( $settings['custom_typography'] ) ) {
61 foreach ( $settings['custom_typography'] as $key => $typo ) {
62 if ( ! empty( $typography[ $typo['_id'] ] ) ) {
63 $settings['custom_typography'][ $key ] = array_merge( $typo, $typography[ $typo['_id'] ] );
64 if ( class_exists( 'Elementor\Core\Files\Fonts\Google_Font' ) && ! empty( $typo['typography_font_family'] ) ) {
65 Google_Font::enqueue( $typo['typography_font_family'] );
66 }
67 }
68 }
69 }
70 }
71
72 $kit->update_settings( $settings );
73 $settings = $kit->get_settings();
74
75 Plugin::$instance->files_manager->clear_cache();
76 return $settings;
77 }
78 }
79 }
80