PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.2
Elementor Website Builder – more than just a page builder v3.0.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 +99 -999 4.2.03.0.2 View file →
@@ -1,29 +1,20 @@
1 1 <?php
2 2 namespace Elementor\Core\Base;
3 3
4 -use Elementor\Core\Base\Elements_Iteration_Actions\Assets as Assets_Iteration_Action;
5 -use Elementor\Core\Base\Elements_Iteration_Actions\Base as Elements_Iteration_Action;
6 -use Elementor\Core\Behaviors\Interfaces\Lock_Behavior;
7 4 use Elementor\Core\Files\CSS\Post as Post_CSS;
8 -use Elementor\Core\Settings\Page\Model as Page_Model;
9 -use Elementor\Core\Utils\Collection;
10 5 use Elementor\Core\Utils\Exceptions;
11 -use Elementor\Includes\Elements\Container;
12 6 use Elementor\Plugin;
7 +use Elementor\DB;
13 8 use Elementor\Controls_Manager;
14 9 use Elementor\Controls_Stack;
15 -use Elementor\TemplateLibrary\Source_Local;
16 10 use Elementor\User;
17 11 use Elementor\Core\Settings\Manager as SettingsManager;
18 12 use Elementor\Utils;
19 13 use Elementor\Widget_Base;
20 -use Elementor\Core\Settings\Page\Manager as PageManager;
21 -use ElementorPro\Modules\Library\Widgets\Template;
22 -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
23 14
24 15 if ( ! defined( 'ABSPATH' ) ) {
25 - exit; // Exit if accessed directly.
16 + exit; // Exit if accessed directly
26 17 }
27 18
28 19 /**
29 20 * Elementor document.
@@ -40,59 +31,14 @@
40 31 * Document type meta key.
41 32 */
42 33 const TYPE_META_KEY = '_elementor_template_type';
43 34 const PAGE_META_KEY = '_elementor_page_settings';
44 - const ELEMENTOR_DATA_META_KEY = '_elementor_data';
45 35
46 - const BUILT_WITH_ELEMENTOR_META_KEY = '_elementor_edit_mode';
47 -
48 - const CACHE_META_KEY = '_elementor_element_cache';
49 -
50 - const UNEDITABLE_WITH_ELEMENTOR_TYPES = [ 'kit' ];
51 -
52 - /**
53 - * Document publish status.
54 - */
55 - const STATUS_PUBLISH = 'publish';
56 -
57 - /**
58 - * Document draft status.
59 - */
60 - const STATUS_DRAFT = 'draft';
61 -
62 - /**
63 - * Document private status.
64 - */
65 - const STATUS_PRIVATE = 'private';
66 -
67 - /**
68 - * Document autosave status.
69 - */
70 - const STATUS_AUTOSAVE = 'autosave';
71 -
72 - /**
73 - * Document pending status.
74 - */
75 - const STATUS_PENDING = 'pending';
76 -
77 - /**
78 - * @var int
79 - */
80 36 private $main_id;
81 37
82 - /**
83 - * @var bool
84 - */
85 - private $is_saving = false;
86 -
87 38 private static $properties = [];
88 39
89 40 /**
90 - * @var Elements_Iteration_Action[]
91 - */
92 - private $elements_iteration_actions = [];
93 -
94 - /**
95 41 * Document post data.
96 42 *
97 43 * Holds the document post data.
98 44 *
@@ -103,44 +49,8 @@
103 49 */
104 50 protected $post;
105 51
106 52 /**
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 53 * @since 2.1.0
144 54 * @access protected
145 55 * @static
146 56 */
@@ -166,15 +76,8 @@
166 76 'edit_capability' => '',
167 77 'show_in_finder' => true,
168 78 'show_on_admin_bar' => true,
169 79 '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 80 ];
178 81 }
179 82
180 83 /**
@@ -182,79 +85,23 @@
182 85 * @access public
183 86 * @static
184 87 */
185 88 public static function get_editor_panel_config() {
186 - $default_route = 'panel/elements/categories';
187 -
188 - if ( ! Plugin::instance()->role_manager->user_can( 'design' ) ) {
189 - $default_route = 'panel/page-settings/settings';
190 - }
191 -
192 89 return [
193 90 'title' => static::get_title(), // JS Container title.
194 91 'widgets_settings' => [],
195 - 'elements_categories' => self::get_filtered_editor_panel_categories(),
196 - 'default_route' => $default_route,
92 + 'elements_categories' => static::get_editor_panel_categories(),
93 + 'default_route' => 'panel/elements/categories',
197 94 'has_elements' => static::get_property( 'has_elements' ),
198 95 'support_kit' => static::get_property( 'support_kit' ),
199 96 'messages' => [
200 - 'publish_notification' => sprintf(
201 - /* translators: %s: Document title. */
202 - esc_html__( 'Hurray! Your %s is live.', 'elementor' ),
203 - static::get_title()
204 - ),
97 + /* translators: %s: the document title. */
98 + 'publish_notification' => sprintf( __( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ),
205 99 ],
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 100 ];
213 101 }
214 102
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 103 /**
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 104 * Get element title.
258 105 *
259 106 * Retrieve the element title.
260 107 *
@@ -264,23 +111,11 @@
264 111 *
265 112 * @return string Element title.
266 113 */
267 114 public static function get_title() {
268 - return esc_html__( 'Document', 'elementor' );
115 + return __( 'Document', 'elementor' );
269 116 }
270 117
271 - public static function get_plural_title() {
272 - return static::get_title();
273 - }
274 -
275 - 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 - );
281 - }
282 -
283 118 /**
284 119 * Get property.
285 120 *
286 121 * Retrieve the document property.
@@ -311,31 +146,14 @@
311 146 public static function get_class_full_name() {
312 147 return get_called_class();
313 148 }
314 149
315 - public static function get_create_url() {
316 - $properties = static::get_properties();
317 -
318 - // BC Support - Each document should define it own CPT this code is for BC support.
319 - $cpt = Source_Local::CPT;
320 -
321 - if ( isset( $properties['cpt'][0] ) ) {
322 - $cpt = $properties['cpt'][0];
323 - }
324 -
325 - return Plugin::$instance->documents->get_create_new_post_url( $cpt, static::get_type() );
326 - }
327 -
328 - public function get_name() {
329 - return static::get_type();
330 - }
331 -
332 150 /**
333 151 * @since 2.0.0
334 152 * @access public
335 153 */
336 154 public function get_unique_name() {
337 - return static::get_type() . '-' . $this->post->ID;
155 + return $this->get_name() . '-' . $this->post->ID;
338 156 }
339 157
340 158 /**
341 159 * @since 2.3.0
@@ -347,8 +165,17 @@
347 165 return $post_type_object->labels->singular_name;
348 166 }
349 167
350 168 /**
169 + * @since 2.0.12
170 + * @deprecated 2.4.0 Use `Document::get_remote_library_config()` instead
171 + * @access public
172 + */
173 + public function get_remote_library_type() {
174 + _deprecated_function( __METHOD__, '2.4.0', __CLASS__ . '::get_remote_library_config()' );
175 + }
176 +
177 + /**
351 178 * @since 2.0.0
352 179 * @access public
353 180 */
354 181 public function get_main_id() {
@@ -367,15 +194,8 @@
367 194 return $this->main_id;
368 195 }
369 196
370 197 /**
371 - * @return null|Lock_Behavior
372 - */
373 - public static function get_lock_behavior_v2() {
374 - return null;
375 - }
376 -
377 - /**
378 198 * @since 2.0.0
379 199 * @access public
380 200 *
381 201 * @param $data
@@ -409,8 +229,19 @@
409 229 public function get_main_post() {
410 230 return get_post( $this->get_main_id() );
411 231 }
412 232
233 + /**
234 + * @since 2.0.6
235 + * @deprecated 2.4.0 Use `Document::get_container_attributes()` instead
236 + * @access public
237 + */
238 + public function get_container_classes() {
239 + _deprecated_function( __METHOD__, '2.4.0', __CLASS__ . '::get_container_attributes()' );
240 +
241 + return '';
242 + }
243 +
413 244 public function get_container_attributes() {
414 245 $id = $this->get_main_id();
415 246
416 247 $attributes = [
@@ -427,16 +258,12 @@
427 258
428 259 if ( Plugin::$instance->preview->is_preview() ) {
429 260 $attributes['data-elementor-title'] = static::get_title();
430 261 } else {
431 - $elementor_settings = $this->get_frontend_settings();
432 - if ( ! empty( $elementor_settings ) ) {
433 - $attributes['data-elementor-settings'] = wp_json_encode( $elementor_settings );
434 - }
262 + $attributes['data-elementor-settings'] = wp_json_encode( $this->get_frontend_settings() );
435 263 }
436 264
437 - // apply this filter to allow the attributes to be modified by different sources
438 - return apply_filters( 'elementor/document/wrapper_attributes', $attributes, $this );
265 + return $attributes;
439 266 }
440 267
441 268 /**
442 269 * @since 2.0.0
@@ -446,12 +273,10 @@
446 273 $main_post_id = $this->get_main_id();
447 274 $document = $this;
448 275
449 276 // 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
277 + if ( ! empty( $_POST['initial_document_id'] ) ) {
278 + $document = Plugin::$instance->documents->get( $_POST['initial_document_id'] );
454 279 }
455 280
456 281 $url = get_preview_post_link(
457 282 $document->get_main_id(),
@@ -498,62 +323,8 @@
498 323 return $url;
499 324 }
500 325
501 326 /**
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 327 * Get auto-saved post revision.
557 328 *
558 329 * Retrieve the auto-saved post revision that is newer than current post.
559 330 *
@@ -559,10 +330,12 @@
559 330 *
560 331 * @since 2.0.0
561 332 * @access public
562 333 *
334 + *
563 335 * @return bool|Document
564 336 */
337 +
565 338 public function get_newer_autosave() {
566 339 $autosave = $this->get_autosave();
567 340
568 341 // Detect if there exists an autosave newer than the post.
@@ -581,26 +354,8 @@
581 354 return wp_is_post_autosave( $this->post->ID );
582 355 }
583 356
584 357 /**
585 - * Check if the current document is a 'revision'
586 - *
587 - * @return bool
588 - */
589 - public function is_revision() {
590 - return 'revision' === $this->post->post_type;
591 - }
592 -
593 - /**
594 - * Checks if the current document status is 'trash'.
595 - *
596 - * @return bool
597 - */
598 - public function is_trash() {
599 - return 'trash' === $this->post->post_status;
600 - }
601 -
602 - /**
603 358 * @since 2.0.0
604 359 * @access public
605 360 *
606 361 * @param int $user_id
@@ -617,12 +372,8 @@
617 372
618 373 if ( $autosave_id ) {
619 374 $document = Plugin::$instance->documents->get( $autosave_id );
620 375 } elseif ( $create ) {
621 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
622 - require_once ABSPATH . 'wp-admin/includes/post.php';
623 - }
624 -
625 376 $autosave_id = wp_create_post_autosave( [
626 377 'post_ID' => $this->post->ID,
627 378 'post_type' => $this->post->post_type,
628 379 'post_title' => $this->post->post_title,
@@ -651,14 +402,14 @@
651 402 * Fired by `post_row_actions` and `page_row_actions` filters.
652 403 *
653 404 * @access public
654 405 *
655 - * @param array $actions An array of row action links.
406 + * @param array $actions An array of row action links.
656 407 *
657 408 * @return array An updated array of row action links.
658 409 */
659 410 public function filter_admin_row_actions( $actions ) {
660 - if ( $this->is_editable_with_elementor() ) {
411 + if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) {
661 412 $actions['edit_with_elementor'] = sprintf(
662 413 '<a href="%1$s">%2$s</a>',
663 414 $this->get_edit_url(),
664 415 __( 'Edit with Elementor', 'elementor' )
@@ -667,16 +418,8 @@
667 418
668 419 return $actions;
669 420 }
670 421
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 422 /**
680 423 * @since 2.0.0
681 424 * @access public
682 425 */
@@ -701,12 +444,10 @@
701 444 if ( $locked_user ) {
702 445 $locked_user = $locked_user->display_name;
703 446 }
704 447
705 - $post = $this->get_main_post();
448 + $post_type_object = get_post_type_object( $this->get_main_post()->post_type );
706 449
707 - $post_type_object = get_post_type_object( $post->post_type );
708 -
709 450 $settings = SettingsManager::get_settings_managers_config();
710 451
711 452 $config = [
712 453 'id' => $this->get_main_id(),
@@ -724,56 +465,23 @@
724 465 // Deprecated config since 2.9.0.
725 466 'locked' => $locked_user,
726 467 ],
727 468 '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(),
469 + 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(),
730 470 'preview' => $this->get_preview_url(),
731 471 'wp_preview' => $this->get_wp_preview_url(),
732 472 'permalink' => $this->get_permalink(),
733 473 'have_a_look' => $this->get_have_a_look_url(),
734 - 'main_dashboard' => $this->get_main_dashboard_url(),
735 474 ],
736 475 ];
737 476
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 - do_action( 'elementor/document/before_get_config', $this );
748 -
749 477 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();
754 -
755 478 $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() );
479 + $config['widgets'] = Plugin::$instance->widgets_manager->get_widget_types_config();
758 480 }
759 481
760 - $additional_config = [];
482 + $additional_config = apply_filters( 'elementor/document/config', [], $this->get_main_id() );
761 483
762 - /**
763 - * Additional document configuration.
764 - *
765 - * Filters the document configuration by adding additional configuration.
766 - * External developers can use this hook to add custom configuration in
767 - * addition to Elementor's initial configuration.
768 - *
769 - * Use the $post_id to add custom configuration for different pages.
770 - *
771 - * @param array $additional_config The additional document configuration.
772 - * @param int $post_id The post ID of the document.
773 - */
774 - $additional_config = apply_filters( 'elementor/document/config', $additional_config, $this->get_main_id() );
775 -
776 484 if ( ! empty( $additional_config ) ) {
777 485 $config = array_replace_recursive( $config, $additional_config );
778 486 }
779 487
@@ -780,21 +488,18 @@
780 488 return $config;
781 489 }
782 490
783 491 /**
784 - * @since 3.1.0
492 + * @since 2.0.0
785 493 * @access protected
786 494 */
787 - protected function register_controls() {
495 + protected function _register_controls() {
788 496 $this->register_document_controls();
789 -
790 497 /**
791 498 * Register document controls.
792 499 *
793 500 * Fires after Elementor registers the document controls.
794 501 *
795 - * External developers can use this hook to add new controls to the document.
796 - *
797 502 * @since 2.0.0
798 503 *
799 504 * @param Document $this The document instance.
800 505 */
@@ -809,39 +514,12 @@
809 514 *
810 515 * @return bool
811 516 */
812 517 public function save( $data ) {
813 - /**
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 - * Document save data.
823 - *
824 - * Filter the document data before saving process starts.
825 - *
826 - * External developers can use this hook to change the data before
827 - * saving it to the database.
828 - *
829 - * @since 3.3.0
830 - *
831 - * @param array $data The document data.
832 - * @param \Elementor\Core\Base\Document $this The document instance.
833 - */
834 - $data = apply_filters( 'elementor/document/save/data', $data, $this );
835 -
836 - $this->add_handle_revisions_changed_filter();
837 -
838 518 if ( ! $this->is_editable_by_current_user() ) {
839 519 return false;
840 520 }
841 521
842 - $this->set_is_saving( true );
843 -
844 522 /**
845 523 * Before document save.
846 524 *
847 525 * Fires when document save starts on Elementor.
@@ -853,15 +531,13 @@
853 531 */
854 532 do_action( 'elementor/document/before_save', $this, $data );
855 533
856 534 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 - } );
535 + $data = wp_kses_post_deep( $data );
860 536 }
861 537
862 538 if ( ! empty( $data['settings'] ) ) {
863 - if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
539 + if ( isset( $data['settings']['post_status'] ) && DB::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
864 540 if ( ! defined( 'DOING_AUTOSAVE' ) ) {
865 541 define( 'DOING_AUTOSAVE', true );
866 542 }
867 543 }
@@ -867,9 +543,10 @@
867 543 }
868 544
869 545 $this->save_settings( $data['settings'] );
870 546
871 - $this->refresh_post();
547 + // Refresh post after save settings.
548 + $this->post = get_post( $this->post->ID );
872 549 }
873 550
874 551 // Don't check is_empty, because an empty array should be saved.
875 552 if ( isset( $data['elements'] ) && is_array( $data['elements'] ) ) {
@@ -884,11 +561,8 @@
884 561 $post_css = Post_CSS::create( $this->post->ID );
885 562
886 563 $post_css->delete();
887 564
888 - // Remove Document Cache
889 - $this->delete_cache();
890 -
891 565 /**
892 566 * After document save.
893 567 *
894 568 * Fires when document save is complete.
@@ -899,41 +573,12 @@
899 573 * @param $data.
900 574 */
901 575 do_action( 'elementor/document/after_save', $this, $data );
902 576
903 - $this->set_is_saving( false );
904 -
905 - $this->remove_handle_revisions_changed_filter();
906 -
907 - setlocale( LC_NUMERIC, $original_lc );
908 -
909 577 return true;
910 578 }
911 579
912 - public function refresh_post() {
913 - $this->post = get_post( $this->post->ID );
914 - }
915 -
916 580 /**
917 - * @param array $new_settings
918 - *
919 - * @return static
920 - */
921 - public function update_settings( array $new_settings ) {
922 - $document_settings = $this->get_meta( PageManager::META_KEY );
923 -
924 - if ( ! $document_settings ) {
925 - $document_settings = [];
926 - }
927 -
928 - $this->save_settings(
929 - array_replace_recursive( $document_settings, $new_settings )
930 - );
931 -
932 - return $this;
933 - }
934 -
935 - /**
936 581 * Is built with Elementor.
937 582 *
938 583 * Check whether the post was built with Elementor.
939 584 *
@@ -942,30 +587,12 @@
942 587 *
943 588 * @return bool Whether the post was built with Elementor.
944 589 */
945 590 public function is_built_with_elementor() {
946 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
591 + return ! ! get_post_meta( $this->post->ID, '_elementor_edit_mode', true );
947 592 }
948 593
949 594 /**
950 - * Mark the post as "built with elementor" or not.
951 - *
952 - * @param bool $is_built_with_elementor
953 - *
954 - * @return $this
955 - */
956 - public function set_is_built_with_elementor( $is_built_with_elementor ) {
957 - if ( $is_built_with_elementor ) {
958 - // Use the string `builder` and not a boolean for rollback compatibility
959 - $this->update_meta( self::BUILT_WITH_ELEMENTOR_META_KEY, 'builder' );
960 - } else {
961 - $this->delete_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
962 - }
963 -
964 - return $this;
965 - }
966 -
967 - /**
968 595 * @since 2.0.0
969 596 * @access public
970 597 * @static
971 598 *
@@ -1053,16 +680,8 @@
1053 680
1054 681 return $meta;
1055 682 }
1056 683
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 684 /**
1066 685 * @since 2.0.0
1067 686 * @access public
1068 687 *
@@ -1069,10 +688,8 @@
1069 688 * @param null $data
1070 689 * @param bool $with_html_content
1071 690 *
1072 691 * @return array
1073 - *
1074 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1075 692 */
1076 693 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1077 694 if ( ! static::get_property( 'has_elements' ) ) {
1078 695 return [];
@@ -1081,23 +698,8 @@
1081 698 if ( is_null( $data ) ) {
1082 699 $data = $this->get_elements_data();
1083 700 }
1084 701
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 702 // Change the current documents, so widgets can use `documents->get_current` and other post data
1101 703 Plugin::$instance->documents->switch_to_document( $this );
1102 704
1103 705 $editor_data = [];
@@ -1102,15 +704,8 @@
1102 704
1103 705 $editor_data = [];
1104 706
1105 707 foreach ( $data as $element_data ) {
1106 - if ( ! is_array( $element_data ) ) {
1107 - throw new \Exception( 'Invalid data: ' . wp_json_encode( [
1108 - 'data' => $data,
1109 - 'element' => $element_data,
1110 - ] ) );
1111 - }
1112 -
1113 708 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1114 709
1115 710 if ( ! $element ) {
1116 711 continue;
@@ -1115,17 +710,11 @@
1115 710 if ( ! $element ) {
1116 711 continue;
1117 712 }
1118 713
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 - }
714 + $editor_data[] = $element->get_raw_data( $with_html_content );
715 + } // End foreach().
1124 716
1125 - $editor_data[] = $element_data;
1126 - }
1127 -
1128 717 Plugin::$instance->documents->restore_document();
1129 718
1130 719 return $editor_data;
1131 720 }
@@ -1137,18 +726,18 @@
1137 726 * @param string $status
1138 727 *
1139 728 * @return array
1140 729 */
1141 - public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1142 - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
730 + public function get_elements_data( $status = DB::STATUS_PUBLISH ) {
731 + $elements = $this->get_json_meta( '_elementor_data' );
1143 732
1144 - if ( self::STATUS_DRAFT === $status ) {
733 + if ( DB::STATUS_DRAFT === $status ) {
1145 734 $autosave = $this->get_newer_autosave();
1146 735
1147 736 if ( is_object( $autosave ) ) {
1148 737 $autosave_elements = Plugin::$instance->documents
1149 738 ->get( $autosave->get_post()->ID )
1150 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
739 + ->get_json_meta( '_elementor_data' );
1151 740 }
1152 741 }
1153 742
1154 743 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1168,17 +757,8 @@
1168 757 return $elements;
1169 758 }
1170 759
1171 760 /**
1172 - * Get document setting from DB.
1173 - *
1174 - * @return array
1175 - */
1176 - public function get_db_document_settings() {
1177 - return $this->get_meta( static::PAGE_META_KEY );
1178 - }
1179 -
1180 - /**
1181 761 * @since 2.3.0
1182 762 * @access public
1183 763 */
1184 764 public function convert_to_elementor() {
@@ -1209,20 +789,28 @@
1209 789 ];
1210 790 }
1211 791
1212 792 // TODO: Better coding to start template for editor
1213 - $converted_blocks = [
793 + return [
1214 794 [
1215 795 'id' => Utils::generate_random_string(),
1216 - 'elType' => $widget_type::get_type(),
1217 - 'widgetType' => $widget_type->get_name(),
1218 - 'settings' => $settings,
796 + 'elType' => 'section',
797 + 'elements' => [
798 + [
799 + 'id' => Utils::generate_random_string(),
800 + 'elType' => 'column',
801 + 'elements' => [
802 + [
803 + 'id' => Utils::generate_random_string(),
804 + 'elType' => $widget_type::get_type(),
805 + 'widgetType' => $widget_type->get_name(),
806 + 'settings' => $settings,
807 + ],
808 + ],
809 + ],
810 + ],
1219 811 ],
1220 812 ];
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 813 }
1226 814
1227 815 /**
1228 816 * @since 2.1.3
@@ -1232,11 +820,21 @@
1232 820 if ( ! $elements_data ) {
1233 821 $elements_data = $this->get_elements_data();
1234 822 }
1235 823
824 + $is_legacy_mode_active = Plugin::instance()->get_legacy_mode( 'elementWrappers' );
825 +
1236 826 ?>
1237 - <div <?php Utils::print_html_attributes( $this->get_container_attributes() ); ?>>
1238 - <?php $this->print_elements( $elements_data ); ?>
827 + <div <?php echo Utils::render_html_attributes( $this->get_container_attributes() ); ?>>
828 + <?php if ( $is_legacy_mode_active ) { ?>
829 + <div class="elementor-inner">
830 + <?php } ?>
831 + <div class="elementor-section-wrap">
832 + <?php $this->print_elements( $elements_data ); ?>
833 + </div>
834 + <?php if ( $is_legacy_mode_active ) { ?>
835 + </div>
836 + <?php } ?>
1239 837 </div>
1240 838 <?php
1241 839 }
1242 840
@@ -1253,13 +851,10 @@
1253 851 * @access public
1254 852 */
1255 853 public function get_panel_page_settings() {
1256 854 return [
1257 - 'title' => sprintf(
1258 - /* translators: %s: Document title. */
1259 - esc_html__( '%s Settings', 'elementor' ),
1260 - static::get_title()
1261 - ),
855 + /* translators: %s: Document title */
856 + 'title' => sprintf( __( '%s Settings', 'elementor' ), static::get_title() ),
1262 857 ];
1263 858 }
1264 859
1265 860 /**
@@ -1299,78 +894,9 @@
1299 894
1300 895 return $deleted && ! is_wp_error( $deleted );
1301 896 }
1302 897
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 898 /**
1310 - * On import update dynamic content (e.g. post and term IDs).
1311 - *
1312 - * @since 3.8.0
1313 - *
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.
1317 - *
1318 - * @return array Element data.
1319 - */
1320 - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
1321 - foreach ( $config as &$element_config ) {
1322 - $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1323 -
1324 - if ( is_null( $element_instance ) ) {
1325 - continue;
1326 - }
1327 -
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() );
1333 - }
1334 -
1335 - $element_config['elements'] = static::on_import_update_dynamic_content( $element_config['elements'], $data );
1336 - }
1337 -
1338 - return $config;
1339 - }
1340 -
1341 - /**
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 899 * Save editor elements.
1374 900 *
1375 901 * Save data from the editor to the database.
1376 902 *
@@ -1385,9 +911,9 @@
1385 911 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1386 912 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1387 913
1388 914 // 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 );
915 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1390 916
1391 917 /**
1392 918 * Before saving data.
1393 919 *
@@ -1401,14 +927,8 @@
1401 927 do_action( 'elementor/db/before_save', $this->post->post_status, $is_meta_updated );
1402 928
1403 929 Plugin::$instance->db->save_plain_text( $this->post->ID );
1404 930
1405 - $elements_iteration_actions = $this->get_elements_iteration_actions();
1406 -
1407 - if ( $elements_iteration_actions ) {
1408 - $this->iterate_elements( $elements, $elements_iteration_actions, 'save' );
1409 - }
1410 -
1411 931 /**
1412 932 * After saving data.
1413 933 *
1414 934 * Fires after Elementor saves data to the database.
@@ -1455,8 +975,9 @@
1455 975 *
1456 976 * @since 2.5.12
1457 977 *
1458 978 * @param \Elementor\Core\Base\Document $this The current document.
979 + *
1459 980 */
1460 981 do_action( 'elementor/document/save_version', $this );
1461 982 }
1462 983 }
@@ -1493,9 +1014,9 @@
1493 1014 * @since 2.0.4
1494 1015 * @access public
1495 1016 *
1496 1017 * @param string $key Meta data key.
1497 - * @param mixed $value Meta data value.
1018 + * @param string $value Meta data value.
1498 1019 *
1499 1020 * @return bool|int
1500 1021 */
1501 1022 public function update_main_meta( $key, $value ) {
@@ -1570,46 +1091,19 @@
1570 1091 $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) );
1571 1092 $display_name = get_the_author_meta( 'display_name', $post->post_author );
1572 1093
1573 1094 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 - );
1095 + /* translators: 1: Saving date, 2: Author display name */
1096 + $last_edited = sprintf( __( 'Draft saved on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name );
1580 1097 } 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 - );
1098 + /* translators: 1: Editing date, 2: Author display name */
1099 + $last_edited = sprintf( __( 'Last edited on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name );
1587 1100 }
1588 1101
1589 1102 return $last_edited;
1590 1103 }
1591 1104
1592 -
1593 1105 /**
1594 - * @return bool
1595 - */
1596 - public function is_saving() {
1597 - return $this->is_saving;
1598 - }
1599 -
1600 - /**
1601 - * @param $is_saving
1602 - *
1603 - * @return $this
1604 - */
1605 - public function set_is_saving( $is_saving ) {
1606 - $this->is_saving = $is_saving;
1607 -
1608 - return $this;
1609 - }
1610 -
1611 - /**
1612 1106 * @since 2.0.0
1613 1107 * @access public
1614 1108 *
1615 1109 * @param array $data
@@ -1623,9 +1117,9 @@
1623 1117 } else {
1624 1118 $this->post = get_post( $data['post_id'] );
1625 1119
1626 1120 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
1121 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1628 1122 }
1629 1123 }
1630 1124
1631 1125 // Each Control_Stack is based on a unique ID.
@@ -1643,170 +1137,8 @@
1643 1137
1644 1138 parent::__construct( $data );
1645 1139 }
1646 1140
1647 - /**
1648 - * Get Export Data
1649 - *
1650 - * Filters a document's data on export
1651 - *
1652 - * @since 3.2.0
1653 - * @access public
1654 - *
1655 - * @return array The data to export
1656 - */
1657 - public function get_export_data() {
1658 - $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1659 - $element_data['id'] = Utils::generate_random_string();
1660 -
1661 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1662 -
1663 - $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1664 -
1665 - // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1666 - if ( ! $element ) {
1667 - return null;
1668 - }
1669 -
1670 - return $this->process_element_import_export( $element, 'on_export' );
1671 - } );
1672 -
1673 - return [
1674 - 'content' => $content,
1675 - 'settings' => $this->get_data( 'settings' ),
1676 - 'metadata' => $this->get_export_metadata(),
1677 - ];
1678 - }
1679 -
1680 - public function get_export_summary() {
1681 - return [
1682 - 'title' => $this->post->post_title,
1683 - 'doc_type' => $this->get_name(),
1684 - 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1685 - ];
1686 - }
1687 -
1688 - /**
1689 - * Get Import Data
1690 - *
1691 - * Filters a document's data on import
1692 - *
1693 - * @since 3.2.0
1694 - * @access public
1695 - *
1696 - * @return array The data to import
1697 - */
1698 - public function get_import_data( array $data ) {
1699 - $data['content'] = Plugin::$instance->db->iterate_data( $data['content'], function( $element_data ) {
1700 - $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1701 -
1702 - // If the widget/element isn't exist, like a plugin that creates a widget but deactivated
1703 - if ( ! $element ) {
1704 - return null;
1705 - }
1706 -
1707 - return $this->process_element_import_export( $element, 'on_import' );
1708 - } );
1709 -
1710 - if ( ! empty( $data['settings'] ) ) {
1711 - $template_model = new Page_Model( [
1712 - 'id' => 0,
1713 - 'settings' => $data['settings'],
1714 - ] );
1715 -
1716 - $page_data = $this->process_element_import_export( $template_model, 'on_import' );
1717 -
1718 - $data['settings'] = $page_data['settings'];
1719 - }
1720 -
1721 - return $data;
1722 - }
1723 -
1724 - /**
1725 - * Import
1726 - *
1727 - * Allows to import an external data to a document
1728 - *
1729 - * @since 3.2.0
1730 - * @access public
1731 - *
1732 - * @param array $data
1733 - */
1734 - public function import( array $data ) {
1735 - $data = $this->get_import_data( $data );
1736 -
1737 - $this->save( [
1738 - 'elements' => $data['content'],
1739 - 'settings' => $data['settings'],
1740 - ] );
1741 -
1742 - if ( $data['import_settings']['thumbnail'] ) {
1743 - $attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( [ 'url' => $data['import_settings']['thumbnail'] ] );
1744 -
1745 - set_post_thumbnail( $this->get_main_post(), $attachment['id'] );
1746 - }
1747 -
1748 - if ( ! empty( $data['metadata'] ) ) {
1749 - foreach ( $data['metadata'] as $key => $value ) {
1750 - $this->update_meta( $key, $value );
1751 - }
1752 - }
1753 - }
1754 -
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 - }
1759 -
1760 - if ( method_exists( $element, $method ) ) {
1761 - // TODO: Use the internal element data without parameters.
1762 - $element_data = $element->{$method}( $element_data );
1763 - }
1764 -
1765 - foreach ( $element->get_controls() as $control ) {
1766 - $control_class = Plugin::$instance->controls_manager->get_control( $control['type'] );
1767 -
1768 - // If the control isn't exist, like a plugin that creates the control but deactivated.
1769 - if ( ! $control_class ) {
1770 - return $element_data;
1771 - }
1772 -
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 - );
1782 - }
1783 -
1784 - // On Export, check if the control has an argument 'export' => false.
1785 - if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) {
1786 - unset( $element_data['settings'][ $control['name'] ] );
1787 - }
1788 - }
1789 -
1790 - return $element_data;
1791 - }
1792 -
1793 - protected function get_export_metadata() {
1794 - $metadata = get_post_meta( $this->get_main_id() );
1795 -
1796 - foreach ( $metadata as $meta_key => $meta_value ) {
1797 - if ( is_protected_meta( $meta_key, 'post' ) ) {
1798 - unset( $metadata[ $meta_key ] );
1799 -
1800 - continue;
1801 - }
1802 -
1803 - $metadata[ $meta_key ] = $meta_value[0];
1804 - }
1805 -
1806 - return $metadata;
1807 - }
1808 -
1809 1141 protected function get_remote_library_config() {
1810 1142 $config = [
1811 1143 'type' => 'block',
1812 1144 'default_route' => 'templates/blocks',
@@ -1830,92 +1162,11 @@
1830 1162 }
1831 1163
1832 1164 /**
1833 1165 * @since 2.1.3
1834 - * @access public
1166 + * @access protected
1835 1167 */
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();
1840 -
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;
1852 - }
1853 -
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 -
1168 + protected function print_elements( $elements_data ) {
1918 1169 foreach ( $elements_data as $element_data ) {
1919 1170 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1920 1171
1921 1172 if ( ! $element ) {
@@ -1925,80 +1176,13 @@
1925 1176 $element->print_element();
1926 1177 }
1927 1178 }
1928 1179
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 1180 protected function register_document_controls() {
1997 1181 $this->start_controls_section(
1998 1182 'document_settings',
1999 1183 [
2000 - 'label' => esc_html__( 'General Settings', 'elementor' ),
1184 + 'label' => __( 'General Settings', 'elementor' ),
2001 1185 'tab' => Controls_Manager::TAB_SETTINGS,
2002 1186 ]
2003 1187 );
2004 1188
@@ -2004,12 +1188,13 @@
2004 1188
2005 1189 $this->add_control(
2006 1190 'post_title',
2007 1191 [
2008 - 'label' => esc_html__( 'Title', 'elementor' ),
1192 + 'label' => __( 'Title', 'elementor' ),
2009 1193 'type' => Controls_Manager::TEXT,
2010 1194 'default' => $this->post->post_title,
2011 1195 'label_block' => true,
1196 + 'separator' => 'none',
2012 1197 ]
2013 1198 );
2014 1199
2015 1200 $post_type_object = get_post_type_object( $this->post->post_type );
@@ -2014,21 +1199,21 @@
2014 1199
2015 1200 $post_type_object = get_post_type_object( $this->post->post_type );
2016 1201
2017 1202 $can_publish = $post_type_object && current_user_can( $post_type_object->cap->publish_posts );
2018 - $is_published = self::STATUS_PUBLISH === $this->post->post_status || self::STATUS_PRIVATE === $this->post->post_status;
1203 + $is_published = DB::STATUS_PUBLISH === $this->post->post_status || DB::STATUS_PRIVATE === $this->post->post_status;
2019 1204
2020 1205 if ( $is_published || $can_publish || ! Plugin::$instance->editor->is_edit_mode() ) {
2021 1206
2022 1207 $statuses = $this->get_post_statuses();
2023 1208 if ( 'future' === $this->get_main_post()->post_status ) {
2024 - $statuses['future'] = esc_html__( 'Future', 'elementor' );
1209 + $statuses['future'] = __( 'Future', 'elementor' );
2025 1210 }
2026 1211
2027 1212 $this->add_control(
2028 1213 'post_status',
2029 1214 [
2030 - 'label' => esc_html__( 'Status', 'elementor' ),
1215 + 'label' => __( 'Status', 'elementor' ),
2031 1216 'type' => Controls_Manager::SELECT,
2032 1217 'default' => $this->get_main_post()->post_status,
2033 1218 'options' => $statuses,
2034 1219 ]
@@ -2043,91 +1228,6 @@
2043 1228 }
2044 1229
2045 1230 protected function get_have_a_look_url() {
2046 1231 return $this->get_permalink();
2047 - }
2048 -
2049 - public function handle_revisions_changed( $post_has_changed, $last_revision, $post ) {
2050 - // In case default, didn't determine the changes.
2051 - if ( ! $post_has_changed ) {
2052 - $last_revision_id = $last_revision->ID;
2053 - $last_revision_document = Plugin::instance()->documents->get( $last_revision_id );
2054 - $post_document = Plugin::instance()->documents->get( $post->ID );
2055 -
2056 - $last_revision_settings = $last_revision_document->get_settings();
2057 - $post_settings = $post_document->get_settings();
2058 -
2059 - // TODO: Its better to add crc32 signature for each revision and then only compare one part of the checksum.
2060 - $post_has_changed = $last_revision_settings !== $post_settings;
2061 - }
2062 -
2063 - return $post_has_changed;
2064 - }
2065 -
2066 - private function add_handle_revisions_changed_filter() {
2067 - add_filter( 'wp_save_post_revision_post_has_changed', [ $this, 'handle_revisions_changed' ], 10, 3 );
2068 - }
2069 -
2070 - private function remove_handle_revisions_changed_filter() {
2071 - remove_filter( 'wp_save_post_revision_post_has_changed', [ $this, 'handle_revisions_changed' ] );
2072 - }
2073 -
2074 - private function get_runtime_elements_iteration_actions() {
2075 - $runtime_elements_iteration_actions = [];
2076 -
2077 - $elements_iteration_actions = $this->get_elements_iteration_actions();
2078 -
2079 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2080 - if ( $elements_iteration_action->is_action_needed() ) {
2081 - $runtime_elements_iteration_actions[] = $elements_iteration_action;
2082 - }
2083 - }
2084 -
2085 - return $runtime_elements_iteration_actions;
2086 - }
2087 -
2088 - private function iterate_elements( $elements, $elements_iteration_actions, $mode ) {
2089 - $unique_page_elements = [];
2090 -
2091 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2092 - $elements_iteration_action->set_mode( $mode );
2093 - }
2094 -
2095 - Plugin::$instance->db->iterate_data( $elements, function( array $element_data ) use ( &$unique_page_elements, $elements_iteration_actions ) {
2096 - $element_type = 'widget' === $element_data['elType'] ? $element_data['widgetType'] : $element_data['elType'];
2097 -
2098 - $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
2099 -
2100 - if ( $element ) {
2101 - if ( ! in_array( $element_type, $unique_page_elements, true ) ) {
2102 - $unique_page_elements[] = $element_type;
2103 -
2104 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2105 - $elements_iteration_action->unique_element_action( $element );
2106 - }
2107 - }
2108 -
2109 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2110 - $elements_iteration_action->element_action( $element );
2111 - }
2112 - }
2113 -
2114 - return $element_data;
2115 - } );
2116 -
2117 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2118 - $elements_iteration_action->after_elements_iteration();
2119 - }
2120 - }
2121 -
2122 - private function get_elements_iteration_actions() {
2123 - if ( ! $this->elements_iteration_actions ) {
2124 - $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2125 - }
2126 -
2127 - return $this->elements_iteration_actions;
2128 - }
2129 -
2130 - public function get_elementor_version() {
2131 - return $this->get_main_meta( '_elementor_version' );
2132 1232 }
2133 1233 }