PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.3
Elementor Website Builder – more than just a page builder v3.2.3
4.3.0-beta3 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 All 452 releases
← All changes | core/upgrade/upgrades.php +182 -235 4.1.53.2.3 View file →
@@ -1,18 +1,17 @@
1 1 <?php
2 2 namespace Elementor\Core\Upgrade;
3 3
4 -use Elementor\Api;
5 4 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
6 5 use Elementor\Core\Experiments\Manager as Experiments_Manager;
6 +use Elementor\Core\Kits\Documents\Tabs\Settings_Layout;
7 +use Elementor\Core\Responsive\Responsive;
7 8 use Elementor\Core\Settings\Manager as SettingsManager;
8 9 use Elementor\Core\Settings\Page\Manager as SettingsPageManager;
9 10 use Elementor\Icons_Manager;
10 -use Elementor\Includes\Elements\Container;
11 11 use Elementor\Modules\Usage\Module;
12 12 use Elementor\Plugin;
13 -use Elementor\Tracker;
14 -use Elementor\App\Modules\ImportExport\Utils;
13 +use Elementor\Utils;
15 14
16 15 if ( ! defined( 'ABSPATH' ) ) {
17 16 exit; // Exit if accessed directly.
18 17 }
@@ -26,21 +25,8 @@
26 25 * @since 1.0.0
27 26 */
28 27 class Upgrades {
29 28
30 - public static function _on_each_version( $updater ) {
31 - self::recalc_usage_data( $updater );
32 - self::remove_remote_info_api_data();
33 -
34 - $uploads_manager = Plugin::$instance->uploads_manager;
35 -
36 - $temp_dir = $uploads_manager->get_temp_dir();
37 -
38 - if ( file_exists( $temp_dir ) ) {
39 - $uploads_manager->remove_file_or_dir( $temp_dir );
40 - }
41 - }
42 -
43 29 /**
44 30 * Upgrade Elementor 0.3.2
45 31 *
46 32 * Change the image widget link URL, setting is to `custom` link.
@@ -404,9 +390,9 @@
404 390 update_metadata( 'post', $post_id, '_elementor_data', $json_value );
405 391
406 392 // Clear WP cache for next step.
407 393 wp_cache_flush();
408 - }
394 + } // End foreach().
409 395 }
410 396
411 397 /**
412 398 * @param Updater $updater
@@ -479,9 +465,9 @@
479 465 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
480 466 $json_value = wp_slash( wp_json_encode( $data ) );
481 467
482 468 update_metadata( 'post', $post_id, '_elementor_data', $json_value );
483 - }
469 + } // End foreach().
484 470
485 471 return $updater->should_run_again( $post_ids );
486 472 }
487 473
@@ -515,9 +501,9 @@
515 501 continue;
516 502 }
517 503
518 504 $document->save_template_type();
519 - }
505 + } // End foreach().
520 506
521 507 return $updater->should_run_again( $post_ids );
522 508 }
523 509
@@ -529,9 +515,9 @@
529 515 add_option( 'elementor_load_fa4_shim', 'yes' );
530 516 }
531 517
532 518 /**
533 - * Migrate Icon control string value to Icons control array value
519 + * migrate Icon control string value to Icons control array value
534 520 *
535 521 * @param array $element
536 522 * @param array $args
537 523 *
@@ -581,10 +567,11 @@
581 567 /**
582 568 * Update database to separate page from post.
583 569 *
584 570 * @param Updater $updater
585 - * @param string $type
586 571 *
572 + * @param string $type
573 + *
587 574 * @return bool
588 575 */
589 576 public static function rename_document_base_to_wp( $updater, $type ) {
590 577 global $wpdb;
@@ -608,8 +595,26 @@
608 595 return $updater->should_run_again( $post_ids );
609 596 }
610 597
611 598 /**
599 + * Update database to separate page from post.
600 + *
601 + * @param Updater $updater
602 + *
603 + * @return bool
604 + */
605 + // Because the query is slow on large sites, temporary don't upgrade.
606 + /* public static function _v_2_7_0_rename_document_types_to_wp( $updater ) {
607 + return self::rename_document_base_to_wp( $updater, 'post' ) || self::rename_document_base_to_wp( $updater, 'page' );
608 + }*/
609 +
610 + // Upgrade code was fixed & moved to _v_2_7_1_remove_old_usage_data.
611 + /* public static function _v_2_7_0_remove_old_usage_data() {} */
612 +
613 + // Upgrade code moved to _v_2_7_1_recalc_usage_data.
614 + /* public static function _v_2_7_0_recalc_usage_data( $updater ) {} */
615 +
616 + /**
612 617 * Don't use the old data anymore.
613 618 * Since 2.7.1 the key was changed from `elementor_elements_usage` to `elementor_controls_usage`.
614 619 */
615 620 public static function _v_2_7_1_remove_old_usage_data() {
@@ -624,12 +629,8 @@
624 629 *
625 630 * @return bool
626 631 */
627 632 public static function recalc_usage_data( $updater ) {
628 - if ( ! Tracker::is_allow_track() ) {
629 - return false;
630 - }
631 -
632 633 /** @var Module $module */
633 634 $module = Plugin::$instance->modules_manager->get_modules( 'usage' );
634 635
635 636 $post_count = $module->recalc_usage( $updater->get_limit(), $updater->get_current_offset() );
@@ -709,193 +710,213 @@
709 710
710 711 return self::move_settings_to_kit( $callback, $updater );
711 712 }
712 713
713 - public static function _v_3_2_0_migrate_breakpoints_to_new_system( $updater, $include_revisions = true ) {
714 + /**
715 + * Move default colors settings to active kit and all it's revisions.
716 + *
717 + * @param Updater $updater
718 + *
719 + * @return bool
720 + */
721 + public static function _v_3_0_0_move_default_colors_to_kit( $updater, $include_revisions = true ) {
714 722 $callback = function( $kit_id ) {
723 + if ( ! Plugin::$instance->kits_manager->is_custom_colors_enabled() ) {
724 + self::notice( 'System colors are disabled. nothing to do.' );
725 + return;
726 + }
727 +
715 728 $kit = Plugin::$instance->documents->get( $kit_id );
716 729
717 - $kit_settings = $kit->get_meta( SettingsPageManager::META_KEY );
718 -
719 - if ( ! $kit_settings ) {
720 - // Nothing to upgrade.
730 + // Already exist. use raw settings that doesn't have default values.
731 + $meta_key = SettingsPageManager::META_KEY;
732 + $kit_raw_settings = $kit->get_meta( $meta_key );
733 + if ( isset( $kit_raw_settings['system_colors'] ) ) {
734 + self::notice( 'System colors already exist. nothing to do.' );
721 735 return;
722 736 }
723 737
724 - $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
725 - $old_mobile_option_key = $prefix . 'md';
726 - $old_tablet_option_key = $prefix . 'lg';
738 + $scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color' );
727 739
728 - $breakpoint_values = [
729 - $old_mobile_option_key => Plugin::$instance->kits_manager->get_current_settings( $old_mobile_option_key ),
730 - $old_tablet_option_key => Plugin::$instance->kits_manager->get_current_settings( $old_tablet_option_key ),
740 + $default_colors = $scheme_obj->get_scheme();
741 +
742 + $new_ids = [
743 + 'primary',
744 + 'secondary',
745 + 'text',
746 + 'accent',
731 747 ];
732 748
733 - // Breakpoint values are either a number, or an empty string (empty setting).
734 - array_walk( $breakpoint_values, function( &$breakpoint_value, $breakpoint_key ) {
735 - if ( $breakpoint_value ) {
736 - // If the saved breakpoint value is a number, 1px is reduced because the new breakpoints system is
737 - // based on max-width, as opposed to the old breakpoints system that worked based on min-width.
738 - $breakpoint_value--;
739 - }
749 + foreach ( $default_colors as $index => $color ) {
750 + $kit->add_repeater_row( 'system_colors', [
751 + '_id' => $new_ids[ $index - 1 ], // $default_colors starts from 1.
752 + 'title' => $color['title'],
753 + 'color' => strtoupper( $color['value'] ),
754 + ] );
755 + }
756 + };
740 757
741 - return $breakpoint_value;
742 - } );
758 + return self::move_settings_to_kit( $callback, $updater, $include_revisions );
759 + }
743 760
744 - $kit_settings[ $prefix . Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ] = $breakpoint_values[ $old_mobile_option_key ];
745 - $kit_settings[ $prefix . Breakpoints_Manager::BREAKPOINT_KEY_TABLET ] = $breakpoint_values[ $old_tablet_option_key ];
761 + /**
762 + * Move saved colors settings to active kit and all it's revisions.
763 + *
764 + * @param Updater $updater
765 + *
766 + * @return bool
767 + */
768 + public static function _v_3_0_0_move_saved_colors_to_kit( $updater, $include_revisions = true ) {
769 + $callback = function( $kit_id ) {
770 + $kit = Plugin::$instance->documents->get( $kit_id );
746 771
747 - $page_settings_manager = SettingsManager::get_settings_managers( 'page' );
748 - $page_settings_manager->save_settings( $kit_settings, $kit_id );
749 - };
772 + // Already exist. use raw settings that doesn't have default values.
773 + $meta_key = SettingsPageManager::META_KEY;
774 + $kit_raw_settings = $kit->get_meta( $meta_key );
775 + if ( isset( $kit_raw_settings['custom_colors'] ) ) {
776 + self::notice( 'Custom colors already exist. nothing to do.' );
777 + return;
778 + }
750 779
751 - return self::move_settings_to_kit( $callback, $updater, $include_revisions );
752 - }
780 + $system_colors_rows = $kit->get_settings( 'system_colors' );
753 781
754 - public static function _v_3_4_8_fix_font_awesome_default_value_from_1_to_yes() {
755 - // if `Icons_Manager::LOAD_FA4_SHIM_OPTION_KEY` value is '1', then set it to `yes`.
756 - $load_fa4_shim_option = get_option( Icons_Manager::LOAD_FA4_SHIM_OPTION_KEY );
782 + if ( ! $system_colors_rows ) {
783 + $system_colors_rows = [];
784 + }
757 785
758 - if ( '1' === $load_fa4_shim_option ) {
759 - update_option( Icons_Manager::LOAD_FA4_SHIM_OPTION_KEY, 'yes' );
760 - }
761 - }
786 + $system_colors = [];
762 787
763 - public static function _v_3_5_0_remove_old_elementor_scheme() {
764 - global $wpdb;
788 + foreach ( $system_colors_rows as $color_row ) {
789 + $system_colors[] = strtoupper( $color_row['color'] );
790 + }
765 791
766 - $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'elementor_scheme_%';" );
767 - }
792 + $saved_scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color-picker' );
768 793
769 - public static function _v_3_8_0_fix_php8_image_custom_size() {
770 - global $wpdb;
794 + $current_saved_colors_rows = $saved_scheme_obj->get_scheme();
771 795
772 - $attachment_ids = $wpdb->get_col(
773 - 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
774 - WHERE `meta_key` = "_wp_attachment_metadata"
775 - AND (
776 - `meta_value` LIKE \'%elementor_custom_%\'
777 - );'
778 - );
796 + $current_saved_colors = [];
779 797
780 - foreach ( $attachment_ids as $attachment_id ) {
781 - $attachment_metadata = wp_get_attachment_metadata( $attachment_id );
782 - if ( empty( $attachment_metadata['sizes'] ) || ! is_array( $attachment_metadata['sizes'] ) ) {
783 - continue;
798 + foreach ( $current_saved_colors_rows as $color_row ) {
799 + $current_saved_colors[] = strtoupper( $color_row['value'] );
784 800 }
785 801
786 - $old_attachment_metadata = $attachment_metadata;
787 - foreach ( $attachment_metadata['sizes'] as $size_key => $size_value ) {
788 - if ( 0 !== strpos( $size_key, 'elementor_custom_' ) ) {
789 - continue;
790 - }
802 + $colors_to_save = array_diff( $current_saved_colors, $system_colors );
791 803
792 - if ( absint( $size_value['width'] ) !== $size_value['width'] ) {
793 - $attachment_metadata['sizes'][ $size_key ]['width'] = (int) $size_value['width'];
794 - }
804 + if ( empty( $colors_to_save ) ) {
805 + self::notice( 'Saved colors not found. nothing to do.' );
806 + return;
807 + }
795 808
796 - if ( absint( $size_value['height'] ) !== $size_value['height'] ) {
797 - $attachment_metadata['sizes'][ $size_key ]['height'] = (int) $size_value['height'];
798 - }
809 + foreach ( $colors_to_save as $index => $color ) {
810 + $kit->add_repeater_row( 'custom_colors', [
811 + '_id' => Utils::generate_random_string(),
812 + 'title' => __( 'Saved Color', 'elementor' ) . ' #' . ( $index + 1 ),
813 + 'color' => $color,
814 + ] );
799 815 }
816 + };
800 817
801 - if ( $old_attachment_metadata['sizes'] === $attachment_metadata['sizes'] ) {
802 - continue;
818 + return self::move_settings_to_kit( $callback, $updater, $include_revisions );
819 + }
820 +
821 + /**
822 + * Move default typography settings to active kit and all it's revisions.
823 + *
824 + * @param Updater $updater
825 + *
826 + * @return bool
827 + */
828 + public static function _v_3_0_0_move_default_typography_to_kit( $updater, $include_revisions = true ) {
829 + $callback = function( $kit_id ) {
830 + if ( ! Plugin::$instance->kits_manager->is_custom_typography_enabled() ) {
831 + self::notice( 'System typography is disabled. nothing to do.' );
832 + return;
803 833 }
804 834
805 - wp_update_attachment_metadata( $attachment_id, $attachment_metadata );
806 - }
807 - }
835 + $kit = Plugin::$instance->documents->get( $kit_id );
808 836
809 - public static function _v_3_16_0_container_updates( $updater ) {
810 - $post_ids = self::get_post_ids_by_element_type( $updater, 'container' );
837 + // Already exist. use raw settings that doesn't have default values.
838 + $meta_key = SettingsPageManager::META_KEY;
839 + $kit_raw_settings = $kit->get_meta( $meta_key );
840 + if ( isset( $kit_raw_settings['system_typography'] ) ) {
841 + self::notice( 'System typography already exist. nothing to do.' );
842 + return;
843 + }
811 844
812 - if ( empty( $post_ids ) ) {
813 - return false;
814 - }
845 + $scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'typography' );
815 846
816 - foreach ( $post_ids as $post_id ) {
817 - $document = Plugin::$instance->documents->get( $post_id );
847 + $default_typography = $scheme_obj->get_scheme();
818 848
819 - if ( $document ) {
820 - $data = $document->get_elements_data();
821 - }
849 + $new_ids = [
850 + 'primary',
851 + 'secondary',
852 + 'text',
853 + 'accent',
854 + ];
822 855
823 - if ( empty( $data ) ) {
824 - continue;
856 + foreach ( $default_typography as $index => $typography ) {
857 + $kit->add_repeater_row( 'system_typography', [
858 + '_id' => $new_ids[ $index - 1 ], // $default_typography starts from 1.
859 + 'title' => $typography['title'],
860 + 'typography_typography' => 'custom',
861 + 'typography_font_family' => $typography['value']['font_family'],
862 + 'typography_font_weight' => $typography['value']['font_weight'],
863 + ] );
825 864 }
865 + };
826 866
827 - $data = self::iterate_containers( $data );
867 + return self::move_settings_to_kit( $callback, $updater, $include_revisions );
868 + }
828 869
829 - self::save_updated_document( $post_id, $data );
830 - }
831 - }
870 + public static function v_3_1_0_move_optimized_dom_output_to_experiments() {
871 + $saved_option = get_option( 'elementor_optimized_dom_output' );
832 872
833 - public static function _v_3_17_0_site_settings_updates() {
834 - $options = [ 'elementor_active_kit', 'elementor_previous_kit' ];
873 + if ( $saved_option ) {
874 + $new_option = 'enabled' === $saved_option ? Experiments_Manager::STATE_ACTIVE : Experiments_Manager::STATE_INACTIVE;
835 875
836 - foreach ( $options as $option_name ) {
837 - self::maybe_add_gap_control_data( $option_name );
876 + add_option( 'elementor_experiment-e_dom_optimization', $new_option );
838 877 }
839 878 }
840 879
841 - /**
842 - * Upgrade Elementor 3.26.0 - Delete old experiments from the DB.
843 - *
844 - * @since 3.26.0
845 - * @static
846 - * @access public
847 - */
848 - public static function _v_3_26_0() {
849 - delete_option( 'elementor_experiment-ai-layout' );
850 - delete_option( 'elementor_experiment-block_editor_assets_optimize' );
851 - delete_option( 'elementor_experiment-container_grid' );
852 - delete_option( 'elementor_experiment-display-conditions' );
853 - delete_option( 'elementor_experiment-e_dom_optimization' );
854 - delete_option( 'elementor_experiment-e_global_styleguide' );
855 - delete_option( 'elementor_experiment-e_image_loading_optimization' );
856 - delete_option( 'elementor_experiment-e_lazyload' );
857 - delete_option( 'elementor_experiment-e_optimized_assets_loading' );
858 - delete_option( 'elementor_experiment-e_optimized_css_loading' );
859 - delete_option( 'elementor_experiment-e_scroll_snap' );
860 - delete_option( 'elementor_experiment-floating-buttons' );
861 - delete_option( 'elementor_experiment-form-submissions' );
862 - delete_option( 'elementor_experiment-link-in-bio' );
863 - delete_option( 'elementor_experiment-loop' );
864 - delete_option( 'elementor_experiment-notes' );
865 - delete_option( 'elementor_experiment-off-canvas' );
866 - delete_option( 'elementor_experiment-page-transitions' );
867 - delete_option( 'elementor_experiment-search' );
868 - delete_option( 'elementor_experiment-taxonomy-filter' );
869 - }
880 + public static function _v_3_2_0_migrate_breakpoints_to_new_system( $updater, $include_revisions = true ) {
881 + $callback = function( $kit_id ) {
882 + $kit = Plugin::$instance->documents->get( $kit_id );
870 883
871 - private static function maybe_add_gap_control_data( $option_name ) {
872 - $kit_id = get_option( $option_name );
884 + $kit_settings = $kit->get_meta( SettingsPageManager::META_KEY );
873 885
874 - if ( ! $kit_id ) {
875 - return;
876 - }
886 + if ( ! $kit_settings ) {
887 + // Nothing to upgrade.
888 + return;
889 + }
877 890
878 - $kit_data_array = get_post_meta( (int) $kit_id, '_elementor_page_settings', true );
891 + $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
892 + $old_mobile_option_key = $prefix . 'md';
893 + $old_tablet_option_key = $prefix . 'lg';
879 894
880 - $setting_not_exist = ! isset( $kit_data_array['space_between_widgets'] );
881 - $already_processed = isset( $kit_data_array['space_between_widgets']['column'] );
895 + $breakpoint_values = [
896 + $old_mobile_option_key => Plugin::$instance->kits_manager->get_current_settings( $old_mobile_option_key ),
897 + $old_tablet_option_key => Plugin::$instance->kits_manager->get_current_settings( $old_tablet_option_key ),
898 + ];
882 899
883 - if ( $setting_not_exist || $already_processed ) {
884 - return;
885 - }
900 + // Breakpoint values are either a number, or an empty string (empty setting).
901 + array_walk( $breakpoint_values, function( &$breakpoint_value, $breakpoint_key ) {
902 + if ( $breakpoint_value ) {
903 + // If the saved breakpoint value is a number, 1px is reduced because the new breakpoints system is
904 + // based on max-width, as opposed to the old breakpoints system that worked based on min-width.
905 + $breakpoint_value--;
906 + }
886 907
887 - $kit_data_array['space_between_widgets'] = Utils::update_space_between_widgets_values( $kit_data_array['space_between_widgets'] );
908 + return $breakpoint_value;
909 + } );
888 910
889 - update_post_meta( (int) $kit_id, '_elementor_page_settings', $kit_data_array );
890 - }
911 + $kit_settings[ $prefix . Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ] = $breakpoint_values[ $old_mobile_option_key ];
912 + $kit_settings[ $prefix . Breakpoints_Manager::BREAKPOINT_KEY_TABLET ] = $breakpoint_values[ $old_tablet_option_key ];
891 913
892 - public static function remove_remote_info_api_data() {
893 - global $wpdb;
914 + $page_settings_manager = SettingsManager::get_settings_managers( 'page' );
915 + $page_settings_manager->save_settings( $kit_settings, $kit_id );
916 + };
894 917
895 - $key = Api::TRANSIENT_KEY_PREFIX;
896 -
897 - return $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '{$key}%';" ); // phpcs:ignore
918 + return self::move_settings_to_kit( $callback, $updater, $include_revisions );
898 919 }
899 920
900 921 /**
901 922 * @param callback $callback
@@ -939,80 +960,6 @@
939 960
940 961 private static function notice( $message ) {
941 962 $logger = Plugin::$instance->logger->get_logger();
942 963 $logger->notice( $message );
943 - }
944 -
945 - public static function get_post_ids_by_element_type( $updater, string $element_type ): array {
946 - global $wpdb;
947 -
948 - return $updater->query_col(
949 - 'SELECT `post_id`
950 - FROM `' . $wpdb->postmeta . '`
951 - WHERE `meta_key` = "_elementor_data"
952 - AND `meta_value` LIKE \'%"elType":"' . $element_type . '"%\';'
953 - );
954 - }
955 - /**
956 - * @param $data
957 - *
958 - * @return array|mixed
959 - */
960 - private static function iterate_containers( $data ) {
961 - return Plugin::$instance->db->iterate_data(
962 - $data, function ( $element ) {
963 -
964 - if ( 'container' !== $element['elType'] || ! isset( $element['elements'] ) ) {
965 - return $element;
966 - }
967 -
968 - $element = self::maybe_convert_to_inner_container( $element );
969 - $element = self::maybe_convert_to_grid_container( $element );
970 - return Container::slider_to_gaps_converter( $element );
971 - }
972 - );
973 - }
974 -
975 - /**
976 - * @param $element
977 - *
978 - * @return array
979 - */
980 - private static function maybe_convert_to_inner_container( $element ) {
981 - foreach ( $element['elements'] as &$inner_element ) {
982 - if ( 'container' === $inner_element['elType'] && ! $inner_element['isInner'] ) {
983 - $inner_element['isInner'] = true;
984 - }
985 - }
986 -
987 - return $element;
988 - }
989 -
990 - /**
991 - * @param $element
992 - *
993 - * @return array
994 - */
995 - private static function maybe_convert_to_grid_container( $element ) {
996 - $is_grid_container = isset( $element['settings']['container_type'] ) && 'grid' === $element['settings']['container_type'];
997 - if ( 'container' !== $element['elType'] || empty( $element['settings'] ) || ! $is_grid_container ) {
998 - return $element;
999 - }
1000 -
1001 - $element['settings']['presetTitle'] = 'Grid';
1002 - $element['settings']['presetIcon'] = 'eicon-container-grid';
1003 -
1004 - return $element;
1005 - }
1006 -
1007 - /**
1008 - * @param $post_id
1009 - * @param $data
1010 - *
1011 - * @return void
1012 - */
1013 - private static function save_updated_document( $post_id, $data ) {
1014 - $json_value = wp_slash( wp_json_encode( $data ) );
1015 -
1016 - update_metadata( 'post', $post_id, '_elementor_data', $json_value );
1017 964 }
1018 965 }