PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.2
Elementor Website Builder – more than just a page builder v3.6.2
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
← All changes | core/base/document.php +87 -518 4.2.0-beta23.6.2 View file →
@@ -2,12 +2,10 @@
2 2 namespace Elementor\Core\Base;
3 3
4 4 use Elementor\Core\Base\Elements_Iteration_Actions\Assets as Assets_Iteration_Action;
5 5 use Elementor\Core\Base\Elements_Iteration_Actions\Base as Elements_Iteration_Action;
6 -use Elementor\Core\Behaviors\Interfaces\Lock_Behavior;
7 6 use Elementor\Core\Files\CSS\Post as Post_CSS;
8 7 use Elementor\Core\Settings\Page\Model as Page_Model;
9 -use Elementor\Core\Utils\Collection;
10 8 use Elementor\Core\Utils\Exceptions;
11 9 use Elementor\Includes\Elements\Container;
12 10 use Elementor\Plugin;
13 11 use Elementor\Controls_Manager;
@@ -18,12 +16,11 @@
18 16 use Elementor\Utils;
19 17 use Elementor\Widget_Base;
20 18 use Elementor\Core\Settings\Page\Manager as PageManager;
21 19 use ElementorPro\Modules\Library\Widgets\Template;
22 -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
23 20
24 21 if ( ! defined( 'ABSPATH' ) ) {
25 - exit; // Exit if accessed directly.
22 + exit; // Exit if accessed directly
26 23 }
27 24
28 25 /**
29 26 * Elementor document.
@@ -40,16 +37,11 @@
40 37 * Document type meta key.
41 38 */
42 39 const TYPE_META_KEY = '_elementor_template_type';
43 40 const PAGE_META_KEY = '_elementor_page_settings';
44 - const ELEMENTOR_DATA_META_KEY = '_elementor_data';
45 41
46 42 const BUILT_WITH_ELEMENTOR_META_KEY = '_elementor_edit_mode';
47 43
48 - const CACHE_META_KEY = '_elementor_element_cache';
49 -
50 - const UNEDITABLE_WITH_ELEMENTOR_TYPES = [ 'kit' ];
51 -
52 44 /**
53 45 * Document publish status.
54 46 */
55 47 const STATUS_PUBLISH = 'publish';
@@ -73,11 +65,9 @@
73 65 * Document pending status.
74 66 */
75 67 const STATUS_PENDING = 'pending';
76 68
77 - /**
78 - * @var int
79 - */
69 +
80 70 private $main_id;
81 71
82 72 /**
83 73 * @var bool
@@ -103,44 +93,8 @@
103 93 */
104 94 protected $post;
105 95
106 96 /**
107 - * @param array $internal_elements
108 - *
109 - * @return array[]
110 - */
111 - private function get_container_elements_data( array $internal_elements ): array {
112 - return [
113 - [
114 - 'id' => Utils::generate_random_string(),
115 - 'elType' => 'container',
116 - 'elements' => $internal_elements,
117 - ],
118 - ];
119 - }
120 -
121 - /**
122 - * @param array $internal_elements
123 - *
124 - * @return array[]
125 - */
126 - private function get_sections_elements_data( array $internal_elements ): array {
127 - return [
128 - [
129 - 'id' => Utils::generate_random_string(),
130 - 'elType' => 'section',
131 - 'elements' => [
132 - [
133 - 'id' => Utils::generate_random_string(),
134 - 'elType' => 'column',
135 - 'elements' => $internal_elements,
136 - ],
137 - ],
138 - ],
139 - ];
140 - }
141 -
142 - /**
143 97 * @since 2.1.0
144 98 * @access protected
145 99 * @static
146 100 */
@@ -166,15 +120,8 @@
166 120 'edit_capability' => '',
167 121 'show_in_finder' => true,
168 122 'show_on_admin_bar' => true,
169 123 'support_kit' => false,
170 - 'show_navigator' => true,
171 - 'allow_adding_widgets' => true,
172 - 'support_page_layout' => true,
173 - 'show_copy_and_share' => false,
174 - 'library_close_title' => esc_html__( 'Close', 'elementor' ),
175 - 'publish_button_title' => esc_html__( 'Publish', 'elementor' ),
176 - 'allow_closing_remote_library' => true,
177 124 ];
178 125 }
179 126
180 127 /**
@@ -191,70 +138,20 @@
191 138
192 139 return [
193 140 'title' => static::get_title(), // JS Container title.
194 141 'widgets_settings' => [],
195 - 'elements_categories' => self::get_filtered_editor_panel_categories(),
142 + 'elements_categories' => static::get_editor_panel_categories(),
196 143 'default_route' => $default_route,
197 144 'has_elements' => static::get_property( 'has_elements' ),
198 145 'support_kit' => static::get_property( 'support_kit' ),
199 146 'messages' => [
200 - 'publish_notification' => sprintf(
201 - /* translators: %s: Document title. */
202 - esc_html__( 'Hurray! Your %s is live.', 'elementor' ),
203 - static::get_title()
204 - ),
147 + /* translators: %s: Document title. */
148 + 'publish_notification' => sprintf( esc_html__( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ),
205 149 ],
206 - 'show_navigator' => static::get_property( 'show_navigator' ),
207 - 'allow_adding_widgets' => static::get_property( 'allow_adding_widgets' ),
208 - 'show_copy_and_share' => static::get_property( 'show_copy_and_share' ),
209 - 'library_close_title' => static::get_property( 'library_close_title' ),
210 - 'publish_button_title' => static::get_property( 'publish_button_title' ),
211 - 'allow_closing_remote_library' => static::get_property( 'allow_closing_remote_library' ),
212 150 ];
213 151 }
214 152
215 - public static function get_filtered_editor_panel_categories(): array {
216 - $categories = static::get_editor_panel_categories();
217 - $has_pro = Utils::has_pro();
218 -
219 - foreach ( $categories as $index => $category ) {
220 - if ( isset( $category['promotion'] ) ) {
221 - $categories = self::get_panel_category_item( $category['promotion'], $index, $categories, $has_pro );
222 - }
223 - }
224 -
225 - return $categories;
226 - }
227 -
228 153 /**
229 - * @param $promotion
230 - * @param $index
231 - * @param array $categories
232 - *
233 - * @return array
234 - */
235 - private static function get_panel_category_item( $promotion, $index, array $categories, bool $has_pro ): array {
236 - $keep_promotion = $has_pro && apply_filters(
237 - 'elementor/document/panel_category_keep_promotion',
238 - false,
239 - $index,
240 - $promotion
241 - );
242 -
243 - if ( ! $has_pro || $keep_promotion ) {
244 - $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data(
245 - $promotion,
246 - 'elementor/panel/' . $index . '/custom_promotion',
247 - 'url'
248 - );
249 - } else {
250 - unset( $categories[ $index ]['promotion'] );
251 - }
252 -
253 - return $categories;
254 - }
255 -
256 - /**
257 154 * Get element title.
258 155 *
259 156 * Retrieve the element title.
260 157 *
@@ -272,13 +169,9 @@
272 169 return static::get_title();
273 170 }
274 171
275 172 public static function get_add_new_title() {
276 - return sprintf(
277 - /* translators: %s: Document title. */
278 - esc_html__( 'Add New %s', 'elementor' ),
279 - static::get_title()
280 - );
173 + return sprintf( esc_html__( 'Add New %s', 'elementor' ), static::get_title() );
281 174 }
282 175
283 176 /**
284 177 * Get property.
@@ -367,15 +260,8 @@
367 260 return $this->main_id;
368 261 }
369 262
370 263 /**
371 - * @return null|Lock_Behavior
372 - */
373 - public static function get_lock_behavior_v2() {
374 - return null;
375 - }
376 -
377 - /**
378 264 * @since 2.0.0
379 265 * @access public
380 266 *
381 267 * @param $data
@@ -433,10 +319,9 @@
433 319 $attributes['data-elementor-settings'] = wp_json_encode( $elementor_settings );
434 320 }
435 321 }
436 322
437 - // apply this filter to allow the attributes to be modified by different sources
438 - return apply_filters( 'elementor/document/wrapper_attributes', $attributes, $this );
323 + return $attributes;
439 324 }
440 325
441 326 /**
442 327 * @since 2.0.0
@@ -446,12 +331,12 @@
446 331 $main_post_id = $this->get_main_id();
447 332 $document = $this;
448 333
449 334 // Ajax request from editor.
450 - $initial_document_id = Utils::get_super_global_value( $_POST, 'initial_document_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
451 -
452 - if ( ! empty( $initial_document_id ) ) {
453 - $document = Plugin::$instance->documents->get( $initial_document_id ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
335 + // PHPCS - only reading the value from $_POST['initial_document_id'].
336 + if ( ! empty( $_POST['initial_document_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
337 + // PHPCS - only reading the value from $_POST['initial_document_id'].
338 + $document = Plugin::$instance->documents->get( $_POST['initial_document_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
454 339 }
455 340
456 341 $url = get_preview_post_link(
457 342 $document->get_main_id(),
@@ -498,62 +383,8 @@
498 383 return $url;
499 384 }
500 385
501 386 /**
502 - * Get All Post Type URL
503 - *
504 - * Get url of the page which display all the posts of the current active document's post type.
505 - *
506 - * @since 3.7.0
507 - *
508 - * @return string $url
509 - */
510 - public function get_all_post_type_url() {
511 - $post_type = get_post_type( $this->get_main_id() );
512 -
513 - $url = get_admin_url() . 'edit.php';
514 -
515 - if ( 'post' !== $post_type ) {
516 - $url .= '?post_type=' . $post_type;
517 - }
518 -
519 - /**
520 - * Document "display all post type" URL.
521 - *
522 - * @since 3.7.0
523 - *
524 - * @param string $url The URL.
525 - * @param Document $this The document instance.
526 - */
527 - $url = apply_filters( 'elementor/document/urls/all_post_type', $url, $this );
528 -
529 - return $url;
530 - }
531 -
532 - /**
533 - * Get Main WP dashboard URL.
534 - *
535 - * @since 3.7.0
536 - *
537 - * @return string $url
538 - */
539 - protected function get_main_dashboard_url() {
540 - $url = get_dashboard_url();
541 -
542 - /**
543 - * Document "Main Dashboard" URL.
544 - *
545 - * @since 3.7.0
546 - *
547 - * @param string $url The URL.
548 - * @param Document $this The document instance.
549 - */
550 - $url = apply_filters( 'elementor/document/urls/main_dashboard', $url, $this );
551 -
552 - return $url;
553 - }
554 -
555 - /**
556 387 * Get auto-saved post revision.
557 388 *
558 389 * Retrieve the auto-saved post revision that is newer than current post.
559 390 *
@@ -559,10 +390,12 @@
559 390 *
560 391 * @since 2.0.0
561 392 * @access public
562 393 *
394 + *
563 395 * @return bool|Document
564 396 */
397 +
565 398 public function get_newer_autosave() {
566 399 $autosave = $this->get_autosave();
567 400
568 401 // Detect if there exists an autosave newer than the post.
@@ -617,12 +450,8 @@
617 450
618 451 if ( $autosave_id ) {
619 452 $document = Plugin::$instance->documents->get( $autosave_id );
620 453 } elseif ( $create ) {
621 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
622 - require_once ABSPATH . 'wp-admin/includes/post.php';
623 - }
624 -
625 454 $autosave_id = wp_create_post_autosave( [
626 455 'post_ID' => $this->post->ID,
627 456 'post_type' => $this->post->post_type,
628 457 'post_title' => $this->post->post_title,
@@ -651,14 +480,14 @@
651 480 * Fired by `post_row_actions` and `page_row_actions` filters.
652 481 *
653 482 * @access public
654 483 *
655 - * @param array $actions An array of row action links.
484 + * @param array $actions An array of row action links.
656 485 *
657 486 * @return array An updated array of row action links.
658 487 */
659 488 public function filter_admin_row_actions( $actions ) {
660 - if ( $this->is_editable_with_elementor() ) {
489 + if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) {
661 490 $actions['edit_with_elementor'] = sprintf(
662 491 '<a href="%1$s">%2$s</a>',
663 492 $this->get_edit_url(),
664 493 __( 'Edit with Elementor', 'elementor' )
@@ -667,16 +496,8 @@
667 496
668 497 return $actions;
669 498 }
670 499
671 - public function is_editable_with_elementor() {
672 - if ( in_array( $this->get_type(), self::UNEDITABLE_WITH_ELEMENTOR_TYPES ) ) {
673 - return false;
674 - }
675 -
676 - return $this->is_editable_by_current_user() && $this->is_built_with_elementor();
677 - }
678 -
679 500 /**
680 501 * @since 2.0.0
681 502 * @access public
682 503 */
@@ -701,12 +522,10 @@
701 522 if ( $locked_user ) {
702 523 $locked_user = $locked_user->display_name;
703 524 }
704 525
705 - $post = $this->get_main_post();
526 + $post_type_object = get_post_type_object( $this->get_main_post()->post_type );
706 527
707 - $post_type_object = get_post_type_object( $post->post_type );
708 -
709 528 $settings = SettingsManager::get_settings_managers_config();
710 529
711 530 $config = [
712 531 'id' => $this->get_main_id(),
@@ -724,38 +543,30 @@
724 543 // Deprecated config since 2.9.0.
725 544 'locked' => $locked_user,
726 545 ],
727 546 'urls' => [
728 - 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(), // WP post type edit page
729 - 'all_post_type' => $this->get_all_post_type_url(),
547 + 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(),
730 548 'preview' => $this->get_preview_url(),
731 549 'wp_preview' => $this->get_wp_preview_url(),
732 550 'permalink' => $this->get_permalink(),
733 551 'have_a_look' => $this->get_have_a_look_url(),
734 - 'main_dashboard' => $this->get_main_dashboard_url(),
735 552 ],
736 553 ];
737 554
738 - $post_status_object = get_post_status_object( $post->post_status );
739 -
740 - if ( $post_status_object ) {
741 - $config['status'] = [
742 - 'value' => $post_status_object->name,
743 - 'label' => $post_status_object->label,
744 - ];
745 - }
746 -
747 555 do_action( 'elementor/document/before_get_config', $this );
748 556
749 557 if ( static::get_property( 'has_elements' ) ) {
750 - $elements_config = Collection::make( Plugin::$instance->elements_manager->get_element_types() )
751 - ->filter( fn( $element ) => ( ! empty( $element->get_config()['include_in_widgets_config'] ) ) )
752 - ->map( fn( $element ) => $element->get_config() )
753 - ->all();
558 + $container_config = [];
559 + $experiments_manager = Plugin::$instance->experiments;
754 560
561 + if ( $experiments_manager->is_feature_active( 'container' ) ) {
562 + $container_config = [
563 + 'container' => Plugin::$instance->elements_manager->get_element_types( 'container' )->get_config(),
564 + ];
565 + }
566 +
755 567 $config['elements'] = $this->get_elements_raw_data( null, true );
756 - // `get_elements_raw_data` has to be called before `get_widget_types_config`, because it affects it.
757 - $config['widgets'] = array_merge( $elements_config, Plugin::$instance->widgets_manager->get_widget_types_config() );
568 + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config();
758 569 }
759 570
760 571 $additional_config = [];
761 572
@@ -810,16 +621,8 @@
810 621 * @return bool
811 622 */
812 623 public function save( $data ) {
813 624 /**
814 - * Set locale to "C" to avoid issues with comma as decimal separator.
815 - *
816 - * @see https://github.com/elementor/elementor/issues/10992
817 - */
818 - $original_lc = setlocale( LC_NUMERIC, 0 );
819 - setlocale( LC_NUMERIC, 'C' );
820 -
821 - /**
822 625 * Document save data.
823 626 *
824 627 * Filter the document data before saving process starts.
825 628 *
@@ -853,11 +656,9 @@
853 656 */
854 657 do_action( 'elementor/document/before_save', $this, $data );
855 658
856 659 if ( ! current_user_can( 'unfiltered_html' ) ) {
857 - $data = map_deep( $data, function ( $value ) {
858 - return is_bool( $value ) || is_null( $value ) ? $value : wp_kses_post( $value );
859 - } );
660 + $data = wp_kses_post_deep( $data );
860 661 }
861 662
862 663 if ( ! empty( $data['settings'] ) ) {
863 664 if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
@@ -884,11 +685,8 @@
884 685 $post_css = Post_CSS::create( $this->post->ID );
885 686
886 687 $post_css->delete();
887 688
888 - // Remove Document Cache
889 - $this->delete_cache();
890 -
891 689 /**
892 690 * After document save.
893 691 *
894 692 * Fires when document save is complete.
@@ -903,10 +701,8 @@
903 701 $this->set_is_saving( false );
904 702
905 703 $this->remove_handle_revisions_changed_filter();
906 704
907 - setlocale( LC_NUMERIC, $original_lc );
908 -
909 705 return true;
910 706 }
911 707
912 708 public function refresh_post() {
@@ -942,9 +738,9 @@
942 738 *
943 739 * @return bool Whether the post was built with Elementor.
944 740 */
945 741 public function is_built_with_elementor() {
946 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
742 + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
947 743 }
948 744
949 745 /**
950 746 * Mark the post as "built with elementor" or not.
@@ -1053,16 +849,8 @@
1053 849
1054 850 return $meta;
1055 851 }
1056 852
1057 - public function update_json_meta( $key, $value ) {
1058 - return $this->update_meta(
1059 - $key,
1060 - // `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1061 - wp_slash( wp_json_encode( $value ) )
1062 - );
1063 - }
1064 -
1065 853 /**
1066 854 * @since 2.0.0
1067 855 * @access public
1068 856 *
@@ -1069,10 +857,8 @@
1069 857 * @param null $data
1070 858 * @param bool $with_html_content
1071 859 *
1072 860 * @return array
1073 - *
1074 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1075 861 */
1076 862 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1077 863 if ( ! static::get_property( 'has_elements' ) ) {
1078 864 return [];
@@ -1081,23 +867,8 @@
1081 867 if ( is_null( $data ) ) {
1082 868 $data = $this->get_elements_data();
1083 869 }
1084 870
1085 - /**
1086 - * Filters document elements data after loading.
1087 - *
1088 - * Allows modification of elements data when loading (not saving).
1089 - * Useful for migrations, transformations, or data enrichment.
1090 - *
1091 - * @since 3.35.0
1092 - *
1093 - * @param array $data The elements data array.
1094 - * @param \Elementor\Core\Base\Document $document The document instance.
1095 - */
1096 - if ( ! $this->is_saving ) {
1097 - $data = apply_filters( 'elementor/document/load/data', $data, $this );
1098 - }
1099 -
1100 871 // Change the current documents, so widgets can use `documents->get_current` and other post data
1101 872 Plugin::$instance->documents->switch_to_document( $this );
1102 873
1103 874 $editor_data = [];
@@ -1115,17 +886,11 @@
1115 886 if ( ! $element ) {
1116 887 continue;
1117 888 }
1118 889
1119 - if ( $this->is_saving ) {
1120 - $element_data = $element->get_data_for_save();
1121 - } else {
1122 - $element_data = $element->get_raw_data( $with_html_content );
1123 - }
890 + $editor_data[] = $element->get_raw_data( $with_html_content );
891 + } // End foreach().
1124 892
1125 - $editor_data[] = $element_data;
1126 - }
1127 -
1128 893 Plugin::$instance->documents->restore_document();
1129 894
1130 895 return $editor_data;
1131 896 }
@@ -1138,9 +903,9 @@
1138 903 *
1139 904 * @return array
1140 905 */
1141 906 public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1142 - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
907 + $elements = $this->get_json_meta( '_elementor_data' );
1143 908
1144 909 if ( self::STATUS_DRAFT === $status ) {
1145 910 $autosave = $this->get_newer_autosave();
1146 911
@@ -1146,9 +911,9 @@
1146 911
1147 912 if ( is_object( $autosave ) ) {
1148 913 $autosave_elements = Plugin::$instance->documents
1149 914 ->get( $autosave->get_post()->ID )
1150 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
915 + ->get_json_meta( '_elementor_data' );
1151 916 }
1152 917 }
1153 918
1154 919 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1209,20 +974,28 @@
1209 974 ];
1210 975 }
1211 976
1212 977 // TODO: Better coding to start template for editor
1213 - $converted_blocks = [
978 + return [
1214 979 [
1215 980 'id' => Utils::generate_random_string(),
1216 - 'elType' => $widget_type::get_type(),
1217 - 'widgetType' => $widget_type->get_name(),
1218 - 'settings' => $settings,
981 + 'elType' => 'section',
982 + 'elements' => [
983 + [
984 + 'id' => Utils::generate_random_string(),
985 + 'elType' => 'column',
986 + 'elements' => [
987 + [
988 + 'id' => Utils::generate_random_string(),
989 + 'elType' => $widget_type::get_type(),
990 + 'widgetType' => $widget_type->get_name(),
991 + 'settings' => $settings,
992 + ],
993 + ],
994 + ],
995 + ],
1219 996 ],
1220 997 ];
1221 -
1222 - return Plugin::$instance->experiments->is_feature_active( 'container' )
1223 - ? $this->get_container_elements_data( $converted_blocks )
1224 - : $this->get_sections_elements_data( $converted_blocks );
1225 998 }
1226 999
1227 1000 /**
1228 1001 * @since 2.1.3
@@ -1232,11 +1005,20 @@
1232 1005 if ( ! $elements_data ) {
1233 1006 $elements_data = $this->get_elements_data();
1234 1007 }
1235 1008
1009 + $is_dom_optimization_active = Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' );
1236 1010 ?>
1237 1011 <div <?php Utils::print_html_attributes( $this->get_container_attributes() ); ?>>
1012 + <?php if ( ! $is_dom_optimization_active ) : ?>
1013 + <div class="elementor-inner">
1014 + <div class="elementor-section-wrap">
1015 + <?php endif; ?>
1238 1016 <?php $this->print_elements( $elements_data ); ?>
1017 + <?php if ( ! $is_dom_optimization_active ) : ?>
1018 + </div>
1019 + </div>
1020 + <?php endif; ?>
1239 1021 </div>
1240 1022 <?php
1241 1023 }
1242 1024
@@ -1253,13 +1035,10 @@
1253 1035 * @access public
1254 1036 */
1255 1037 public function get_panel_page_settings() {
1256 1038 return [
1257 - 'title' => sprintf(
1258 - /* translators: %s: Document title. */
1259 - esc_html__( '%s Settings', 'elementor' ),
1260 - static::get_title()
1261 - ),
1039 + /* translators: %s: Document title. */
1040 + 'title' => sprintf( esc_html__( '%s Settings', 'elementor' ), static::get_title() ),
1262 1041 ];
1263 1042 }
1264 1043
1265 1044 /**
@@ -1299,41 +1078,25 @@
1299 1078
1300 1079 return $deleted && ! is_wp_error( $deleted );
1301 1080 }
1302 1081
1303 - public function force_delete() {
1304 - $deleted = wp_delete_post( $this->post->ID, true );
1305 -
1306 - return $deleted && ! is_wp_error( $deleted );
1307 - }
1308 -
1309 1082 /**
1310 - * On import update dynamic content (e.g. post and term IDs).
1311 1083 *
1312 - * @since 3.8.0
1084 + * @since 3.6.0
1313 1085 *
1314 - * @param array $config The config of the passed element.
1315 - * @param array $data The data that requires updating/replacement when imported.
1316 - * @param array|null $controls The available controls.
1086 + * @param array $config
1317 1087 *
1318 - * @return array Element data.
1088 + * @param array $map_old_new_post_ids
1319 1089 */
1320 - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
1090 + public static function on_import_replace_dynamic_content( $config, $map_old_new_post_ids ) {
1321 1091 foreach ( $config as &$element_config ) {
1322 1092 $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1323 1093
1324 - if ( is_null( $element_instance ) ) {
1325 - continue;
1326 - }
1094 + if ( $element_instance ) {
1095 + $element_config = $element_instance::on_import_replace_dynamic_content( $element_config, $map_old_new_post_ids );
1327 1096
1328 - if ( $element_instance->has_own_method( 'on_import_replace_dynamic_content' ) ) {
1329 - // TODO: Remove this check in the future.
1330 - $element_config = $element_instance::on_import_replace_dynamic_content( $element_config, $data['post_ids'] );
1331 - } else {
1332 - $element_config = $element_instance::on_import_update_dynamic_content( $element_config, $data, $element_instance->get_controls() );
1097 + $element_config['elements'] = static::on_import_replace_dynamic_content( $element_config['elements'], $map_old_new_post_ids );
1333 1098 }
1334 -
1335 - $element_config['elements'] = static::on_import_update_dynamic_content( $element_config['elements'], $data );
1336 1099 }
1337 1100
1338 1101 return $config;
1339 1102 }
@@ -1338,39 +1101,8 @@
1338 1101 return $config;
1339 1102 }
1340 1103
1341 1104 /**
1342 - * Update dynamic settings in the document for import.
1343 - *
1344 - * @param array $settings The settings of the document.
1345 - * @param array $config Import config to update the settings.
1346 - *
1347 - * @return array
1348 - */
1349 - public function on_import_update_settings( array $settings, array $config ): array {
1350 - $controls = $this->get_controls();
1351 - $controls_manager = Plugin::$instance->controls_manager;
1352 -
1353 - foreach ( $settings as $key => $value ) {
1354 -
1355 - if ( ! isset( $controls[ $key ] ) ) {
1356 - continue;
1357 - }
1358 -
1359 - $control = $controls[ $key ];
1360 - $control_instance = $controls_manager->get_control( $control['type'] );
1361 -
1362 - if ( ! $control_instance ) {
1363 - continue;
1364 - }
1365 -
1366 - $settings[ $key ] = $control_instance->on_import_update_settings( $value, $control, $config );
1367 - }
1368 -
1369 - return $settings;
1370 - }
1371 -
1372 - /**
1373 1105 * Save editor elements.
1374 1106 *
1375 1107 * Save data from the editor to the database.
1376 1108 *
@@ -1385,9 +1117,9 @@
1385 1117 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1386 1118 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1387 1119
1388 1120 // Don't use `update_post_meta` that can't handle `revision` post type
1389 - $is_meta_updated = update_metadata( 'post', $this->post->ID, self::ELEMENTOR_DATA_META_KEY, $json_value );
1121 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1390 1122
1391 1123 /**
1392 1124 * Before saving data.
1393 1125 *
@@ -1455,8 +1187,9 @@
1455 1187 *
1456 1188 * @since 2.5.12
1457 1189 *
1458 1190 * @param \Elementor\Core\Base\Document $this The current document.
1191 + *
1459 1192 */
1460 1193 do_action( 'elementor/document/save_version', $this );
1461 1194 }
1462 1195 }
@@ -1493,9 +1226,9 @@
1493 1226 * @since 2.0.4
1494 1227 * @access public
1495 1228 *
1496 1229 * @param string $key Meta data key.
1497 - * @param mixed $value Meta data value.
1230 + * @param string $value Meta data value.
1498 1231 *
1499 1232 * @return bool|int
1500 1233 */
1501 1234 public function update_main_meta( $key, $value ) {
@@ -1570,21 +1303,13 @@
1570 1303 $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) );
1571 1304 $display_name = get_the_author_meta( 'display_name', $post->post_author );
1572 1305
1573 1306 if ( $autosave_post || 'revision' === $post->post_type ) {
1574 - $last_edited = sprintf(
1575 - /* translators: 1: Saving date, 2: Author display name. */
1576 - esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ),
1577 - '<time>' . $date . '</time>',
1578 - $display_name
1579 - );
1307 + /* translators: 1: Saving date, 2: Author display name. */
1308 + $last_edited = sprintf( esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name );
1580 1309 } else {
1581 - $last_edited = sprintf(
1582 - /* translators: 1: Editing date, 2: Author display name. */
1583 - esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ),
1584 - '<time>' . $date . '</time>',
1585 - $display_name
1586 - );
1310 + /* translators: 1: Editing date, 2: Author display name. */
1311 + $last_edited = sprintf( esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name );
1587 1312 }
1588 1313
1589 1314 return $last_edited;
1590 1315 }
@@ -1623,9 +1348,9 @@
1623 1348 } else {
1624 1349 $this->post = get_post( $data['post_id'] );
1625 1350
1626 1351 if ( ! $this->post ) {
1627 - throw new \Exception( sprintf( 'Post ID #%s does not exist.', esc_html( $data['post_id'] ) ), Exceptions::NOT_FOUND ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
1352 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1628 1353 }
1629 1354 }
1630 1355
1631 1356 // Each Control_Stack is based on a unique ID.
@@ -1643,9 +1368,9 @@
1643 1368
1644 1369 parent::__construct( $data );
1645 1370 }
1646 1371
1647 - /**
1372 + /*
1648 1373 * Get Export Data
1649 1374 *
1650 1375 * Filters a document's data on export
1651 1376 *
@@ -1657,13 +1382,11 @@
1657 1382 public function get_export_data() {
1658 1383 $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1659 1384 $element_data['id'] = Utils::generate_random_string();
1660 1385
1661 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1662 -
1663 1386 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1664 1387
1665 - // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1388 + // If the widget/element isn't exist, like a plugin that creates a widget but deactivated
1666 1389 if ( ! $element ) {
1667 1390 return null;
1668 1391 }
1669 1392
@@ -1684,9 +1407,9 @@
1684 1407 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1685 1408 ];
1686 1409 }
1687 1410
1688 - /**
1411 + /*
1689 1412 * Get Import Data
1690 1413 *
1691 1414 * Filters a document's data on import
1692 1415 *
@@ -1751,12 +1474,10 @@
1751 1474 }
1752 1475 }
1753 1476 }
1754 1477
1755 - public function process_element_import_export( Controls_Stack $element, $method, $element_data = null ) {
1756 - if ( null === $element_data ) {
1757 - $element_data = $element->get_data();
1758 - }
1478 + private function process_element_import_export( Controls_Stack $element, $method ) {
1479 + $element_data = $element->get_data();
1759 1480
1760 1481 if ( method_exists( $element, $method ) ) {
1761 1482 // TODO: Use the internal element data without parameters.
1762 1483 $element_data = $element->{$method}( $element_data );
@@ -1769,17 +1490,10 @@
1769 1490 if ( ! $control_class ) {
1770 1491 return $element_data;
1771 1492 }
1772 1493
1773 - // Do not add default value to the final settings, if there is no value at the
1774 - // data before the methods `on_import` or `on_export` called.
1775 - $has_value = isset( $element_data['settings'][ $control['name'] ] );
1776 -
1777 - if ( $has_value && method_exists( $control_class, $method ) ) {
1778 - $element_data['settings'][ $control['name'] ] = $control_class->{$method}(
1779 - $element_data['settings'][ $control['name'] ],
1780 - $control
1781 - );
1494 + if ( method_exists( $control_class, $method ) ) {
1495 + $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ), $control );
1782 1496 }
1783 1497
1784 1498 // On Export, check if the control has an argument 'export' => false.
1785 1499 if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) {
@@ -1830,92 +1544,18 @@
1830 1544 }
1831 1545
1832 1546 /**
1833 1547 * @since 2.1.3
1834 - * @access public
1548 + * @access protected
1835 1549 */
1836 - public function print_elements( $elements_data ) {
1837 - $is_element_cache_active = 'disable' !== get_option( 'elementor_element_cache_ttl', '' );
1838 - if ( ! $is_element_cache_active ) {
1839 - ob_start();
1550 + protected function print_elements( $elements_data ) {
1551 + // Collect all data updaters that should be updated on runtime.
1552 + $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions();
1840 1553
1841 - $this->do_print_elements( $elements_data );
1842 -
1843 - $content = ob_get_clean();
1844 -
1845 - if ( has_blocks( $content ) ) {
1846 - $content = do_blocks( $content );
1847 - }
1848 -
1849 - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1850 -
1851 - return;
1554 + if ( $runtime_elements_iteration_actions ) {
1555 + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1852 1556 }
1853 1557
1854 - $cached_data = $this->get_document_cache();
1855 -
1856 - if ( false === $cached_data ) {
1857 - add_filter( 'elementor/element/should_render_shortcode', '__return_true' );
1858 -
1859 - $scripts_to_queue = [];
1860 - $styles_to_queue = [];
1861 -
1862 - global $wp_scripts, $wp_styles;
1863 -
1864 - $should_store_scripts = $wp_scripts instanceof \WP_Scripts && $wp_styles instanceof \WP_Styles;
1865 - if ( $should_store_scripts ) {
1866 - $scripts_ignored = $wp_scripts->queue;
1867 - $styles_ignored = $wp_styles->queue;
1868 - }
1869 -
1870 - ob_start();
1871 -
1872 - $this->do_print_elements( $elements_data );
1873 -
1874 - if ( $should_store_scripts ) {
1875 - $scripts_to_queue = array_values( array_diff( $wp_scripts->queue, $scripts_ignored ) );
1876 - $styles_to_queue = array_values( array_diff( $wp_styles->queue, $styles_ignored ) );
1877 - }
1878 -
1879 - $cached_data = [
1880 - 'content' => ob_get_clean(),
1881 - 'scripts' => $scripts_to_queue,
1882 - 'styles' => $styles_to_queue,
1883 - ];
1884 -
1885 - if ( $this->should_store_cache_elements() ) {
1886 - $this->set_document_cache( $cached_data );
1887 - }
1888 -
1889 - remove_filter( 'elementor/element/should_render_shortcode', '__return_true' );
1890 - } else {
1891 - if ( ! empty( $cached_data['scripts'] ) ) {
1892 - foreach ( $cached_data['scripts'] as $script_handle ) {
1893 - wp_enqueue_script( $script_handle );
1894 - }
1895 - }
1896 -
1897 - if ( ! empty( $cached_data['styles'] ) ) {
1898 - foreach ( $cached_data['styles'] as $style_handle ) {
1899 - wp_enqueue_style( $style_handle );
1900 - }
1901 - }
1902 - }
1903 -
1904 - if ( ! empty( $cached_data['content'] ) ) {
1905 - $content = do_shortcode( $cached_data['content'] );
1906 -
1907 - if ( has_blocks( $content ) ) {
1908 - $content = do_blocks( $content );
1909 - }
1910 -
1911 - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1912 - }
1913 - }
1914 -
1915 - protected function do_print_elements( $elements_data ) {
1916 - $this->update_runtime_elements( $elements_data );
1917 -
1918 1558 foreach ( $elements_data as $element_data ) {
1919 1559 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1920 1560
1921 1561 if ( ! $element ) {
@@ -1925,75 +1565,8 @@
1925 1565 $element->print_element();
1926 1566 }
1927 1567 }
1928 1568
1929 - public function update_runtime_elements( $elements_data = null ) {
1930 - if ( null === $elements_data ) {
1931 - $elements_data = $this->get_elements_data();
1932 - }
1933 -
1934 - // Collect all data updaters that should be updated on runtime.
1935 - $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions();
1936 -
1937 - if ( $runtime_elements_iteration_actions ) {
1938 - $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1939 - }
1940 - }
1941 -
1942 - public function set_document_cache( $value ) {
1943 - $expiration_hours = get_option( 'elementor_element_cache_ttl', '' );
1944 -
1945 - if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) {
1946 - $expiration_hours = '24';
1947 - }
1948 -
1949 - $expiration_hours = absint( $expiration_hours );
1950 -
1951 - $expiration = '+' . $expiration_hours . ' hours';
1952 -
1953 - $data = [
1954 - 'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ),
1955 - 'value' => $value,
1956 - ];
1957 -
1958 - $this->update_json_meta( static::CACHE_META_KEY, $data );
1959 - }
1960 -
1961 - private function get_document_cache() {
1962 - $cache = $this->get_json_meta( static::CACHE_META_KEY );
1963 -
1964 - if ( empty( $cache['timeout'] ) ) {
1965 - return false;
1966 - }
1967 -
1968 - if ( current_time( 'timestamp' ) > $cache['timeout'] ) {
1969 - return false;
1970 - }
1971 -
1972 - if ( ! is_array( $cache['value'] ) ) {
1973 - return false;
1974 - }
1975 -
1976 - return $cache['value'];
1977 - }
1978 -
1979 - protected function delete_cache() {
1980 - $this->delete_meta( static::CACHE_META_KEY );
1981 - }
1982 -
1983 - private function should_store_cache_elements() {
1984 - static $should_store_cache_elements = null;
1985 -
1986 - if ( null === $should_store_cache_elements ) {
1987 - $should_store_cache_elements = (
1988 - ! is_admin()
1989 - && ! Plugin::$instance->preview->is_preview_mode()
1990 - );
1991 - }
1992 -
1993 - return $should_store_cache_elements;
1994 - }
1995 -
1996 1569 protected function register_document_controls() {
1997 1570 $this->start_controls_section(
1998 1571 'document_settings',
1999 1572 [
@@ -2124,10 +1697,6 @@
2124 1697 $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2125 1698 }
2126 1699
2127 1700 return $this->elements_iteration_actions;
2128 - }
2129 -
2130 - public function get_elementor_version() {
2131 - return $this->get_main_meta( '_elementor_version' );
2132 1701 }
2133 1702 }