PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.8.1
Shortcodes and extra features for Phlox theme v2.8.1
2.17.22 2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / elementor / modules / settings / base / manager.php
auxin-elements / includes / elementor / modules / settings / base Last commit date
manager.php 5 years ago
manager.php
195 lines
1 <?php
2 namespace Auxin\Plugin\CoreElements\Elementor\Settings\Base;
3
4 use Elementor\Core\Base\Document;
5 use Elementor\Widget_Base;
6 use Elementor\Controls_Manager;
7 use Elementor\Group_Control_Image_Size;
8 use Elementor\Group_Control_Typography;
9 use Elementor\Core\Schemes\Color;
10 use Elementor\Core\Schemes\Typography;
11 use Elementor\Control_Media;
12 use Elementor\Group_Control_Border;
13 use Elementor\Group_Control_Box_Shadow;
14 use Elementor\Group_Control_Background;
15 use Elementor\Core\Kits\Controls\Repeater as Global_Style_Repeater;
16 use Elementor\Repeater;
17
18
19 abstract class Manager {
20
21 function __construct(){
22 $this->register_hooks();
23 }
24
25 protected function register_hooks(){
26 add_action( 'elementor/documents/register_controls', [ $this, 'register_controls' ] );
27 add_action( 'elementor/document/after_save', [ $this, 'on_save_settings' ], 10, 2 );
28 add_action( 'elementor/document/after_save', [ $this, 'elementor_after_save' ], 10, 2 );
29 add_action( 'customize_save_after', [ $this, 'sync_customizer_with_elementor'] );
30 }
31
32 /**
33 * Register Document Controls
34 *
35 * Add New Controls to Elementor Page Options
36 * @param $document
37 */
38 abstract public function register_controls ( $document );
39
40 /**
41 * Stores the changed controllers
42 *
43 * @param array $settings list of settings for changes controllers
44 * @param Document $document Elementor base Document class
45 * @param array|null $data All document info passed for saving
46 * @return mixed
47 */
48 abstract protected function save_settings( array $settings, $document, $data = null );
49
50 /**
51 * Parsing custom control settings
52 *
53 * @param $document
54 * @param $data
55 */
56 public function on_save_settings( $document, $data ){
57 if( empty( $data['settings'] ) ){
58 return;
59 }
60 $settings_to_save = $this->get_settings_to_save( $data['settings'] );
61 $this->save_settings( $settings_to_save, $document, $data );
62 }
63
64 /**
65 * Default special page settings in Elementor document
66 *
67 * @return array
68 */
69 protected function get_special_settings_names(){
70 return [
71 'id',
72 'post_title',
73 'post_status',
74 'template',
75 'post_excerpt',
76 'post_featured_image',
77 ];
78 }
79
80 /**
81 * Get custom control settings which are changed
82 *
83 * @param array $settings
84 * @return array
85 */
86 private function get_settings_to_save( array $settings ){
87 $special_settings = $this->get_special_settings_names();
88
89 $settings_to_save = $settings;
90
91 foreach ( $special_settings as $special_setting ) {
92 if ( isset( $settings_to_save[ $special_setting ] ) ) {
93 unset( $settings_to_save[ $special_setting ] );
94 }
95 }
96
97 return $settings_to_save;
98 }
99
100 /**
101 * Save auxin colors
102 *
103 * @param object $object
104 * @param array $data
105 * @return void
106 */
107 public function elementor_after_save( $object, $data ) {
108 if ( $data && isset( $data['settings'] ) && is_array( $data['settings'] ) ) {
109 foreach ( $data['settings']['system_colors'] as $key => $value ) {
110
111 if ( !empty( $value['color'] ) ) {
112 auxin_update_option( 'elementor_color_' . $value['_id'], $value['color'] );
113 }
114 }
115
116 }
117 }
118
119 /**
120 * Sync Customizer with elementor for elementor global colors
121 *
122 * @return void
123 */
124 public function sync_customizer_with_elementor() {
125
126 // get elementor settings
127 $active_kit = get_option( 'elementor_active_kit', '' );
128 if ( empty( $active_kit ) ) {
129 return;
130 }
131
132 $settings = get_post_meta( $active_kit, '_elementor_page_settings', true );
133
134 // get elementor global custom colors from customizer
135 $added_custom_colors = auxin_get_option( 'elementor_global_custom_colors_repeater', '');
136 $colors = json_decode( $added_custom_colors, true );
137 $custom_colors = [];
138 if ( !empty( $colors ) ) {
139 foreach( $colors as $key => $color ) {
140 if( empty( $color['color'] ) ) {
141 continue;
142 }
143 $custom_colors[] = [
144 '_id' => !empty( $color['_id'] ) ? sanitize_text_field( $color['_id'] ) : \Elementor\Utils::generate_random_string(),
145 'title' => !empty( $color['title'] ) ? sanitize_text_field( $color['title'] ) : __('New Color', 'auxin-elements') . ' #' . $key,
146 'color' => $color['color']
147 ];
148 }
149 }
150
151 if ( empty( $settings ) ) {
152
153 // get elementor system colors form customizer
154 $system_colors_key = ['primary', 'secondary', 'text', 'accent' ];
155 foreach( $system_colors_key as $key ) {
156 $system_colors[] = [
157 '_id' => $key,
158 'title' => ucfirst( $key ),
159 'color' => auxin_get_option( 'elementor_color_' . $key, '' )
160 ];
161 }
162
163 // udpate system colors
164 \Elementor\Plugin::$instance->kits_manager->update_kit_settings_based_on_option( 'system_colors', $system_colors );
165
166 // update custom colors
167 if ( !empty( $custom_colors ) ) {
168 \Elementor\Plugin::$instance->kits_manager->update_kit_settings_based_on_option( 'custom_colors', $custom_colors );
169 }
170
171 } else {
172 // get and update system colors => executing these codes to remain title of system colors from elementor settings unchanged
173 $current_settings = \Elementor\Plugin::$instance->kits_manager->get_current_settings();
174 foreach ( $current_settings['system_colors'] as $color ) {
175 $system_colors[] = [
176 '_id' => $color['_id'],
177 'title' => $color['title'],
178 'color' => auxin_get_option( 'elementor_color_' . $color['_id'], $color['color'] )
179 ];
180 }
181 \Elementor\Plugin::$instance->kits_manager->update_kit_settings_based_on_option( 'system_colors', $system_colors );
182
183 // update custom colors -> updating via post meta because we have to replace all custom colors from customizer with the one in elemnetor settings
184 if ( ! empty( $custom_colors ) ) {
185 $settings['custom_colors'] = $custom_colors;
186 update_post_meta( $active_kit, '_elementor_page_settings', $settings );
187 }
188 }
189
190 auxin_update_option( 'elementor_global_custom_colors_repeater', '' );
191 \Elementor\Plugin::instance()->files_manager->clear_cache();
192
193 }
194 }
195