| @@ -1,18 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Core\Upgrade; |
| 3 | 3 | |
| 4 | -use Elementor\Api; | |
| 5 | -use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; | |
| 6 | -use Elementor\Core\Experiments\Manager as Experiments_Manager; | |
| 4 | +use Elementor\Core\Responsive\Responsive; | |
| 7 | 5 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 8 | -use Elementor\Core\Settings\Page\Manager as SettingsPageManager; | |
| 9 | 6 | use Elementor\Icons_Manager; |
| 10 | -use Elementor\Includes\Elements\Container; | |
| 11 | 7 | use Elementor\Modules\Usage\Module; |
| 12 | 8 | use Elementor\Plugin; |
| 13 | -use Elementor\Tracker; | |
| 14 | -use Elementor\App\Modules\ImportExport\Utils; | |
| 9 | +use Elementor\Utils; | |
| 15 | 10 | |
| 16 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | 12 | exit; // Exit if accessed directly. |
| 18 | 13 | } |
| @@ -26,21 +21,8 @@ | ||
| 26 | 21 | * @since 1.0.0 |
| 27 | 22 | */ |
| 28 | 23 | class Upgrades { |
| 29 | 24 | |
| 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 | 25 | /** |
| 44 | 26 | * Upgrade Elementor 0.3.2 |
| 45 | 27 | * |
| 46 | 28 | * Change the image widget link URL, setting is to `custom` link. |
| @@ -404,9 +386,9 @@ | ||
| 404 | 386 | update_metadata( 'post', $post_id, '_elementor_data', $json_value ); |
| 405 | 387 | |
| 406 | 388 | // Clear WP cache for next step. |
| 407 | 389 | wp_cache_flush(); |
| 408 | - } | |
| 390 | + } // End foreach(). | |
| 409 | 391 | } |
| 410 | 392 | |
| 411 | 393 | /** |
| 412 | 394 | * @param Updater $updater |
| @@ -479,9 +461,9 @@ | ||
| 479 | 461 | // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 480 | 462 | $json_value = wp_slash( wp_json_encode( $data ) ); |
| 481 | 463 | |
| 482 | 464 | update_metadata( 'post', $post_id, '_elementor_data', $json_value ); |
| 483 | - } | |
| 465 | + } // End foreach(). | |
| 484 | 466 | |
| 485 | 467 | return $updater->should_run_again( $post_ids ); |
| 486 | 468 | } |
| 487 | 469 | |
| @@ -515,9 +497,9 @@ | ||
| 515 | 497 | continue; |
| 516 | 498 | } |
| 517 | 499 | |
| 518 | 500 | $document->save_template_type(); |
| 519 | - } | |
| 501 | + } // End foreach(). | |
| 520 | 502 | |
| 521 | 503 | return $updater->should_run_again( $post_ids ); |
| 522 | 504 | } |
| 523 | 505 | |
| @@ -529,9 +511,9 @@ | ||
| 529 | 511 | add_option( 'elementor_load_fa4_shim', 'yes' ); |
| 530 | 512 | } |
| 531 | 513 | |
| 532 | 514 | /** |
| 533 | - * Migrate Icon control string value to Icons control array value | |
| 515 | + * migrate Icon control string value to Icons control array value | |
| 534 | 516 | * |
| 535 | 517 | * @param array $element |
| 536 | 518 | * @param array $args |
| 537 | 519 | * |
| @@ -581,10 +563,11 @@ | ||
| 581 | 563 | /** |
| 582 | 564 | * Update database to separate page from post. |
| 583 | 565 | * |
| 584 | 566 | * @param Updater $updater |
| 585 | - * @param string $type | |
| 586 | 567 | * |
| 568 | + * @param string $type | |
| 569 | + * | |
| 587 | 570 | * @return bool |
| 588 | 571 | */ |
| 589 | 572 | public static function rename_document_base_to_wp( $updater, $type ) { |
| 590 | 573 | global $wpdb; |
| @@ -608,8 +591,26 @@ | ||
| 608 | 591 | return $updater->should_run_again( $post_ids ); |
| 609 | 592 | } |
| 610 | 593 | |
| 611 | 594 | /** |
| 595 | + * Update database to separate page from post. | |
| 596 | + * | |
| 597 | + * @param Updater $updater | |
| 598 | + * | |
| 599 | + * @return bool | |
| 600 | + */ | |
| 601 | + // Because the query is slow on large sites, temporary don't upgrade. | |
| 602 | + /* public static function _v_2_7_0_rename_document_types_to_wp( $updater ) { | |
| 603 | + return self::rename_document_base_to_wp( $updater, 'post' ) || self::rename_document_base_to_wp( $updater, 'page' ); | |
| 604 | + }*/ | |
| 605 | + | |
| 606 | + // Upgrade code was fixed & moved to _v_2_7_1_remove_old_usage_data. | |
| 607 | + /* public static function _v_2_7_0_remove_old_usage_data() {} */ | |
| 608 | + | |
| 609 | + // Upgrade code moved to _v_2_7_1_recalc_usage_data. | |
| 610 | + /* public static function _v_2_7_0_recalc_usage_data( $updater ) {} */ | |
| 611 | + | |
| 612 | + /** | |
| 612 | 613 | * Don't use the old data anymore. |
| 613 | 614 | * Since 2.7.1 the key was changed from `elementor_elements_usage` to `elementor_controls_usage`. |
| 614 | 615 | */ |
| 615 | 616 | public static function _v_2_7_1_remove_old_usage_data() { |
| @@ -624,12 +625,8 @@ | ||
| 624 | 625 | * |
| 625 | 626 | * @return bool |
| 626 | 627 | */ |
| 627 | 628 | public static function recalc_usage_data( $updater ) { |
| 628 | - if ( ! Tracker::is_allow_track() ) { | |
| 629 | - return false; | |
| 630 | - } | |
| 631 | - | |
| 632 | 629 | /** @var Module $module */ |
| 633 | 630 | $module = Plugin::$instance->modules_manager->get_modules( 'usage' ); |
| 634 | 631 | |
| 635 | 632 | $post_count = $module->recalc_usage( $updater->get_limit(), $updater->get_current_offset() ); |
| @@ -661,14 +658,12 @@ | ||
| 661 | 658 | self::notice( 'Kit not found. nothing to do.' ); |
| 662 | 659 | return; |
| 663 | 660 | } |
| 664 | 661 | |
| 665 | - $meta_key = SettingsPageManager::META_KEY; | |
| 662 | + $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY; | |
| 666 | 663 | $current_settings = get_option( '_elementor_general_settings', [] ); |
| 667 | - // Take the `space_between_widgets` from the option due to a bug on E < 3.0.0 that the value `0` is stored separated. | |
| 668 | - $current_settings['space_between_widgets'] = get_option( 'elementor_space_between_widgets', '' ); | |
| 669 | - $current_settings[ Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . 'md' ] = get_option( 'elementor_viewport_md', '' ); | |
| 670 | - $current_settings[ Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . 'lg' ] = get_option( 'elementor_viewport_lg', '' ); | |
| 664 | + $current_settings[ Responsive::BREAKPOINT_OPTION_PREFIX . 'md' ] = get_option( 'elementor_viewport_md', '' ); | |
| 665 | + $current_settings[ Responsive::BREAKPOINT_OPTION_PREFIX . 'lg' ] = get_option( 'elementor_viewport_lg', '' ); | |
| 671 | 666 | |
| 672 | 667 | $kit_settings = $kit->get_meta( $meta_key ); |
| 673 | 668 | |
| 674 | 669 | // Already exist. |
| @@ -692,9 +687,9 @@ | ||
| 692 | 687 | 'space_between_widgets', |
| 693 | 688 | ]; |
| 694 | 689 | |
| 695 | 690 | foreach ( $settings_to_slider as $setting ) { |
| 696 | - if ( isset( $current_settings[ $setting ] ) ) { | |
| 691 | + if ( ! empty( $current_settings[ $setting ] ) ) { | |
| 697 | 692 | $current_settings[ $setting ] = [ |
| 698 | 693 | 'unit' => 'px', |
| 699 | 694 | 'size' => $current_settings[ $setting ], |
| 700 | 695 | ]; |
| @@ -709,195 +704,205 @@ | ||
| 709 | 704 | |
| 710 | 705 | return self::move_settings_to_kit( $callback, $updater ); |
| 711 | 706 | } |
| 712 | 707 | |
| 713 | - public static function _v_3_2_0_migrate_breakpoints_to_new_system( $updater, $include_revisions = true ) { | |
| 708 | + /** | |
| 709 | + * Move default colors settings to active kit and all it's revisions. | |
| 710 | + * | |
| 711 | + * @param Updater $updater | |
| 712 | + * | |
| 713 | + * @return bool | |
| 714 | + */ | |
| 715 | + public static function _v_3_0_0_move_default_colors_to_kit( $updater, $include_revisions = true ) { | |
| 714 | 716 | $callback = function( $kit_id ) { |
| 717 | + if ( ! Plugin::$instance->kits_manager->is_custom_colors_enabled() ) { | |
| 718 | + self::notice( 'System colors are disabled. nothing to do.' ); | |
| 719 | + return; | |
| 720 | + } | |
| 721 | + | |
| 715 | 722 | $kit = Plugin::$instance->documents->get( $kit_id ); |
| 716 | 723 | |
| 717 | - $kit_settings = $kit->get_meta( SettingsPageManager::META_KEY ); | |
| 718 | - | |
| 719 | - if ( ! $kit_settings ) { | |
| 720 | - // Nothing to upgrade. | |
| 724 | + // Already exist. use raw settings that doesn't have default values. | |
| 725 | + $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY; | |
| 726 | + $kit_raw_settings = $kit->get_meta( $meta_key ); | |
| 727 | + if ( isset( $kit_raw_settings['system_colors'] ) ) { | |
| 728 | + self::notice( 'System colors already exist. nothing to do.' ); | |
| 721 | 729 | return; |
| 722 | 730 | } |
| 723 | 731 | |
| 724 | - $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX; | |
| 725 | - $old_mobile_option_key = $prefix . 'md'; | |
| 726 | - $old_tablet_option_key = $prefix . 'lg'; | |
| 732 | + $scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color' ); | |
| 727 | 733 | |
| 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 ), | |
| 734 | + $default_colors = $scheme_obj->get_scheme(); | |
| 735 | + | |
| 736 | + $new_ids = [ | |
| 737 | + 'primary', | |
| 738 | + 'secondary', | |
| 739 | + 'text', | |
| 740 | + 'accent', | |
| 731 | 741 | ]; |
| 732 | 742 | |
| 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 | - } | |
| 743 | + foreach ( $default_colors as $index => $color ) { | |
| 744 | + $kit->add_repeater_row( 'system_colors', [ | |
| 745 | + '_id' => $new_ids[ $index - 1 ], // $default_colors starts from 1. | |
| 746 | + 'title' => $color['title'], | |
| 747 | + 'color' => strtoupper( $color['value'] ), | |
| 748 | + ] ); | |
| 749 | + } | |
| 750 | + }; | |
| 740 | 751 | |
| 741 | - return $breakpoint_value; | |
| 742 | - } ); | |
| 752 | + return self::move_settings_to_kit( $callback, $updater, $include_revisions ); | |
| 753 | + } | |
| 743 | 754 | |
| 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 ]; | |
| 755 | + /** | |
| 756 | + * Move saved colors settings to active kit and all it's revisions. | |
| 757 | + * | |
| 758 | + * @param Updater $updater | |
| 759 | + * | |
| 760 | + * @return bool | |
| 761 | + */ | |
| 762 | + public static function _v_3_0_0_move_saved_colors_to_kit( $updater, $include_revisions = true ) { | |
| 763 | + $callback = function( $kit_id ) { | |
| 764 | + $kit = Plugin::$instance->documents->get( $kit_id ); | |
| 746 | 765 | |
| 747 | - $page_settings_manager = SettingsManager::get_settings_managers( 'page' ); | |
| 748 | - $page_settings_manager->save_settings( $kit_settings, $kit_id ); | |
| 749 | - }; | |
| 766 | + // Already exist. use raw settings that doesn't have default values. | |
| 767 | + $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY; | |
| 768 | + $kit_raw_settings = $kit->get_meta( $meta_key ); | |
| 769 | + if ( isset( $kit_raw_settings['custom_colors'] ) ) { | |
| 770 | + self::notice( 'Custom colors already exist. nothing to do.' ); | |
| 771 | + return; | |
| 772 | + } | |
| 750 | 773 | |
| 751 | - return self::move_settings_to_kit( $callback, $updater, $include_revisions ); | |
| 752 | - } | |
| 774 | + $system_colors_rows = $kit->get_settings( 'system_colors' ); | |
| 753 | 775 | |
| 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 ); | |
| 776 | + if ( ! $system_colors_rows ) { | |
| 777 | + $system_colors_rows = []; | |
| 778 | + } | |
| 757 | 779 | |
| 758 | - if ( '1' === $load_fa4_shim_option ) { | |
| 759 | - update_option( Icons_Manager::LOAD_FA4_SHIM_OPTION_KEY, 'yes' ); | |
| 760 | - } | |
| 761 | - } | |
| 780 | + $system_colors = []; | |
| 762 | 781 | |
| 763 | - public static function _v_3_5_0_remove_old_elementor_scheme() { | |
| 764 | - global $wpdb; | |
| 782 | + foreach ( $system_colors_rows as $color_row ) { | |
| 783 | + $system_colors[] = strtoupper( $color_row['color'] ); | |
| 784 | + } | |
| 765 | 785 | |
| 766 | - $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'elementor_scheme_%';" ); | |
| 767 | - } | |
| 786 | + $saved_scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color-picker' ); | |
| 768 | 787 | |
| 769 | - public static function _v_3_8_0_fix_php8_image_custom_size() { | |
| 770 | - global $wpdb; | |
| 788 | + $current_saved_colors_rows = $saved_scheme_obj->get_scheme(); | |
| 771 | 789 | |
| 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 | - ); | |
| 790 | + $current_saved_colors = []; | |
| 779 | 791 | |
| 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; | |
| 792 | + foreach ( $current_saved_colors_rows as $color_row ) { | |
| 793 | + $current_saved_colors[] = strtoupper( $color_row['value'] ); | |
| 784 | 794 | } |
| 785 | 795 | |
| 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 | - } | |
| 796 | + $colors_to_save = array_diff( $current_saved_colors, $system_colors ); | |
| 791 | 797 | |
| 792 | - if ( absint( $size_value['width'] ) !== $size_value['width'] ) { | |
| 793 | - $attachment_metadata['sizes'][ $size_key ]['width'] = (int) $size_value['width']; | |
| 794 | - } | |
| 795 | - | |
| 796 | - if ( absint( $size_value['height'] ) !== $size_value['height'] ) { | |
| 797 | - $attachment_metadata['sizes'][ $size_key ]['height'] = (int) $size_value['height']; | |
| 798 | - } | |
| 798 | + if ( empty( $colors_to_save ) ) { | |
| 799 | + self::notice( 'Saved colors not found. nothing to do.' ); | |
| 800 | + return; | |
| 799 | 801 | } |
| 800 | 802 | |
| 801 | - if ( $old_attachment_metadata['sizes'] === $attachment_metadata['sizes'] ) { | |
| 802 | - continue; | |
| 803 | + foreach ( $colors_to_save as $index => $color ) { | |
| 804 | + $kit->add_repeater_row( 'custom_colors', [ | |
| 805 | + '_id' => Utils::generate_random_string(), | |
| 806 | + 'title' => __( 'Saved Color', 'elementor' ) . ' #' . ( $index + 1 ), | |
| 807 | + 'color' => $color, | |
| 808 | + ] ); | |
| 803 | 809 | } |
| 810 | + }; | |
| 804 | 811 | |
| 805 | - wp_update_attachment_metadata( $attachment_id, $attachment_metadata ); | |
| 806 | - } | |
| 812 | + return self::move_settings_to_kit( $callback, $updater, $include_revisions ); | |
| 807 | 813 | } |
| 808 | 814 | |
| 809 | - public static function _v_3_16_0_container_updates( $updater ) { | |
| 810 | - $post_ids = self::get_post_ids_by_element_type( $updater, 'container' ); | |
| 815 | + /** | |
| 816 | + * Move default typography settings to active kit and all it's revisions. | |
| 817 | + * | |
| 818 | + * @param Updater $updater | |
| 819 | + * | |
| 820 | + * @return bool | |
| 821 | + */ | |
| 822 | + public static function _v_3_0_0_move_default_typography_to_kit( $updater, $include_revisions = true ) { | |
| 823 | + $callback = function( $kit_id ) { | |
| 824 | + if ( ! Plugin::$instance->kits_manager->is_custom_typography_enabled() ) { | |
| 825 | + self::notice( 'System typography is disabled. nothing to do.' ); | |
| 826 | + return; | |
| 827 | + } | |
| 811 | 828 | |
| 812 | - if ( empty( $post_ids ) ) { | |
| 813 | - return false; | |
| 814 | - } | |
| 829 | + $kit = Plugin::$instance->documents->get( $kit_id ); | |
| 815 | 830 | |
| 816 | - foreach ( $post_ids as $post_id ) { | |
| 817 | - $document = Plugin::$instance->documents->get( $post_id ); | |
| 818 | - | |
| 819 | - if ( $document ) { | |
| 820 | - $data = $document->get_elements_data(); | |
| 831 | + // Already exist. use raw settings that doesn't have default values. | |
| 832 | + $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY; | |
| 833 | + $kit_raw_settings = $kit->get_meta( $meta_key ); | |
| 834 | + if ( isset( $kit_raw_settings['system_typography'] ) ) { | |
| 835 | + self::notice( 'System typography already exist. nothing to do.' ); | |
| 836 | + return; | |
| 821 | 837 | } |
| 822 | 838 | |
| 823 | - if ( empty( $data ) ) { | |
| 824 | - continue; | |
| 825 | - } | |
| 839 | + $scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'typography' ); | |
| 826 | 840 | |
| 827 | - $data = self::iterate_containers( $data ); | |
| 841 | + $default_typography = $scheme_obj->get_scheme(); | |
| 828 | 842 | |
| 829 | - self::save_updated_document( $post_id, $data ); | |
| 830 | - } | |
| 831 | - } | |
| 843 | + $new_ids = [ | |
| 844 | + 'primary', | |
| 845 | + 'secondary', | |
| 846 | + 'text', | |
| 847 | + 'accent', | |
| 848 | + ]; | |
| 832 | 849 | |
| 833 | - public static function _v_3_17_0_site_settings_updates() { | |
| 834 | - $options = [ 'elementor_active_kit', 'elementor_previous_kit' ]; | |
| 850 | + foreach ( $default_typography as $index => $typography ) { | |
| 851 | + $kit->add_repeater_row( 'system_typography', [ | |
| 852 | + '_id' => $new_ids[ $index - 1 ], // $default_typography starts from 1. | |
| 853 | + 'title' => $typography['title'], | |
| 854 | + 'typography_typography' => 'custom', | |
| 855 | + 'typography_font_family' => $typography['value']['font_family'], | |
| 856 | + 'typography_font_weight' => $typography['value']['font_weight'], | |
| 857 | + ] ); | |
| 858 | + } | |
| 859 | + }; | |
| 835 | 860 | |
| 836 | - foreach ( $options as $option_name ) { | |
| 837 | - self::maybe_add_gap_control_data( $option_name ); | |
| 838 | - } | |
| 861 | + return self::move_settings_to_kit( $callback, $updater, $include_revisions ); | |
| 839 | 862 | } |
| 840 | 863 | |
| 841 | 864 | /** |
| 842 | - * Upgrade Elementor 3.26.0 - Delete old experiments from the DB. | |
| 865 | + * Re move `space_between_widgets` settings to kit. | |
| 843 | 866 | * |
| 844 | - * @since 3.26.0 | |
| 845 | - * @static | |
| 846 | - * @access public | |
| 867 | + * Due to a bug in previous upgrade, the setting `space_between_widgets` with a value `0` didn't upgraded properly. | |
| 868 | + * Try to re move it, if it's not already set manually in the kit. | |
| 869 | + * | |
| 870 | + * @param $updater | |
| 871 | + * | |
| 872 | + * @return false|mixed | |
| 847 | 873 | */ |
| 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 | - } | |
| 874 | + public static function _v_3_0_5_re_move_space_between_widgets_to_kit( $updater ) { | |
| 875 | + $callback = function( $kit_id ) { | |
| 876 | + $kit = Plugin::$instance->documents->get( $kit_id ); | |
| 870 | 877 | |
| 871 | - private static function maybe_add_gap_control_data( $option_name ) { | |
| 872 | - $kit_id = get_option( $option_name ); | |
| 878 | + if ( ! $kit ) { | |
| 879 | + self::notice( 'Kit not found. nothing to do.' ); | |
| 880 | + return; | |
| 881 | + } | |
| 873 | 882 | |
| 874 | - if ( ! $kit_id ) { | |
| 875 | - return; | |
| 876 | - } | |
| 883 | + $meta_key = \Elementor\Core\Settings\Page\Manager::META_KEY; | |
| 884 | + $old_settings = get_option( '_elementor_general_settings', [] ); | |
| 885 | + $kit_settings = $kit->get_meta( $meta_key ); | |
| 877 | 886 | |
| 878 | - $kit_data_array = get_post_meta( (int) $kit_id, '_elementor_page_settings', true ); | |
| 887 | + if ( ! $kit_settings ) { | |
| 888 | + $kit_settings = []; | |
| 889 | + } | |
| 879 | 890 | |
| 880 | - $setting_not_exist = ! isset( $kit_data_array['space_between_widgets'] ); | |
| 881 | - $already_processed = isset( $kit_data_array['space_between_widgets']['column'] ); | |
| 891 | + if ( isset( $old_settings['space_between_widgets'] ) && ! isset( $kit_settings['space_between_widgets'] ) ) { | |
| 892 | + $kit_settings['space_between_widgets'] = [ | |
| 893 | + 'unit' => 'px', | |
| 894 | + 'size' => $old_settings['space_between_widgets'], | |
| 895 | + ]; | |
| 882 | 896 | |
| 883 | - if ( $setting_not_exist || $already_processed ) { | |
| 884 | - return; | |
| 885 | - } | |
| 897 | + $page_settings_manager = SettingsManager::get_settings_managers( 'page' ); | |
| 898 | + $page_settings_manager->save_settings( $kit_settings, $kit_id ); | |
| 899 | + } | |
| 900 | + }; | |
| 886 | 901 | |
| 887 | - $kit_data_array['space_between_widgets'] = Utils::update_space_between_widgets_values( $kit_data_array['space_between_widgets'] ); | |
| 888 | - | |
| 889 | - update_post_meta( (int) $kit_id, '_elementor_page_settings', $kit_data_array ); | |
| 902 | + return self::move_settings_to_kit( $callback, $updater ); | |
| 890 | 903 | } |
| 891 | 904 | |
| 892 | - public static function remove_remote_info_api_data() { | |
| 893 | - global $wpdb; | |
| 894 | - | |
| 895 | - $key = Api::TRANSIENT_KEY_PREFIX; | |
| 896 | - | |
| 897 | - return $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '{$key}%';" ); // phpcs:ignore | |
| 898 | - } | |
| 899 | - | |
| 900 | 905 | /** |
| 901 | 906 | * @param callback $callback |
| 902 | 907 | * @param Updater $updater |
| 903 | 908 | * |
| @@ -939,80 +944,6 @@ | ||
| 939 | 944 | |
| 940 | 945 | private static function notice( $message ) { |
| 941 | 946 | $logger = Plugin::$instance->logger->get_logger(); |
| 942 | 947 | $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 | 948 | } |
| 1018 | 949 | } |