PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.0
Elementor Website Builder – more than just a page builder v3.0.0
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / upgrade / upgrades.php

upgrades.php in Elementor Website Builder – more than just a page builder 3.0.0, at core/upgrade/upgrades.php

902 lines 22.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Upgrade;
3
4 use Elementor\Core\Settings\Manager as SettingsManager;
5 use Elementor\Icons_Manager;
6 use Elementor\Modules\Usage\Module;
7 use Elementor\Plugin;
8 use Elementor\Utils;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * Elementor upgrades.
16 *
17 * Elementor upgrades handler class is responsible for updating different
18 * Elementor versions.
19 *
20 * @since 1.0.0
21 */
22 class Upgrades {
23
24 /**
25 * Upgrade Elementor 0.3.2
26 *
27 * Change the image widget link URL, setting is to `custom` link.
28 *
29 * @since 2.0.0
30 * @static
31 * @access public
32 */
33 public static function _v_0_3_2() {
34 global $wpdb;
35
36 $post_ids = $wpdb->get_col(
37 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
38 WHERE `meta_key` = \'_elementor_version\'
39 AND `meta_value` = \'0.1\';'
40 );
41
42 if ( empty( $post_ids ) ) {
43 return;
44 }
45
46 foreach ( $post_ids as $post_id ) {
47 $document = Plugin::$instance->documents->get( $post_id );
48
49 if ( $document ) {
50 $data = $document->get_elements_data();
51 }
52
53 if ( empty( $data ) ) {
54 continue;
55 }
56
57 $data = Plugin::$instance->db->iterate_data( $data, function( $element ) {
58 if ( empty( $element['widgetType'] ) || 'image' !== $element['widgetType'] ) {
59 return $element;
60 }
61
62 if ( ! empty( $element['settings']['link']['url'] ) && ! isset( $element['settings']['link_to'] ) ) {
63 $element['settings']['link_to'] = 'custom';
64 }
65
66 return $element;
67 } );
68
69 $document = Plugin::$instance->documents->get( $post_id );
70
71 $document->save( [
72 'elements' => $data,
73 ] );
74 }
75 }
76
77 /**
78 * Upgrade Elementor 0.9.2
79 *
80 * Change the icon widget, icon-box widget and the social-icons widget,
81 * setting their icon padding size to an empty string.
82 *
83 * Change the image widget, setting the image size to full image size.
84 *
85 * @since 2.0.0
86 * @static
87 * @access public
88 */
89 public static function _v_0_9_2() {
90 global $wpdb;
91
92 // Fix Icon/Icon Box Widgets padding.
93 $post_ids = $wpdb->get_col(
94 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
95 WHERE `meta_key` = \'_elementor_version\'
96 AND `meta_value` = \'0.2\';'
97 );
98
99 if ( empty( $post_ids ) ) {
100 return;
101 }
102
103 foreach ( $post_ids as $post_id ) {
104 $document = Plugin::$instance->documents->get( $post_id );
105
106 if ( $document ) {
107 $data = $document->get_elements_data();
108 }
109
110 if ( empty( $data ) ) {
111 continue;
112 }
113
114 $data = Plugin::$instance->db->iterate_data( $data, function( $element ) {
115 if ( empty( $element['widgetType'] ) ) {
116 return $element;
117 }
118
119 if ( in_array( $element['widgetType'], [ 'icon', 'icon-box', 'social-icons' ] ) ) {
120 if ( ! empty( $element['settings']['icon_padding']['size'] ) ) {
121 $element['settings']['icon_padding']['size'] = '';
122 }
123 }
124
125 if ( 'image' === $element['widgetType'] ) {
126 if ( empty( $element['settings']['image_size'] ) ) {
127 $element['settings']['image_size'] = 'full';
128 }
129 }
130
131 return $element;
132 } );
133
134 $document = Plugin::$instance->documents->get( $post_id );
135
136 $document->save( [
137 'elements' => $data,
138 ] );
139 }
140 }
141
142 /**
143 * Upgrade Elementor 0.11.0
144 *
145 * Change the button widget sizes, setting up new button sizes.
146 *
147 * @since 2.0.0
148 * @static
149 * @access public
150 */
151 public static function _v_0_11_0() {
152 global $wpdb;
153
154 // Fix Button widget to new sizes options.
155 $post_ids = $wpdb->get_col(
156 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
157 WHERE `meta_key` = \'_elementor_version\'
158 AND `meta_value` = \'0.3\';'
159 );
160
161 if ( empty( $post_ids ) ) {
162 return;
163 }
164
165 foreach ( $post_ids as $post_id ) {
166 $document = Plugin::$instance->documents->get( $post_id );
167
168 if ( $document ) {
169 $data = $document->get_elements_data();
170 }
171
172 if ( empty( $data ) ) {
173 continue;
174 }
175
176 $data = Plugin::$instance->db->iterate_data( $data, function( $element ) {
177 if ( empty( $element['widgetType'] ) ) {
178 return $element;
179 }
180
181 if ( 'button' === $element['widgetType'] ) {
182 $size_to_replace = [
183 'small' => 'xs',
184 'medium' => 'sm',
185 'large' => 'md',
186 'xl' => 'lg',
187 'xxl' => 'xl',
188 ];
189
190 if ( ! empty( $element['settings']['size'] ) ) {
191 $old_size = $element['settings']['size'];
192
193 if ( isset( $size_to_replace[ $old_size ] ) ) {
194 $element['settings']['size'] = $size_to_replace[ $old_size ];
195 }
196 }
197 }
198
199 return $element;
200 } );
201
202 $document = Plugin::$instance->documents->get( $post_id );
203
204 $document->save( [
205 'elements' => $data,
206 ] );
207 }
208 }
209
210 /**
211 * Upgrade Elementor 2.0.0
212 *
213 * Fix post titles for old autosave drafts that saved with the format 'Auto Save 2018-03-18 17:24'.
214 *
215 * @static
216 * @since 2.0.0
217 * @access public
218 */
219 public static function _v_2_0_0() {
220 global $wpdb;
221
222 $posts = $wpdb->get_results(
223 'SELECT `ID`, `post_title`, `post_parent`
224 FROM `' . $wpdb->posts . '` p
225 LEFT JOIN `' . $wpdb->postmeta . '` m ON p.ID = m.post_id
226 WHERE `post_status` = \'inherit\'
227 AND `post_title` = CONCAT(\'Auto Save \', DATE_FORMAT(post_date, "%Y-%m-%d %H:%i"))
228 AND m.`meta_key` = \'_elementor_data\';'
229 );
230
231 if ( empty( $posts ) ) {
232 return;
233 }
234
235 foreach ( $posts as $post ) {
236 wp_update_post( [
237 'ID' => $post->ID,
238 'post_title' => get_the_title( $post->post_parent ),
239 ] );
240 }
241 }
242
243 /**
244 * Upgrade Elementor 2.0.1
245 *
246 * Fix post titles for old autosave drafts that saved with the format 'Auto Save...'.
247 *
248 * @since 2.0.2
249 * @static
250 * @access public
251 */
252 public static function _v_2_0_1() {
253 global $wpdb;
254
255 $posts = $wpdb->get_results(
256 'SELECT `ID`, `post_title`, `post_parent`
257 FROM `' . $wpdb->posts . '` p
258 LEFT JOIN `' . $wpdb->postmeta . '` m ON p.ID = m.post_id
259 WHERE `post_status` = \'inherit\'
260 AND `post_title` REGEXP \'^Auto Save [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$\'
261 AND m.`meta_key` = \'_elementor_data\';'
262 );
263
264 if ( empty( $posts ) ) {
265 return;
266 }
267
268 foreach ( $posts as $post ) {
269 $parent = get_post( $post->post_parent );
270 $title = isset( $parent->post_title ) ? $parent->post_title : '';
271
272 wp_update_post( [
273 'ID' => $post->ID,
274 'post_title' => $title,
275 ] );
276 }
277 }
278
279 /**
280 * Upgrade Elementor 2.0.10
281 *
282 * Fix post titles for old autosave drafts that saved with the format 'Auto Save...'.
283 * Fix also Translated titles.
284 *
285 * @since 2.0.10
286 * @static
287 * @access public
288 */
289 public static function _v_2_0_10() {
290 global $wpdb;
291
292 $posts = $wpdb->get_results(
293 'SELECT `ID`, `post_title`, `post_parent`
294 FROM `' . $wpdb->posts . '` p
295 LEFT JOIN `' . $wpdb->postmeta . '` m ON p.ID = m.post_id
296 WHERE `post_status` = \'inherit\'
297 AND `post_title` REGEXP \'[[:alnum:]]+ [[:alnum:]]+ [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$\'
298 AND m.`meta_key` = \'_elementor_data\';'
299 );
300
301 if ( empty( $posts ) ) {
302 return;
303 }
304
305 foreach ( $posts as $post ) {
306 $parent = get_post( $post->post_parent );
307 $title = isset( $parent->post_title ) ? $parent->post_title : '';
308
309 wp_update_post( [
310 'ID' => $post->ID,
311 'post_title' => $title,
312 ] );
313 }
314 }
315
316 public static function _v_2_1_0() {
317 global $wpdb;
318
319 // upgrade `video` widget settings (merge providers).
320 $post_ids = $wpdb->get_col(
321 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"widgetType":"video"%\';'
322 );
323
324 if ( empty( $post_ids ) ) {
325 return;
326 }
327
328 foreach ( $post_ids as $post_id ) {
329 $do_update = false;
330 $document = Plugin::$instance->documents->get( $post_id );
331
332 if ( $document ) {
333 $data = $document->get_elements_data();
334 }
335
336 if ( empty( $data ) ) {
337 continue;
338 }
339
340 $data = Plugin::$instance->db->iterate_data( $data, function( $element ) use ( &$do_update ) {
341 if ( empty( $element['widgetType'] ) || 'video' !== $element['widgetType'] ) {
342 return $element;
343 }
344
345 $replacements = [];
346
347 if ( empty( $element['settings']['video_type'] ) || 'youtube' === $element['settings']['video_type'] ) {
348 $replacements = [
349 'yt_autoplay' => 'autoplay',
350 'yt_controls' => 'controls',
351 'yt_mute' => 'mute',
352 'yt_rel' => 'rel',
353 'link' => 'youtube_url',
354 ];
355 } elseif ( 'vimeo' === $element['settings']['video_type'] ) {
356 $replacements = [
357 'vimeo_autoplay' => 'autoplay',
358 'vimeo_loop' => 'loop',
359 'vimeo_color' => 'color',
360 'vimeo_link' => 'vimeo_url',
361 ];
362 }
363
364 // cleanup old unused settings.
365 unset( $element['settings']['yt_rel_videos'] );
366
367 foreach ( $replacements as $old => $new ) {
368 if ( ! empty( $element['settings'][ $old ] ) ) {
369 $element['settings'][ $new ] = $element['settings'][ $old ];
370 $do_update = true;
371 }
372 }
373
374 return $element;
375 } );
376
377 // Only update if needed.
378 if ( ! $do_update ) {
379 continue;
380 }
381
382 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
383 $json_value = wp_slash( wp_json_encode( $data ) );
384
385 update_metadata( 'post', $post_id, '_elementor_data', $json_value );
386
387 // Clear WP cache for next step.
388 wp_cache_flush();
389 } // End foreach().
390 }
391
392 /**
393 * @param Updater $updater
394 *
395 * @return bool
396 */
397 public static function _v_2_3_0_widget_image( $updater ) {
398 global $wpdb;
399
400 // upgrade `video` widget settings (merge providers).
401 $post_ids = $updater->query_col(
402 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND (
403 `meta_value` LIKE \'%"widgetType":"image"%\'
404 OR `meta_value` LIKE \'%"widgetType":"theme-post-featured-image"%\'
405 OR `meta_value` LIKE \'%"widgetType":"theme-site-logo"%\'
406 OR `meta_value` LIKE \'%"widgetType":"woocommerce-category-image"%\'
407 );'
408 );
409
410 if ( empty( $post_ids ) ) {
411 return false;
412 }
413
414 $widgets = [
415 'image',
416 'theme-post-featured-image',
417 'theme-site-logo',
418 'woocommerce-category-image',
419 ];
420
421 foreach ( $post_ids as $post_id ) {
422 // Clear WP cache for next step.
423 wp_cache_flush();
424
425 $do_update = false;
426
427 $document = Plugin::$instance->documents->get( $post_id );
428
429 if ( ! $document ) {
430 continue;
431 }
432
433 $data = $document->get_elements_data();
434
435 if ( empty( $data ) ) {
436 continue;
437 }
438
439 $data = Plugin::$instance->db->iterate_data( $data, function( $element ) use ( &$do_update, $widgets ) {
440 if ( empty( $element['widgetType'] ) || ! in_array( $element['widgetType'], $widgets ) ) {
441 return $element;
442 }
443
444 if ( ! empty( $element['settings']['caption'] ) ) {
445 if ( ! isset( $element['settings']['caption_source'] ) ) {
446 $element['settings']['caption_source'] = 'custom';
447
448 $do_update = true;
449 }
450 }
451
452 return $element;
453 } );
454
455 // Only update if needed.
456 if ( ! $do_update ) {
457 continue;
458 }
459
460 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
461 $json_value = wp_slash( wp_json_encode( $data ) );
462
463 update_metadata( 'post', $post_id, '_elementor_data', $json_value );
464 } // End foreach().
465
466 return $updater->should_run_again( $post_ids );
467 }
468
469 /**
470 * @param Updater $updater
471 *
472 * @return bool
473 */
474 public static function _v_2_3_0_template_type( $updater ) {
475 global $wpdb;
476
477 $post_ids = $updater->query_col(
478 'SELECT p.ID
479 FROM `' . $wpdb->posts . '` AS p
480 LEFT JOIN `' . $wpdb->postmeta . '` AS pm1 ON (p.ID = pm1.post_id)
481 LEFT JOIN `' . $wpdb->postmeta . '` AS pm2 ON (pm1.post_id = pm2.post_id AND pm2.meta_key = "_elementor_template_type")
482 WHERE p.post_status != "inherit" AND pm1.`meta_key` = "_elementor_data" AND pm2.post_id IS NULL;'
483 );
484
485 if ( empty( $post_ids ) ) {
486 return false;
487 }
488
489 foreach ( $post_ids as $post_id ) {
490 // Clear WP cache for next step.
491 wp_cache_flush();
492
493 $document = Plugin::$instance->documents->get( $post_id );
494
495 if ( ! $document ) {
496 continue;
497 }
498
499 $document->save_template_type();
500 } // End foreach().
501
502 return $updater->should_run_again( $post_ids );
503 }
504
505 /**
506 * Set FontAwesome Migration needed flag
507 */
508 public static function _v_2_6_0_fa4_migration_flag() {
509 add_option( 'elementor_icon_manager_needs_update', 'yes' );
510 add_option( 'elementor_load_fa4_shim', 'yes' );
511 }
512
513 /**
514 * migrate Icon control string value to Icons control array value
515 *
516 * @param array $element
517 * @param array $args
518 *
519 * @return mixed
520 */
521 public static function _migrate_icon_fa4_value( $element, $args ) {
522 $widget_id = $args['widget_id'];
523
524 if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) {
525 return $element;
526 }
527 foreach ( $args['control_ids'] as $old_name => $new_name ) {
528 // exit if new value exists
529 if ( isset( $element['settings'][ $new_name ] ) ) {
530 continue;
531 }
532
533 // exit if no value to migrate
534 if ( ! isset( $element['settings'][ $old_name ] ) ) {
535 continue;
536 }
537
538 $element['settings'][ $new_name ] = Icons_Manager::fa4_to_fa5_value_migration( $element['settings'][ $old_name ] );
539 $args['do_update'] = true;
540 }
541 return $element;
542 }
543
544 /**
545 * Set FontAwesome 5 value Migration on for button widget
546 *
547 * @param Updater $updater
548 */
549 public static function _v_2_6_6_fa4_migration_button( $updater ) {
550 $changes = [
551 [
552 'callback' => [ 'Elementor\Core\Upgrade\Upgrades', '_migrate_icon_fa4_value' ],
553 'control_ids' => [
554 'icon' => 'selected_icon',
555 ],
556 ],
557 ];
558 Upgrade_Utils::_update_widget_settings( 'button', $updater, $changes );
559 Upgrade_Utils::_update_widget_settings( 'icon-box', $updater, $changes );
560 }
561
562 /**
563 * Update database to separate page from post.
564 *
565 * @param Updater $updater
566 *
567 * @param string $type
568 *
569 * @return bool
570 */
571 public static function rename_document_base_to_wp( $updater, $type ) {
572 global $wpdb;
573
574 $post_ids = $updater->query_col( $wpdb->prepare(
575 "SELECT p1.ID FROM {$wpdb->posts} AS p
576 LEFT JOIN {$wpdb->posts} AS p1 ON (p.ID = p1.post_parent || p.ID = p1.ID)
577 WHERE p.post_type = %s;", $type ) );
578
579 if ( empty( $post_ids ) ) {
580 return false;
581 }
582
583 $sql_post_ids = implode( ',', $post_ids );
584
585 $wpdb->query( $wpdb->prepare(
586 "UPDATE $wpdb->postmeta SET meta_value = %s
587 WHERE meta_key = '_elementor_template_type' && post_id in ( %s );
588 ", 'wp-' . $type, $sql_post_ids ) );
589
590 return $updater->should_run_again( $post_ids );
591 }
592
593 /**
594 * Update database to separate page from post.
595 *
596 * @param Updater $updater
597 *
598 * @return bool
599 */
600 // Because the query is slow on large sites, temporary don't upgrade.
601 /* public static function _v_2_7_0_rename_document_types_to_wp( $updater ) {
602 return self::rename_document_base_to_wp( $updater, 'post' ) || self::rename_document_base_to_wp( $updater, 'page' );
603 }*/
604
605 // Upgrade code was fixed & moved to _v_2_7_1_remove_old_usage_data.
606 /* public static function _v_2_7_0_remove_old_usage_data() {} */
607
608 // Upgrade code moved to _v_2_7_1_recalc_usage_data.
609 /* public static function _v_2_7_0_recalc_usage_data( $updater ) {} */
610
611 /**
612 * Don't use the old data anymore.
613 * Since 2.7.1 the key was changed from `elementor_elements_usage` to `elementor_controls_usage`.
614 */
615 public static function _v_2_7_1_remove_old_usage_data() {
616 delete_option( 'elementor_elements_usage' );
617 delete_post_meta_by_key( '_elementor_elements_usage' );
618 }
619
620 /**
621 * Recalc usage.
622 *
623 * @param Updater $updater
624 *
625 * @return bool
626 */
627 public static function recalc_usage_data( $updater ) {
628 /** @var Module $module */
629 $module = Plugin::$instance->modules_manager->get_modules( 'usage' );
630
631 $post_count = $module->recalc_usage( $updater->get_limit(), $updater->get_current_offset() );
632
633 return ( $post_count === $updater->get_limit() );
634 }
635
636 public static function _v_2_7_1_recalc_usage_data( $updater ) {
637 return self::recalc_usage_data( $updater );
638 }
639
640 public static function _v_2_8_3_recalc_usage_data( $updater ) {
641 // Re-calc since older version(s) had invalid values.
642 return self::recalc_usage_data( $updater );
643 }
644
645 /**
646 * Move general & lightbox settings to active kit and all it's revisions.
647 *
648 * @param Updater $updater
649 *
650 * @return bool
651 */
652 public static function _v_3_0_0_move_general_settings_to_kit( $updater ) {
653 $callback = function( $kit_id ) {
654 $kit = Plugin::$instance->documents->get( $kit_id );
655
656 if ( ! $kit ) {
657 self::notice( 'Kit not found. nothing to do.' );
658 return;
659 }
660
661 $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY;
662 $current_settings = get_option( '_elementor_general_settings', [] );
663 $current_settings['viewport_md'] = get_option( 'elementor_viewport_md', '' );
664 $current_settings['viewport_lg'] = get_option( 'elementor_viewport_lg', '' );
665
666 $kit_settings = $kit->get_meta( $meta_key );
667
668 // Already exist.
669 if ( isset( $kit_settings['default_generic_fonts'] ) ) {
670 self::notice( 'General Settings already exist. nothing to do.' );
671 return;
672 }
673
674 if ( empty( $current_settings ) ) {
675 self::notice( 'Current settings are empty. nothing to do.' );
676 return;
677 }
678
679 if ( ! $kit_settings ) {
680 $kit_settings = [];
681 }
682
683 // Convert some setting to Elementor slider format.
684 $settings_to_slider = [
685 'container_width',
686 'space_between_widgets',
687 ];
688
689 foreach ( $settings_to_slider as $setting ) {
690 if ( ! empty( $current_settings[ $setting ] ) ) {
691 $current_settings[ $setting ] = [
692 'unit' => 'px',
693 'size' => $current_settings[ $setting ],
694 ];
695 }
696 }
697
698 $kit_settings = array_merge( $kit_settings, $current_settings );
699
700 $page_settings_manager = SettingsManager::get_settings_managers( 'page' );
701 $page_settings_manager->save_settings( $kit_settings, $kit_id );
702 };
703
704 return self::move_settings_to_kit( $callback, $updater );
705 }
706
707 /**
708 * Move default colors settings to active kit and all it's revisions.
709 *
710 * @param Updater $updater
711 *
712 * @return bool
713 */
714 public static function _v_3_0_0_move_default_colors_to_kit( $updater ) {
715 $callback = function( $kit_id ) {
716 if ( ! Plugin::$instance->kits_manager->is_custom_colors_enabled() ) {
717 self::notice( 'System colors are disabled. nothing to do.' );
718 return;
719 }
720
721 $kit = Plugin::$instance->documents->get( $kit_id );
722
723 // Already exist. use raw settings that doesn't have default values.
724 $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY;
725 $kit_raw_settings = $kit->get_meta( $meta_key );
726 if ( isset( $kit_raw_settings['system_colors'] ) ) {
727 self::notice( 'System colors already exist. nothing to do.' );
728 return;
729 }
730
731 $scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color' );
732
733 $default_colors = $scheme_obj->get_scheme();
734
735 $new_ids = [
736 'primary',
737 'secondary',
738 'text',
739 'accent',
740 ];
741
742 foreach ( $default_colors as $index => $color ) {
743 $kit->add_repeater_row( 'system_colors', [
744 '_id' => $new_ids[ $index - 1 ], // $default_colors starts from 1.
745 'title' => $color['title'],
746 'color' => strtoupper( $color['value'] ),
747 ] );
748 }
749 };
750
751 return self::move_settings_to_kit( $callback, $updater );
752 }
753
754 /**
755 * Move saved colors settings to active kit and all it's revisions.
756 *
757 * @param Updater $updater
758 *
759 * @return bool
760 */
761 public static function _v_3_0_0_move_saved_colors_to_kit( $updater ) {
762 $callback = function( $kit_id ) {
763 $kit = Plugin::$instance->documents->get( $kit_id );
764
765 // Already exist. use raw settings that doesn't have default values.
766 $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY;
767 $kit_raw_settings = $kit->get_meta( $meta_key );
768 if ( isset( $kit_raw_settings['custom_colors'] ) ) {
769 self::notice( 'Custom colors already exist. nothing to do.' );
770 return;
771 }
772
773 $system_colors_rows = $kit->get_settings( 'system_colors' );
774
775 if ( ! $system_colors_rows ) {
776 $system_colors_rows = [];
777 }
778
779 $system_colors = [];
780
781 foreach ( $system_colors_rows as $color_row ) {
782 $system_colors[] = strtoupper( $color_row['color'] );
783 }
784
785 $saved_scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color-picker' );
786
787 $current_saved_colors_rows = $saved_scheme_obj->get_scheme();
788
789 $current_saved_colors = [];
790
791 foreach ( $current_saved_colors_rows as $color_row ) {
792 $current_saved_colors[] = strtoupper( $color_row['value'] );
793 }
794
795 $colors_to_save = array_diff( $current_saved_colors, $system_colors );
796
797 if ( empty( $colors_to_save ) ) {
798 self::notice( 'Saved colors not found. nothing to do.' );
799 return;
800 }
801
802 foreach ( $colors_to_save as $index => $color ) {
803 $kit->add_repeater_row( 'custom_colors', [
804 '_id' => Utils::generate_random_string(),
805 'title' => __( 'Saved Color', 'elementor' ) . ' #' . ( $index + 1 ),
806 'color' => $color,
807 ] );
808 }
809 };
810
811 return self::move_settings_to_kit( $callback, $updater );
812 }
813
814 /**
815 * Move default typography settings to active kit and all it's revisions.
816 *
817 * @param Updater $updater
818 *
819 * @return bool
820 */
821 public static function _v_3_0_0_move_default_typography_to_kit( $updater ) {
822 $callback = function( $kit_id ) {
823 if ( ! Plugin::$instance->kits_manager->is_custom_typography_enabled() ) {
824 self::notice( 'System typography is disabled. nothing to do.' );
825 return;
826 }
827
828 $kit = Plugin::$instance->documents->get( $kit_id );
829
830 // Already exist. use raw settings that doesn't have default values.
831 $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY;
832 $kit_raw_settings = $kit->get_meta( $meta_key );
833 if ( isset( $kit_raw_settings['system_typography'] ) ) {
834 self::notice( 'System typography already exist. nothing to do.' );
835 return;
836 }
837
838 $scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'typography' );
839
840 $default_typography = $scheme_obj->get_scheme();
841
842 $new_ids = [
843 'primary',
844 'secondary',
845 'text',
846 'accent',
847 ];
848
849 foreach ( $default_typography as $index => $typography ) {
850 $kit->add_repeater_row( 'system_typography', [
851 '_id' => $new_ids[ $index - 1 ], // $default_typography starts from 1.
852 'title' => $typography['title'],
853 'typography_typography' => 'custom',
854 'typography_font_family' => $typography['value']['font_family'],
855 'typography_font_weight' => $typography['value']['font_weight'],
856 ] );
857 }
858 };
859
860 return self::move_settings_to_kit( $callback, $updater );
861 }
862
863 /**
864 * @param callback $callback
865 * @param Updater $updater
866 *
867 * @return mixed
868 */
869 private static function move_settings_to_kit( $callback, $updater ) {
870 $active_kit_id = Plugin::$instance->kits_manager->get_active_id();
871 if ( ! $active_kit_id ) {
872 self::notice( 'Active kit not found. nothing to do.' );
873 return false;
874 }
875
876 $offset = $updater->get_current_offset();
877
878 // On first iteration apply on active kit itself.
879 // (don't include it with revisions in order to avoid offset/iteration count wrong numbers)
880 if ( 0 === $offset ) {
881 $callback( $active_kit_id );
882 }
883
884 $revisions_ids = wp_get_post_revisions( $active_kit_id, [
885 'fields' => 'ids',
886 'posts_per_page' => $updater->get_limit(),
887 'offset' => $offset,
888 ] );
889
890 foreach ( $revisions_ids as $revision_id ) {
891 $callback( $revision_id );
892 }
893
894 return $updater->should_run_again( $revisions_ids );
895 }
896
897 private static function notice( $message ) {
898 $logger = Plugin::$instance->logger->get_logger();
899 $logger->notice( $message );
900 }
901 }
902