| @@ -5,9 +5,8 @@ | ||
| 5 | 5 | use Elementor\Core\Base\Elements_Iteration_Actions\Base as Elements_Iteration_Action; |
| 6 | 6 | use Elementor\Core\Behaviors\Interfaces\Lock_Behavior; |
| 7 | 7 | use Elementor\Core\Files\CSS\Post as Post_CSS; |
| 8 | 8 | use Elementor\Core\Settings\Page\Model as Page_Model; |
| 9 | -use Elementor\Core\Utils\Collection; | |
| 10 | 9 | use Elementor\Core\Utils\Exceptions; |
| 11 | 10 | use Elementor\Includes\Elements\Container; |
| 12 | 11 | use Elementor\Plugin; |
| 13 | 12 | use Elementor\Controls_Manager; |
| @@ -18,12 +17,11 @@ | ||
| 18 | 17 | use Elementor\Utils; |
| 19 | 18 | use Elementor\Widget_Base; |
| 20 | 19 | use Elementor\Core\Settings\Page\Manager as PageManager; |
| 21 | 20 | use ElementorPro\Modules\Library\Widgets\Template; |
| 22 | -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; | |
| 23 | 21 | |
| 24 | 22 | if ( ! defined( 'ABSPATH' ) ) { |
| 25 | - exit; // Exit if accessed directly. | |
| 23 | + exit; // Exit if accessed directly | |
| 26 | 24 | } |
| 27 | 25 | |
| 28 | 26 | /** |
| 29 | 27 | * Elementor document. |
| @@ -40,14 +38,11 @@ | ||
| 40 | 38 | * Document type meta key. |
| 41 | 39 | */ |
| 42 | 40 | const TYPE_META_KEY = '_elementor_template_type'; |
| 43 | 41 | const PAGE_META_KEY = '_elementor_page_settings'; |
| 44 | - const ELEMENTOR_DATA_META_KEY = '_elementor_data'; | |
| 45 | 42 | |
| 46 | 43 | const BUILT_WITH_ELEMENTOR_META_KEY = '_elementor_edit_mode'; |
| 47 | 44 | |
| 48 | - const CACHE_META_KEY = '_elementor_element_cache'; | |
| 49 | - | |
| 50 | 45 | /** |
| 51 | 46 | * Document publish status. |
| 52 | 47 | */ |
| 53 | 48 | const STATUS_PUBLISH = 'publish'; |
| @@ -71,11 +66,9 @@ | ||
| 71 | 66 | * Document pending status. |
| 72 | 67 | */ |
| 73 | 68 | const STATUS_PENDING = 'pending'; |
| 74 | 69 | |
| 75 | - /** | |
| 76 | - * @var int | |
| 77 | - */ | |
| 70 | + | |
| 78 | 71 | private $main_id; |
| 79 | 72 | |
| 80 | 73 | /** |
| 81 | 74 | * @var bool |
| @@ -101,44 +94,8 @@ | ||
| 101 | 94 | */ |
| 102 | 95 | protected $post; |
| 103 | 96 | |
| 104 | 97 | /** |
| 105 | - * @param array $internal_elements | |
| 106 | - * | |
| 107 | - * @return array[] | |
| 108 | - */ | |
| 109 | - private function get_container_elements_data( array $internal_elements ): array { | |
| 110 | - return [ | |
| 111 | - [ | |
| 112 | - 'id' => Utils::generate_random_string(), | |
| 113 | - 'elType' => 'container', | |
| 114 | - 'elements' => $internal_elements, | |
| 115 | - ], | |
| 116 | - ]; | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * @param array $internal_elements | |
| 121 | - * | |
| 122 | - * @return array[] | |
| 123 | - */ | |
| 124 | - private function get_sections_elements_data( array $internal_elements ): array { | |
| 125 | - return [ | |
| 126 | - [ | |
| 127 | - 'id' => Utils::generate_random_string(), | |
| 128 | - 'elType' => 'section', | |
| 129 | - 'elements' => [ | |
| 130 | - [ | |
| 131 | - 'id' => Utils::generate_random_string(), | |
| 132 | - 'elType' => 'column', | |
| 133 | - 'elements' => $internal_elements, | |
| 134 | - ], | |
| 135 | - ], | |
| 136 | - ], | |
| 137 | - ]; | |
| 138 | - } | |
| 139 | - | |
| 140 | - /** | |
| 141 | 98 | * @since 2.1.0 |
| 142 | 99 | * @access protected |
| 143 | 100 | * @static |
| 144 | 101 | */ |
| @@ -164,15 +121,8 @@ | ||
| 164 | 121 | 'edit_capability' => '', |
| 165 | 122 | 'show_in_finder' => true, |
| 166 | 123 | 'show_on_admin_bar' => true, |
| 167 | 124 | 'support_kit' => false, |
| 168 | - 'show_navigator' => true, | |
| 169 | - 'allow_adding_widgets' => true, | |
| 170 | - 'support_page_layout' => true, | |
| 171 | - 'show_copy_and_share' => false, | |
| 172 | - 'library_close_title' => esc_html__( 'Close', 'elementor' ), | |
| 173 | - 'publish_button_title' => esc_html__( 'Publish', 'elementor' ), | |
| 174 | - 'allow_closing_remote_library' => true, | |
| 175 | 125 | ]; |
| 176 | 126 | } |
| 177 | 127 | |
| 178 | 128 | /** |
| @@ -189,63 +139,20 @@ | ||
| 189 | 139 | |
| 190 | 140 | return [ |
| 191 | 141 | 'title' => static::get_title(), // JS Container title. |
| 192 | 142 | 'widgets_settings' => [], |
| 193 | - 'elements_categories' => self::get_filtered_editor_panel_categories(), | |
| 143 | + 'elements_categories' => static::get_editor_panel_categories(), | |
| 194 | 144 | 'default_route' => $default_route, |
| 195 | 145 | 'has_elements' => static::get_property( 'has_elements' ), |
| 196 | 146 | 'support_kit' => static::get_property( 'support_kit' ), |
| 197 | 147 | 'messages' => [ |
| 198 | - 'publish_notification' => sprintf( | |
| 199 | - /* translators: %s: Document title. */ | |
| 200 | - esc_html__( 'Hurray! Your %s is live.', 'elementor' ), | |
| 201 | - static::get_title() | |
| 202 | - ), | |
| 148 | + /* translators: %s: Document title. */ | |
| 149 | + 'publish_notification' => sprintf( esc_html__( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ), | |
| 203 | 150 | ], |
| 204 | - 'show_navigator' => static::get_property( 'show_navigator' ), | |
| 205 | - 'allow_adding_widgets' => static::get_property( 'allow_adding_widgets' ), | |
| 206 | - 'show_copy_and_share' => static::get_property( 'show_copy_and_share' ), | |
| 207 | - 'library_close_title' => static::get_property( 'library_close_title' ), | |
| 208 | - 'publish_button_title' => static::get_property( 'publish_button_title' ), | |
| 209 | - 'allow_closing_remote_library' => static::get_property( 'allow_closing_remote_library' ), | |
| 210 | 151 | ]; |
| 211 | 152 | } |
| 212 | 153 | |
| 213 | - public static function get_filtered_editor_panel_categories(): array { | |
| 214 | - $categories = static::get_editor_panel_categories(); | |
| 215 | - $has_pro = Utils::has_pro(); | |
| 216 | - | |
| 217 | - foreach ( $categories as $index => $category ) { | |
| 218 | - if ( isset( $category['promotion'] ) ) { | |
| 219 | - $categories = self::get_panel_category_item( $category['promotion'], $index, $categories, $has_pro ); | |
| 220 | - } | |
| 221 | - } | |
| 222 | - | |
| 223 | - return $categories; | |
| 224 | - } | |
| 225 | - | |
| 226 | 154 | /** |
| 227 | - * @param $promotion | |
| 228 | - * @param $index | |
| 229 | - * @param array $categories | |
| 230 | - * | |
| 231 | - * @return array | |
| 232 | - */ | |
| 233 | - private static function get_panel_category_item( $promotion, $index, array $categories, bool $has_pro ): array { | |
| 234 | - if ( ! $has_pro ) { | |
| 235 | - $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data( | |
| 236 | - $promotion, | |
| 237 | - 'elementor/panel/' . $index . '/custom_promotion', | |
| 238 | - 'url' | |
| 239 | - ); | |
| 240 | - } else { | |
| 241 | - unset( $categories[ $index ]['promotion'] ); | |
| 242 | - } | |
| 243 | - | |
| 244 | - return $categories; | |
| 245 | - } | |
| 246 | - | |
| 247 | - /** | |
| 248 | 155 | * Get element title. |
| 249 | 156 | * |
| 250 | 157 | * Retrieve the element title. |
| 251 | 158 | * |
| @@ -263,13 +170,9 @@ | ||
| 263 | 170 | return static::get_title(); |
| 264 | 171 | } |
| 265 | 172 | |
| 266 | 173 | public static function get_add_new_title() { |
| 267 | - return sprintf( | |
| 268 | - /* translators: %s: Document title. */ | |
| 269 | - esc_html__( 'Add New %s', 'elementor' ), | |
| 270 | - static::get_title() | |
| 271 | - ); | |
| 174 | + return sprintf( esc_html__( 'Add New %s', 'elementor' ), static::get_title() ); | |
| 272 | 175 | } |
| 273 | 176 | |
| 274 | 177 | /** |
| 275 | 178 | * Get property. |
| @@ -437,12 +340,12 @@ | ||
| 437 | 340 | $main_post_id = $this->get_main_id(); |
| 438 | 341 | $document = $this; |
| 439 | 342 | |
| 440 | 343 | // Ajax request from editor. |
| 441 | - $initial_document_id = Utils::get_super_global_value( $_POST, 'initial_document_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 442 | - | |
| 443 | - if ( ! empty( $initial_document_id ) ) { | |
| 444 | - $document = Plugin::$instance->documents->get( $initial_document_id ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 344 | + // PHPCS - only reading the value from $_POST['initial_document_id']. | |
| 345 | + if ( ! empty( $_POST['initial_document_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 346 | + // PHPCS - only reading the value from $_POST['initial_document_id']. | |
| 347 | + $document = Plugin::$instance->documents->get( $_POST['initial_document_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 445 | 348 | } |
| 446 | 349 | |
| 447 | 350 | $url = get_preview_post_link( |
| 448 | 351 | $document->get_main_id(), |
| @@ -550,10 +453,12 @@ | ||
| 550 | 453 | * |
| 551 | 454 | * @since 2.0.0 |
| 552 | 455 | * @access public |
| 553 | 456 | * |
| 457 | + * | |
| 554 | 458 | * @return bool|Document |
| 555 | 459 | */ |
| 460 | + | |
| 556 | 461 | public function get_newer_autosave() { |
| 557 | 462 | $autosave = $this->get_autosave(); |
| 558 | 463 | |
| 559 | 464 | // Detect if there exists an autosave newer than the post. |
| @@ -608,12 +513,8 @@ | ||
| 608 | 513 | |
| 609 | 514 | if ( $autosave_id ) { |
| 610 | 515 | $document = Plugin::$instance->documents->get( $autosave_id ); |
| 611 | 516 | } elseif ( $create ) { |
| 612 | - if ( ! function_exists( 'wp_create_post_autosave' ) ) { | |
| 613 | - require_once ABSPATH . 'wp-admin/includes/post.php'; | |
| 614 | - } | |
| 615 | - | |
| 616 | 517 | $autosave_id = wp_create_post_autosave( [ |
| 617 | 518 | 'post_ID' => $this->post->ID, |
| 618 | 519 | 'post_type' => $this->post->post_type, |
| 619 | 520 | 'post_title' => $this->post->post_title, |
| @@ -642,9 +543,9 @@ | ||
| 642 | 543 | * Fired by `post_row_actions` and `page_row_actions` filters. |
| 643 | 544 | * |
| 644 | 545 | * @access public |
| 645 | 546 | * |
| 646 | - * @param array $actions An array of row action links. | |
| 547 | + * @param array $actions An array of row action links. | |
| 647 | 548 | * |
| 648 | 549 | * @return array An updated array of row action links. |
| 649 | 550 | */ |
| 650 | 551 | public function filter_admin_row_actions( $actions ) { |
| @@ -684,12 +585,10 @@ | ||
| 684 | 585 | if ( $locked_user ) { |
| 685 | 586 | $locked_user = $locked_user->display_name; |
| 686 | 587 | } |
| 687 | 588 | |
| 688 | - $post = $this->get_main_post(); | |
| 589 | + $post_type_object = get_post_type_object( $this->get_main_post()->post_type ); | |
| 689 | 590 | |
| 690 | - $post_type_object = get_post_type_object( $post->post_type ); | |
| 691 | - | |
| 692 | 591 | $settings = SettingsManager::get_settings_managers_config(); |
| 693 | 592 | |
| 694 | 593 | $config = [ |
| 695 | 594 | 'id' => $this->get_main_id(), |
| @@ -717,28 +616,22 @@ | ||
| 717 | 616 | 'main_dashboard' => $this->get_main_dashboard_url(), |
| 718 | 617 | ], |
| 719 | 618 | ]; |
| 720 | 619 | |
| 721 | - $post_status_object = get_post_status_object( $post->post_status ); | |
| 722 | - | |
| 723 | - if ( $post_status_object ) { | |
| 724 | - $config['status'] = [ | |
| 725 | - 'value' => $post_status_object->name, | |
| 726 | - 'label' => $post_status_object->label, | |
| 727 | - ]; | |
| 728 | - } | |
| 729 | - | |
| 730 | 620 | do_action( 'elementor/document/before_get_config', $this ); |
| 731 | 621 | |
| 732 | 622 | if ( static::get_property( 'has_elements' ) ) { |
| 733 | - $elements_config = Collection::make( Plugin::$instance->elements_manager->get_element_types() ) | |
| 734 | - ->filter( fn( $element ) => ( ! empty( $element->get_config()['include_in_widgets_config'] ) ) ) | |
| 735 | - ->map( fn( $element ) => $element->get_config() ) | |
| 736 | - ->all(); | |
| 623 | + $container_config = []; | |
| 624 | + $experiments_manager = Plugin::$instance->experiments; | |
| 737 | 625 | |
| 626 | + if ( $experiments_manager->is_feature_active( 'container' ) ) { | |
| 627 | + $container_config = [ | |
| 628 | + 'container' => Plugin::$instance->elements_manager->get_element_types( 'container' )->get_config(), | |
| 629 | + ]; | |
| 630 | + } | |
| 631 | + | |
| 738 | 632 | $config['elements'] = $this->get_elements_raw_data( null, true ); |
| 739 | - // `get_elements_raw_data` has to be called before `get_widget_types_config`, because it affects it. | |
| 740 | - $config['widgets'] = array_merge( $elements_config, Plugin::$instance->widgets_manager->get_widget_types_config() ); | |
| 633 | + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config(); | |
| 741 | 634 | } |
| 742 | 635 | |
| 743 | 636 | $additional_config = []; |
| 744 | 637 | |
| @@ -793,16 +686,8 @@ | ||
| 793 | 686 | * @return bool |
| 794 | 687 | */ |
| 795 | 688 | public function save( $data ) { |
| 796 | 689 | /** |
| 797 | - * Set locale to "C" to avoid issues with comma as decimal separator. | |
| 798 | - * | |
| 799 | - * @see https://github.com/elementor/elementor/issues/10992 | |
| 800 | - */ | |
| 801 | - $original_lc = setlocale( LC_NUMERIC, 0 ); | |
| 802 | - setlocale( LC_NUMERIC, 'C' ); | |
| 803 | - | |
| 804 | - /** | |
| 805 | 690 | * Document save data. |
| 806 | 691 | * |
| 807 | 692 | * Filter the document data before saving process starts. |
| 808 | 693 | * |
| @@ -836,11 +721,9 @@ | ||
| 836 | 721 | */ |
| 837 | 722 | do_action( 'elementor/document/before_save', $this, $data ); |
| 838 | 723 | |
| 839 | 724 | if ( ! current_user_can( 'unfiltered_html' ) ) { |
| 840 | - $data = map_deep( $data, function ( $value ) { | |
| 841 | - return is_bool( $value ) || is_null( $value ) ? $value : wp_kses_post( $value ); | |
| 842 | - } ); | |
| 725 | + $data = wp_kses_post_deep( $data ); | |
| 843 | 726 | } |
| 844 | 727 | |
| 845 | 728 | if ( ! empty( $data['settings'] ) ) { |
| 846 | 729 | if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) { |
| @@ -867,11 +750,8 @@ | ||
| 867 | 750 | $post_css = Post_CSS::create( $this->post->ID ); |
| 868 | 751 | |
| 869 | 752 | $post_css->delete(); |
| 870 | 753 | |
| 871 | - // Remove Document Cache | |
| 872 | - $this->delete_cache(); | |
| 873 | - | |
| 874 | 754 | /** |
| 875 | 755 | * After document save. |
| 876 | 756 | * |
| 877 | 757 | * Fires when document save is complete. |
| @@ -886,10 +766,8 @@ | ||
| 886 | 766 | $this->set_is_saving( false ); |
| 887 | 767 | |
| 888 | 768 | $this->remove_handle_revisions_changed_filter(); |
| 889 | 769 | |
| 890 | - setlocale( LC_NUMERIC, $original_lc ); | |
| 891 | - | |
| 892 | 770 | return true; |
| 893 | 771 | } |
| 894 | 772 | |
| 895 | 773 | public function refresh_post() { |
| @@ -925,9 +803,9 @@ | ||
| 925 | 803 | * |
| 926 | 804 | * @return bool Whether the post was built with Elementor. |
| 927 | 805 | */ |
| 928 | 806 | public function is_built_with_elementor() { |
| 929 | - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 807 | + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 930 | 808 | } |
| 931 | 809 | |
| 932 | 810 | /** |
| 933 | 811 | * Mark the post as "built with elementor" or not. |
| @@ -1037,9 +915,9 @@ | ||
| 1037 | 915 | return $meta; |
| 1038 | 916 | } |
| 1039 | 917 | |
| 1040 | 918 | public function update_json_meta( $key, $value ) { |
| 1041 | - return $this->update_meta( | |
| 919 | + $this->update_meta( | |
| 1042 | 920 | $key, |
| 1043 | 921 | // `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1044 | 922 | wp_slash( wp_json_encode( $value ) ) |
| 1045 | 923 | ); |
| @@ -1052,10 +930,8 @@ | ||
| 1052 | 930 | * @param null $data |
| 1053 | 931 | * @param bool $with_html_content |
| 1054 | 932 | * |
| 1055 | 933 | * @return array |
| 1056 | - * | |
| 1057 | - * @throws \Exception If elements retrieval fails or data processing errors occur. | |
| 1058 | 934 | */ |
| 1059 | 935 | public function get_elements_raw_data( $data = null, $with_html_content = false ) { |
| 1060 | 936 | if ( ! static::get_property( 'has_elements' ) ) { |
| 1061 | 937 | return []; |
| @@ -1064,23 +940,8 @@ | ||
| 1064 | 940 | if ( is_null( $data ) ) { |
| 1065 | 941 | $data = $this->get_elements_data(); |
| 1066 | 942 | } |
| 1067 | 943 | |
| 1068 | - /** | |
| 1069 | - * Filters document elements data after loading. | |
| 1070 | - * | |
| 1071 | - * Allows modification of elements data when loading (not saving). | |
| 1072 | - * Useful for migrations, transformations, or data enrichment. | |
| 1073 | - * | |
| 1074 | - * @since 3.35.0 | |
| 1075 | - * | |
| 1076 | - * @param array $data The elements data array. | |
| 1077 | - * @param \Elementor\Core\Base\Document $document The document instance. | |
| 1078 | - */ | |
| 1079 | - if ( ! $this->is_saving ) { | |
| 1080 | - $data = apply_filters( 'elementor/document/load/data', $data, $this ); | |
| 1081 | - } | |
| 1082 | - | |
| 1083 | 944 | // Change the current documents, so widgets can use `documents->get_current` and other post data |
| 1084 | 945 | Plugin::$instance->documents->switch_to_document( $this ); |
| 1085 | 946 | |
| 1086 | 947 | $editor_data = []; |
| @@ -1105,9 +966,9 @@ | ||
| 1105 | 966 | $element_data = $element->get_raw_data( $with_html_content ); |
| 1106 | 967 | } |
| 1107 | 968 | |
| 1108 | 969 | $editor_data[] = $element_data; |
| 1109 | - } | |
| 970 | + } // End foreach(). | |
| 1110 | 971 | |
| 1111 | 972 | Plugin::$instance->documents->restore_document(); |
| 1112 | 973 | |
| 1113 | 974 | return $editor_data; |
| @@ -1121,9 +982,9 @@ | ||
| 1121 | 982 | * |
| 1122 | 983 | * @return array |
| 1123 | 984 | */ |
| 1124 | 985 | public function get_elements_data( $status = self::STATUS_PUBLISH ) { |
| 1125 | - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 986 | + $elements = $this->get_json_meta( '_elementor_data' ); | |
| 1126 | 987 | |
| 1127 | 988 | if ( self::STATUS_DRAFT === $status ) { |
| 1128 | 989 | $autosave = $this->get_newer_autosave(); |
| 1129 | 990 | |
| @@ -1129,9 +990,9 @@ | ||
| 1129 | 990 | |
| 1130 | 991 | if ( is_object( $autosave ) ) { |
| 1131 | 992 | $autosave_elements = Plugin::$instance->documents |
| 1132 | 993 | ->get( $autosave->get_post()->ID ) |
| 1133 | - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 994 | + ->get_json_meta( '_elementor_data' ); | |
| 1134 | 995 | } |
| 1135 | 996 | } |
| 1136 | 997 | |
| 1137 | 998 | if ( Plugin::$instance->editor->is_edit_mode() ) { |
| @@ -1192,20 +1053,28 @@ | ||
| 1192 | 1053 | ]; |
| 1193 | 1054 | } |
| 1194 | 1055 | |
| 1195 | 1056 | // TODO: Better coding to start template for editor |
| 1196 | - $converted_blocks = [ | |
| 1057 | + return [ | |
| 1197 | 1058 | [ |
| 1198 | 1059 | 'id' => Utils::generate_random_string(), |
| 1199 | - 'elType' => $widget_type::get_type(), | |
| 1200 | - 'widgetType' => $widget_type->get_name(), | |
| 1201 | - 'settings' => $settings, | |
| 1060 | + 'elType' => 'section', | |
| 1061 | + 'elements' => [ | |
| 1062 | + [ | |
| 1063 | + 'id' => Utils::generate_random_string(), | |
| 1064 | + 'elType' => 'column', | |
| 1065 | + 'elements' => [ | |
| 1066 | + [ | |
| 1067 | + 'id' => Utils::generate_random_string(), | |
| 1068 | + 'elType' => $widget_type::get_type(), | |
| 1069 | + 'widgetType' => $widget_type->get_name(), | |
| 1070 | + 'settings' => $settings, | |
| 1071 | + ], | |
| 1072 | + ], | |
| 1073 | + ], | |
| 1074 | + ], | |
| 1202 | 1075 | ], |
| 1203 | 1076 | ]; |
| 1204 | - | |
| 1205 | - return Plugin::$instance->experiments->is_feature_active( 'container' ) | |
| 1206 | - ? $this->get_container_elements_data( $converted_blocks ) | |
| 1207 | - : $this->get_sections_elements_data( $converted_blocks ); | |
| 1208 | 1077 | } |
| 1209 | 1078 | |
| 1210 | 1079 | /** |
| 1211 | 1080 | * @since 2.1.3 |
| @@ -1215,11 +1084,20 @@ | ||
| 1215 | 1084 | if ( ! $elements_data ) { |
| 1216 | 1085 | $elements_data = $this->get_elements_data(); |
| 1217 | 1086 | } |
| 1218 | 1087 | |
| 1088 | + $is_dom_optimization_active = Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ); | |
| 1219 | 1089 | ?> |
| 1220 | 1090 | <div <?php Utils::print_html_attributes( $this->get_container_attributes() ); ?>> |
| 1091 | + <?php if ( ! $is_dom_optimization_active ) : ?> | |
| 1092 | + <div class="elementor-inner"> | |
| 1093 | + <div class="elementor-section-wrap"> | |
| 1094 | + <?php endif; ?> | |
| 1221 | 1095 | <?php $this->print_elements( $elements_data ); ?> |
| 1096 | + <?php if ( ! $is_dom_optimization_active ) : ?> | |
| 1097 | + </div> | |
| 1098 | + </div> | |
| 1099 | + <?php endif; ?> | |
| 1222 | 1100 | </div> |
| 1223 | 1101 | <?php |
| 1224 | 1102 | } |
| 1225 | 1103 | |
| @@ -1236,13 +1114,10 @@ | ||
| 1236 | 1114 | * @access public |
| 1237 | 1115 | */ |
| 1238 | 1116 | public function get_panel_page_settings() { |
| 1239 | 1117 | return [ |
| 1240 | - 'title' => sprintf( | |
| 1241 | - /* translators: %s: Document title. */ | |
| 1242 | - esc_html__( '%s Settings', 'elementor' ), | |
| 1243 | - static::get_title() | |
| 1244 | - ), | |
| 1118 | + /* translators: %s: Document title. */ | |
| 1119 | + 'title' => sprintf( esc_html__( '%s Settings', 'elementor' ), static::get_title() ), | |
| 1245 | 1120 | ]; |
| 1246 | 1121 | } |
| 1247 | 1122 | |
| 1248 | 1123 | /** |
| @@ -1299,9 +1174,9 @@ | ||
| 1299 | 1174 | * @param array|null $controls The available controls. |
| 1300 | 1175 | * |
| 1301 | 1176 | * @return array Element data. |
| 1302 | 1177 | */ |
| 1303 | - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array { | |
| 1178 | + public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array { | |
| 1304 | 1179 | foreach ( $config as &$element_config ) { |
| 1305 | 1180 | $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config ); |
| 1306 | 1181 | |
| 1307 | 1182 | if ( is_null( $element_instance ) ) { |
| @@ -1321,39 +1196,8 @@ | ||
| 1321 | 1196 | return $config; |
| 1322 | 1197 | } |
| 1323 | 1198 | |
| 1324 | 1199 | /** |
| 1325 | - * Update dynamic settings in the document for import. | |
| 1326 | - * | |
| 1327 | - * @param array $settings The settings of the document. | |
| 1328 | - * @param array $config Import config to update the settings. | |
| 1329 | - * | |
| 1330 | - * @return array | |
| 1331 | - */ | |
| 1332 | - public function on_import_update_settings( array $settings, array $config ): array { | |
| 1333 | - $controls = $this->get_controls(); | |
| 1334 | - $controls_manager = Plugin::$instance->controls_manager; | |
| 1335 | - | |
| 1336 | - foreach ( $settings as $key => $value ) { | |
| 1337 | - | |
| 1338 | - if ( ! isset( $controls[ $key ] ) ) { | |
| 1339 | - continue; | |
| 1340 | - } | |
| 1341 | - | |
| 1342 | - $control = $controls[ $key ]; | |
| 1343 | - $control_instance = $controls_manager->get_control( $control['type'] ); | |
| 1344 | - | |
| 1345 | - if ( ! $control_instance ) { | |
| 1346 | - continue; | |
| 1347 | - } | |
| 1348 | - | |
| 1349 | - $settings[ $key ] = $control_instance->on_import_update_settings( $value, $control, $config ); | |
| 1350 | - } | |
| 1351 | - | |
| 1352 | - return $settings; | |
| 1353 | - } | |
| 1354 | - | |
| 1355 | - /** | |
| 1356 | 1200 | * Save editor elements. |
| 1357 | 1201 | * |
| 1358 | 1202 | * Save data from the editor to the database. |
| 1359 | 1203 | * |
| @@ -1368,9 +1212,9 @@ | ||
| 1368 | 1212 | // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1369 | 1213 | $json_value = wp_slash( wp_json_encode( $editor_data ) ); |
| 1370 | 1214 | |
| 1371 | 1215 | // Don't use `update_post_meta` that can't handle `revision` post type |
| 1372 | - $is_meta_updated = update_metadata( 'post', $this->post->ID, self::ELEMENTOR_DATA_META_KEY, $json_value ); | |
| 1216 | + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value ); | |
| 1373 | 1217 | |
| 1374 | 1218 | /** |
| 1375 | 1219 | * Before saving data. |
| 1376 | 1220 | * |
| @@ -1438,8 +1282,9 @@ | ||
| 1438 | 1282 | * |
| 1439 | 1283 | * @since 2.5.12 |
| 1440 | 1284 | * |
| 1441 | 1285 | * @param \Elementor\Core\Base\Document $this The current document. |
| 1286 | + * | |
| 1442 | 1287 | */ |
| 1443 | 1288 | do_action( 'elementor/document/save_version', $this ); |
| 1444 | 1289 | } |
| 1445 | 1290 | } |
| @@ -1476,9 +1321,9 @@ | ||
| 1476 | 1321 | * @since 2.0.4 |
| 1477 | 1322 | * @access public |
| 1478 | 1323 | * |
| 1479 | 1324 | * @param string $key Meta data key. |
| 1480 | - * @param mixed $value Meta data value. | |
| 1325 | + * @param string $value Meta data value. | |
| 1481 | 1326 | * |
| 1482 | 1327 | * @return bool|int |
| 1483 | 1328 | */ |
| 1484 | 1329 | public function update_main_meta( $key, $value ) { |
| @@ -1553,21 +1398,13 @@ | ||
| 1553 | 1398 | $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) ); |
| 1554 | 1399 | $display_name = get_the_author_meta( 'display_name', $post->post_author ); |
| 1555 | 1400 | |
| 1556 | 1401 | if ( $autosave_post || 'revision' === $post->post_type ) { |
| 1557 | - $last_edited = sprintf( | |
| 1558 | - /* translators: 1: Saving date, 2: Author display name. */ | |
| 1559 | - esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), | |
| 1560 | - '<time>' . $date . '</time>', | |
| 1561 | - $display_name | |
| 1562 | - ); | |
| 1402 | + /* translators: 1: Saving date, 2: Author display name. */ | |
| 1403 | + $last_edited = sprintf( esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name ); | |
| 1563 | 1404 | } else { |
| 1564 | - $last_edited = sprintf( | |
| 1565 | - /* translators: 1: Editing date, 2: Author display name. */ | |
| 1566 | - esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), | |
| 1567 | - '<time>' . $date . '</time>', | |
| 1568 | - $display_name | |
| 1569 | - ); | |
| 1405 | + /* translators: 1: Editing date, 2: Author display name. */ | |
| 1406 | + $last_edited = sprintf( esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name ); | |
| 1570 | 1407 | } |
| 1571 | 1408 | |
| 1572 | 1409 | return $last_edited; |
| 1573 | 1410 | } |
| @@ -1606,9 +1443,9 @@ | ||
| 1606 | 1443 | } else { |
| 1607 | 1444 | $this->post = get_post( $data['post_id'] ); |
| 1608 | 1445 | |
| 1609 | 1446 | if ( ! $this->post ) { |
| 1610 | - throw new \Exception( sprintf( 'Post ID #%s does not exist.', esc_html( $data['post_id'] ) ), Exceptions::NOT_FOUND ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 1447 | + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND ); | |
| 1611 | 1448 | } |
| 1612 | 1449 | } |
| 1613 | 1450 | |
| 1614 | 1451 | // Each Control_Stack is based on a unique ID. |
| @@ -1626,9 +1463,9 @@ | ||
| 1626 | 1463 | |
| 1627 | 1464 | parent::__construct( $data ); |
| 1628 | 1465 | } |
| 1629 | 1466 | |
| 1630 | - /** | |
| 1467 | + /* | |
| 1631 | 1468 | * Get Export Data |
| 1632 | 1469 | * |
| 1633 | 1470 | * Filters a document's data on export |
| 1634 | 1471 | * |
| @@ -1640,13 +1477,11 @@ | ||
| 1640 | 1477 | public function get_export_data() { |
| 1641 | 1478 | $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) { |
| 1642 | 1479 | $element_data['id'] = Utils::generate_random_string(); |
| 1643 | 1480 | |
| 1644 | - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data ); | |
| 1645 | - | |
| 1646 | 1481 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1647 | 1482 | |
| 1648 | - // If the widget/element does not exist, like a plugin that creates a widget but deactivated. | |
| 1483 | + // If the widget/element isn't exist, like a plugin that creates a widget but deactivated | |
| 1649 | 1484 | if ( ! $element ) { |
| 1650 | 1485 | return null; |
| 1651 | 1486 | } |
| 1652 | 1487 | |
| @@ -1667,9 +1502,9 @@ | ||
| 1667 | 1502 | 'thumbnail' => get_the_post_thumbnail_url( $this->post ), |
| 1668 | 1503 | ]; |
| 1669 | 1504 | } |
| 1670 | 1505 | |
| 1671 | - /** | |
| 1506 | + /* | |
| 1672 | 1507 | * Get Import Data |
| 1673 | 1508 | * |
| 1674 | 1509 | * Filters a document's data on import |
| 1675 | 1510 | * |
| @@ -1813,92 +1648,18 @@ | ||
| 1813 | 1648 | } |
| 1814 | 1649 | |
| 1815 | 1650 | /** |
| 1816 | 1651 | * @since 2.1.3 |
| 1817 | - * @access public | |
| 1652 | + * @access protected | |
| 1818 | 1653 | */ |
| 1819 | - public function print_elements( $elements_data ) { | |
| 1820 | - $is_element_cache_active = 'disable' !== get_option( 'elementor_element_cache_ttl', '' ); | |
| 1821 | - if ( ! $is_element_cache_active ) { | |
| 1822 | - ob_start(); | |
| 1654 | + protected function print_elements( $elements_data ) { | |
| 1655 | + // Collect all data updaters that should be updated on runtime. | |
| 1656 | + $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions(); | |
| 1823 | 1657 | |
| 1824 | - $this->do_print_elements( $elements_data ); | |
| 1825 | - | |
| 1826 | - $content = ob_get_clean(); | |
| 1827 | - | |
| 1828 | - if ( has_blocks( $content ) ) { | |
| 1829 | - $content = do_blocks( $content ); | |
| 1830 | - } | |
| 1831 | - | |
| 1832 | - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1833 | - | |
| 1834 | - return; | |
| 1658 | + if ( $runtime_elements_iteration_actions ) { | |
| 1659 | + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); | |
| 1835 | 1660 | } |
| 1836 | 1661 | |
| 1837 | - $cached_data = $this->get_document_cache(); | |
| 1838 | - | |
| 1839 | - if ( false === $cached_data ) { | |
| 1840 | - add_filter( 'elementor/element/should_render_shortcode', '__return_true' ); | |
| 1841 | - | |
| 1842 | - $scripts_to_queue = []; | |
| 1843 | - $styles_to_queue = []; | |
| 1844 | - | |
| 1845 | - global $wp_scripts, $wp_styles; | |
| 1846 | - | |
| 1847 | - $should_store_scripts = $wp_scripts instanceof \WP_Scripts && $wp_styles instanceof \WP_Styles; | |
| 1848 | - if ( $should_store_scripts ) { | |
| 1849 | - $scripts_ignored = $wp_scripts->queue; | |
| 1850 | - $styles_ignored = $wp_styles->queue; | |
| 1851 | - } | |
| 1852 | - | |
| 1853 | - ob_start(); | |
| 1854 | - | |
| 1855 | - $this->do_print_elements( $elements_data ); | |
| 1856 | - | |
| 1857 | - if ( $should_store_scripts ) { | |
| 1858 | - $scripts_to_queue = array_values( array_diff( $wp_scripts->queue, $scripts_ignored ) ); | |
| 1859 | - $styles_to_queue = array_values( array_diff( $wp_styles->queue, $styles_ignored ) ); | |
| 1860 | - } | |
| 1861 | - | |
| 1862 | - $cached_data = [ | |
| 1863 | - 'content' => ob_get_clean(), | |
| 1864 | - 'scripts' => $scripts_to_queue, | |
| 1865 | - 'styles' => $styles_to_queue, | |
| 1866 | - ]; | |
| 1867 | - | |
| 1868 | - if ( $this->should_store_cache_elements() ) { | |
| 1869 | - $this->set_document_cache( $cached_data ); | |
| 1870 | - } | |
| 1871 | - | |
| 1872 | - remove_filter( 'elementor/element/should_render_shortcode', '__return_true' ); | |
| 1873 | - } else { | |
| 1874 | - if ( ! empty( $cached_data['scripts'] ) ) { | |
| 1875 | - foreach ( $cached_data['scripts'] as $script_handle ) { | |
| 1876 | - wp_enqueue_script( $script_handle ); | |
| 1877 | - } | |
| 1878 | - } | |
| 1879 | - | |
| 1880 | - if ( ! empty( $cached_data['styles'] ) ) { | |
| 1881 | - foreach ( $cached_data['styles'] as $style_handle ) { | |
| 1882 | - wp_enqueue_style( $style_handle ); | |
| 1883 | - } | |
| 1884 | - } | |
| 1885 | - } | |
| 1886 | - | |
| 1887 | - if ( ! empty( $cached_data['content'] ) ) { | |
| 1888 | - $content = do_shortcode( $cached_data['content'] ); | |
| 1889 | - | |
| 1890 | - if ( has_blocks( $content ) ) { | |
| 1891 | - $content = do_blocks( $content ); | |
| 1892 | - } | |
| 1893 | - | |
| 1894 | - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1895 | - } | |
| 1896 | - } | |
| 1897 | - | |
| 1898 | - protected function do_print_elements( $elements_data ) { | |
| 1899 | - $this->update_runtime_elements( $elements_data ); | |
| 1900 | - | |
| 1901 | 1662 | foreach ( $elements_data as $element_data ) { |
| 1902 | 1663 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1903 | 1664 | |
| 1904 | 1665 | if ( ! $element ) { |
| @@ -1908,75 +1669,8 @@ | ||
| 1908 | 1669 | $element->print_element(); |
| 1909 | 1670 | } |
| 1910 | 1671 | } |
| 1911 | 1672 | |
| 1912 | - public function update_runtime_elements( $elements_data = null ) { | |
| 1913 | - if ( null === $elements_data ) { | |
| 1914 | - $elements_data = $this->get_elements_data(); | |
| 1915 | - } | |
| 1916 | - | |
| 1917 | - // Collect all data updaters that should be updated on runtime. | |
| 1918 | - $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions(); | |
| 1919 | - | |
| 1920 | - if ( $runtime_elements_iteration_actions ) { | |
| 1921 | - $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); | |
| 1922 | - } | |
| 1923 | - } | |
| 1924 | - | |
| 1925 | - public function set_document_cache( $value ) { | |
| 1926 | - $expiration_hours = get_option( 'elementor_element_cache_ttl', '' ); | |
| 1927 | - | |
| 1928 | - if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) { | |
| 1929 | - $expiration_hours = '24'; | |
| 1930 | - } | |
| 1931 | - | |
| 1932 | - $expiration_hours = absint( $expiration_hours ); | |
| 1933 | - | |
| 1934 | - $expiration = '+' . $expiration_hours . ' hours'; | |
| 1935 | - | |
| 1936 | - $data = [ | |
| 1937 | - 'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ), | |
| 1938 | - 'value' => $value, | |
| 1939 | - ]; | |
| 1940 | - | |
| 1941 | - $this->update_json_meta( static::CACHE_META_KEY, $data ); | |
| 1942 | - } | |
| 1943 | - | |
| 1944 | - private function get_document_cache() { | |
| 1945 | - $cache = $this->get_json_meta( static::CACHE_META_KEY ); | |
| 1946 | - | |
| 1947 | - if ( empty( $cache['timeout'] ) ) { | |
| 1948 | - return false; | |
| 1949 | - } | |
| 1950 | - | |
| 1951 | - if ( current_time( 'timestamp' ) > $cache['timeout'] ) { | |
| 1952 | - return false; | |
| 1953 | - } | |
| 1954 | - | |
| 1955 | - if ( ! is_array( $cache['value'] ) ) { | |
| 1956 | - return false; | |
| 1957 | - } | |
| 1958 | - | |
| 1959 | - return $cache['value']; | |
| 1960 | - } | |
| 1961 | - | |
| 1962 | - protected function delete_cache() { | |
| 1963 | - $this->delete_meta( static::CACHE_META_KEY ); | |
| 1964 | - } | |
| 1965 | - | |
| 1966 | - private function should_store_cache_elements() { | |
| 1967 | - static $should_store_cache_elements = null; | |
| 1968 | - | |
| 1969 | - if ( null === $should_store_cache_elements ) { | |
| 1970 | - $should_store_cache_elements = ( | |
| 1971 | - ! is_admin() | |
| 1972 | - && ! Plugin::$instance->preview->is_preview_mode() | |
| 1973 | - ); | |
| 1974 | - } | |
| 1975 | - | |
| 1976 | - return $should_store_cache_elements; | |
| 1977 | - } | |
| 1978 | - | |
| 1979 | 1673 | protected function register_document_controls() { |
| 1980 | 1674 | $this->start_controls_section( |
| 1981 | 1675 | 'document_settings', |
| 1982 | 1676 | [ |
| @@ -2107,10 +1801,6 @@ | ||
| 2107 | 1801 | $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this ); |
| 2108 | 1802 | } |
| 2109 | 1803 | |
| 2110 | 1804 | return $this->elements_iteration_actions; |
| 2111 | - } | |
| 2112 | - | |
| 2113 | - public function get_elementor_version() { | |
| 2114 | - return $this->get_main_meta( '_elementor_version' ); | |
| 2115 | 1805 | } |
| 2116 | 1806 | } |