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 +98 -981 4.0.83.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,57 +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 - /**
51 - * Document publish status.
52 - */
53 - const STATUS_PUBLISH = 'publish';
54 -
55 - /**
56 - * Document draft status.
57 - */
58 - const STATUS_DRAFT = 'draft';
59 -
60 - /**
61 - * Document private status.
62 - */
63 - const STATUS_PRIVATE = 'private';
64 -
65 - /**
66 - * Document autosave status.
67 - */
68 - const STATUS_AUTOSAVE = 'autosave';
69 -
70 - /**
71 - * Document pending status.
72 - */
73 - const STATUS_PENDING = 'pending';
74 -
75 - /**
76 - * @var int
77 - */
78 36 private $main_id;
79 37
80 - /**
81 - * @var bool
82 - */
83 - private $is_saving = false;
84 -
85 38 private static $properties = [];
86 39
87 40 /**
88 - * @var Elements_Iteration_Action[]
89 - */
90 - private $elements_iteration_actions = [];
91 -
92 - /**
93 41 * Document post data.
94 42 *
95 43 * Holds the document post data.
96 44 *
@@ -101,44 +49,8 @@
101 49 */
102 50 protected $post;
103 51
104 52 /**
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 53 * @since 2.1.0
142 54 * @access protected
143 55 * @static
144 56 */
@@ -164,15 +76,8 @@
164 76 'edit_capability' => '',
165 77 'show_in_finder' => true,
166 78 'show_on_admin_bar' => true,
167 79 '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 80 ];
176 81 }
177 82
178 83 /**
@@ -180,72 +85,23 @@
180 85 * @access public
181 86 * @static
182 87 */
183 88 public static function get_editor_panel_config() {
184 - $default_route = 'panel/elements/categories';
185 -
186 - if ( ! Plugin::instance()->role_manager->user_can( 'design' ) ) {
187 - $default_route = 'panel/page-settings/settings';
188 - }
189 -
190 89 return [
191 90 'title' => static::get_title(), // JS Container title.
192 91 'widgets_settings' => [],
193 - 'elements_categories' => self::get_filtered_editor_panel_categories(),
194 - 'default_route' => $default_route,
92 + 'elements_categories' => static::get_editor_panel_categories(),
93 + 'default_route' => 'panel/elements/categories',
195 94 'has_elements' => static::get_property( 'has_elements' ),
196 95 'support_kit' => static::get_property( 'support_kit' ),
197 96 'messages' => [
198 - 'publish_notification' => sprintf(
199 - /* translators: %s: Document title. */
200 - esc_html__( 'Hurray! Your %s is live.', 'elementor' ),
201 - static::get_title()
202 - ),
97 + /* translators: %s: the document title. */
98 + 'publish_notification' => sprintf( __( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ),
203 99 ],
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 100 ];
211 101 }
212 102
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 103 /**
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 104 * Get element title.
249 105 *
250 106 * Retrieve the element title.
251 107 *
@@ -255,23 +111,11 @@
255 111 *
256 112 * @return string Element title.
257 113 */
258 114 public static function get_title() {
259 - return esc_html__( 'Document', 'elementor' );
115 + return __( 'Document', 'elementor' );
260 116 }
261 117
262 - public static function get_plural_title() {
263 - return static::get_title();
264 - }
265 -
266 - 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 - );
272 - }
273 -
274 118 /**
275 119 * Get property.
276 120 *
277 121 * Retrieve the document property.
@@ -302,31 +146,14 @@
302 146 public static function get_class_full_name() {
303 147 return get_called_class();
304 148 }
305 149
306 - public static function get_create_url() {
307 - $properties = static::get_properties();
308 -
309 - // BC Support - Each document should define it own CPT this code is for BC support.
310 - $cpt = Source_Local::CPT;
311 -
312 - if ( isset( $properties['cpt'][0] ) ) {
313 - $cpt = $properties['cpt'][0];
314 - }
315 -
316 - return Plugin::$instance->documents->get_create_new_post_url( $cpt, static::get_type() );
317 - }
318 -
319 - public function get_name() {
320 - return static::get_type();
321 - }
322 -
323 150 /**
324 151 * @since 2.0.0
325 152 * @access public
326 153 */
327 154 public function get_unique_name() {
328 - return static::get_type() . '-' . $this->post->ID;
155 + return $this->get_name() . '-' . $this->post->ID;
329 156 }
330 157
331 158 /**
332 159 * @since 2.3.0
@@ -338,8 +165,17 @@
338 165 return $post_type_object->labels->singular_name;
339 166 }
340 167
341 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 + /**
342 178 * @since 2.0.0
343 179 * @access public
344 180 */
345 181 public function get_main_id() {
@@ -358,15 +194,8 @@
358 194 return $this->main_id;
359 195 }
360 196
361 197 /**
362 - * @return null|Lock_Behavior
363 - */
364 - public static function get_lock_behavior_v2() {
365 - return null;
366 - }
367 -
368 - /**
369 198 * @since 2.0.0
370 199 * @access public
371 200 *
372 201 * @param $data
@@ -400,8 +229,19 @@
400 229 public function get_main_post() {
401 230 return get_post( $this->get_main_id() );
402 231 }
403 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 +
404 244 public function get_container_attributes() {
405 245 $id = $this->get_main_id();
406 246
407 247 $attributes = [
@@ -418,16 +258,12 @@
418 258
419 259 if ( Plugin::$instance->preview->is_preview() ) {
420 260 $attributes['data-elementor-title'] = static::get_title();
421 261 } else {
422 - $elementor_settings = $this->get_frontend_settings();
423 - if ( ! empty( $elementor_settings ) ) {
424 - $attributes['data-elementor-settings'] = wp_json_encode( $elementor_settings );
425 - }
262 + $attributes['data-elementor-settings'] = wp_json_encode( $this->get_frontend_settings() );
426 263 }
427 264
428 - // apply this filter to allow the attributes to be modified by different sources
429 - return apply_filters( 'elementor/document/wrapper_attributes', $attributes, $this );
265 + return $attributes;
430 266 }
431 267
432 268 /**
433 269 * @since 2.0.0
@@ -437,12 +273,10 @@
437 273 $main_post_id = $this->get_main_id();
438 274 $document = $this;
439 275
440 276 // 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
277 + if ( ! empty( $_POST['initial_document_id'] ) ) {
278 + $document = Plugin::$instance->documents->get( $_POST['initial_document_id'] );
445 279 }
446 280
447 281 $url = get_preview_post_link(
448 282 $document->get_main_id(),
@@ -489,62 +323,8 @@
489 323 return $url;
490 324 }
491 325
492 326 /**
493 - * Get All Post Type URL
494 - *
495 - * Get url of the page which display all the posts of the current active document's post type.
496 - *
497 - * @since 3.7.0
498 - *
499 - * @return string $url
500 - */
501 - public function get_all_post_type_url() {
502 - $post_type = get_post_type( $this->get_main_id() );
503 -
504 - $url = get_admin_url() . 'edit.php';
505 -
506 - if ( 'post' !== $post_type ) {
507 - $url .= '?post_type=' . $post_type;
508 - }
509 -
510 - /**
511 - * Document "display all post type" URL.
512 - *
513 - * @since 3.7.0
514 - *
515 - * @param string $url The URL.
516 - * @param Document $this The document instance.
517 - */
518 - $url = apply_filters( 'elementor/document/urls/all_post_type', $url, $this );
519 -
520 - return $url;
521 - }
522 -
523 - /**
524 - * Get Main WP dashboard URL.
525 - *
526 - * @since 3.7.0
527 - *
528 - * @return string $url
529 - */
530 - protected function get_main_dashboard_url() {
531 - $url = get_dashboard_url();
532 -
533 - /**
534 - * Document "Main Dashboard" URL.
535 - *
536 - * @since 3.7.0
537 - *
538 - * @param string $url The URL.
539 - * @param Document $this The document instance.
540 - */
541 - $url = apply_filters( 'elementor/document/urls/main_dashboard', $url, $this );
542 -
543 - return $url;
544 - }
545 -
546 - /**
547 327 * Get auto-saved post revision.
548 328 *
549 329 * Retrieve the auto-saved post revision that is newer than current post.
550 330 *
@@ -550,10 +330,12 @@
550 330 *
551 331 * @since 2.0.0
552 332 * @access public
553 333 *
334 + *
554 335 * @return bool|Document
555 336 */
337 +
556 338 public function get_newer_autosave() {
557 339 $autosave = $this->get_autosave();
558 340
559 341 // Detect if there exists an autosave newer than the post.
@@ -572,26 +354,8 @@
572 354 return wp_is_post_autosave( $this->post->ID );
573 355 }
574 356
575 357 /**
576 - * Check if the current document is a 'revision'
577 - *
578 - * @return bool
579 - */
580 - public function is_revision() {
581 - return 'revision' === $this->post->post_type;
582 - }
583 -
584 - /**
585 - * Checks if the current document status is 'trash'.
586 - *
587 - * @return bool
588 - */
589 - public function is_trash() {
590 - return 'trash' === $this->post->post_status;
591 - }
592 -
593 - /**
594 358 * @since 2.0.0
595 359 * @access public
596 360 *
597 361 * @param int $user_id
@@ -608,12 +372,8 @@
608 372
609 373 if ( $autosave_id ) {
610 374 $document = Plugin::$instance->documents->get( $autosave_id );
611 375 } elseif ( $create ) {
612 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
613 - require_once ABSPATH . 'wp-admin/includes/post.php';
614 - }
615 -
616 376 $autosave_id = wp_create_post_autosave( [
617 377 'post_ID' => $this->post->ID,
618 378 'post_type' => $this->post->post_type,
619 379 'post_title' => $this->post->post_title,
@@ -642,9 +402,9 @@
642 402 * Fired by `post_row_actions` and `page_row_actions` filters.
643 403 *
644 404 * @access public
645 405 *
646 - * @param array $actions An array of row action links.
406 + * @param array $actions An array of row action links.
647 407 *
648 408 * @return array An updated array of row action links.
649 409 */
650 410 public function filter_admin_row_actions( $actions ) {
@@ -684,12 +444,10 @@
684 444 if ( $locked_user ) {
685 445 $locked_user = $locked_user->display_name;
686 446 }
687 447
688 - $post = $this->get_main_post();
448 + $post_type_object = get_post_type_object( $this->get_main_post()->post_type );
689 449
690 - $post_type_object = get_post_type_object( $post->post_type );
691 -
692 450 $settings = SettingsManager::get_settings_managers_config();
693 451
694 452 $config = [
695 453 'id' => $this->get_main_id(),
@@ -707,56 +465,23 @@
707 465 // Deprecated config since 2.9.0.
708 466 'locked' => $locked_user,
709 467 ],
710 468 'urls' => [
711 - 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(), // WP post type edit page
712 - 'all_post_type' => $this->get_all_post_type_url(),
469 + 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(),
713 470 'preview' => $this->get_preview_url(),
714 471 'wp_preview' => $this->get_wp_preview_url(),
715 472 'permalink' => $this->get_permalink(),
716 473 'have_a_look' => $this->get_have_a_look_url(),
717 - 'main_dashboard' => $this->get_main_dashboard_url(),
718 474 ],
719 475 ];
720 476
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 - do_action( 'elementor/document/before_get_config', $this );
731 -
732 477 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();
737 -
738 478 $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() );
479 + $config['widgets'] = Plugin::$instance->widgets_manager->get_widget_types_config();
741 480 }
742 481
743 - $additional_config = [];
482 + $additional_config = apply_filters( 'elementor/document/config', [], $this->get_main_id() );
744 483
745 - /**
746 - * Additional document configuration.
747 - *
748 - * Filters the document configuration by adding additional configuration.
749 - * External developers can use this hook to add custom configuration in
750 - * addition to Elementor's initial configuration.
751 - *
752 - * Use the $post_id to add custom configuration for different pages.
753 - *
754 - * @param array $additional_config The additional document configuration.
755 - * @param int $post_id The post ID of the document.
756 - */
757 - $additional_config = apply_filters( 'elementor/document/config', $additional_config, $this->get_main_id() );
758 -
759 484 if ( ! empty( $additional_config ) ) {
760 485 $config = array_replace_recursive( $config, $additional_config );
761 486 }
762 487
@@ -763,21 +488,18 @@
763 488 return $config;
764 489 }
765 490
766 491 /**
767 - * @since 3.1.0
492 + * @since 2.0.0
768 493 * @access protected
769 494 */
770 - protected function register_controls() {
495 + protected function _register_controls() {
771 496 $this->register_document_controls();
772 -
773 497 /**
774 498 * Register document controls.
775 499 *
776 500 * Fires after Elementor registers the document controls.
777 501 *
778 - * External developers can use this hook to add new controls to the document.
779 - *
780 502 * @since 2.0.0
781 503 *
782 504 * @param Document $this The document instance.
783 505 */
@@ -792,39 +514,12 @@
792 514 *
793 515 * @return bool
794 516 */
795 517 public function save( $data ) {
796 - /**
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 - * Document save data.
806 - *
807 - * Filter the document data before saving process starts.
808 - *
809 - * External developers can use this hook to change the data before
810 - * saving it to the database.
811 - *
812 - * @since 3.3.0
813 - *
814 - * @param array $data The document data.
815 - * @param \Elementor\Core\Base\Document $this The document instance.
816 - */
817 - $data = apply_filters( 'elementor/document/save/data', $data, $this );
818 -
819 - $this->add_handle_revisions_changed_filter();
820 -
821 518 if ( ! $this->is_editable_by_current_user() ) {
822 519 return false;
823 520 }
824 521
825 - $this->set_is_saving( true );
826 -
827 522 /**
828 523 * Before document save.
829 524 *
830 525 * Fires when document save starts on Elementor.
@@ -836,15 +531,13 @@
836 531 */
837 532 do_action( 'elementor/document/before_save', $this, $data );
838 533
839 534 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 - } );
535 + $data = wp_kses_post_deep( $data );
843 536 }
844 537
845 538 if ( ! empty( $data['settings'] ) ) {
846 - 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'] ) {
847 540 if ( ! defined( 'DOING_AUTOSAVE' ) ) {
848 541 define( 'DOING_AUTOSAVE', true );
849 542 }
850 543 }
@@ -850,9 +543,10 @@
850 543 }
851 544
852 545 $this->save_settings( $data['settings'] );
853 546
854 - $this->refresh_post();
547 + // Refresh post after save settings.
548 + $this->post = get_post( $this->post->ID );
855 549 }
856 550
857 551 // Don't check is_empty, because an empty array should be saved.
858 552 if ( isset( $data['elements'] ) && is_array( $data['elements'] ) ) {
@@ -867,11 +561,8 @@
867 561 $post_css = Post_CSS::create( $this->post->ID );
868 562
869 563 $post_css->delete();
870 564
871 - // Remove Document Cache
872 - $this->delete_cache();
873 -
874 565 /**
875 566 * After document save.
876 567 *
877 568 * Fires when document save is complete.
@@ -882,41 +573,12 @@
882 573 * @param $data.
883 574 */
884 575 do_action( 'elementor/document/after_save', $this, $data );
885 576
886 - $this->set_is_saving( false );
887 -
888 - $this->remove_handle_revisions_changed_filter();
889 -
890 - setlocale( LC_NUMERIC, $original_lc );
891 -
892 577 return true;
893 578 }
894 579
895 - public function refresh_post() {
896 - $this->post = get_post( $this->post->ID );
897 - }
898 -
899 580 /**
900 - * @param array $new_settings
901 - *
902 - * @return static
903 - */
904 - public function update_settings( array $new_settings ) {
905 - $document_settings = $this->get_meta( PageManager::META_KEY );
906 -
907 - if ( ! $document_settings ) {
908 - $document_settings = [];
909 - }
910 -
911 - $this->save_settings(
912 - array_replace_recursive( $document_settings, $new_settings )
913 - );
914 -
915 - return $this;
916 - }
917 -
918 - /**
919 581 * Is built with Elementor.
920 582 *
921 583 * Check whether the post was built with Elementor.
922 584 *
@@ -925,30 +587,12 @@
925 587 *
926 588 * @return bool Whether the post was built with Elementor.
927 589 */
928 590 public function is_built_with_elementor() {
929 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
591 + return ! ! get_post_meta( $this->post->ID, '_elementor_edit_mode', true );
930 592 }
931 593
932 594 /**
933 - * Mark the post as "built with elementor" or not.
934 - *
935 - * @param bool $is_built_with_elementor
936 - *
937 - * @return $this
938 - */
939 - public function set_is_built_with_elementor( $is_built_with_elementor ) {
940 - if ( $is_built_with_elementor ) {
941 - // Use the string `builder` and not a boolean for rollback compatibility
942 - $this->update_meta( self::BUILT_WITH_ELEMENTOR_META_KEY, 'builder' );
943 - } else {
944 - $this->delete_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
945 - }
946 -
947 - return $this;
948 - }
949 -
950 - /**
951 595 * @since 2.0.0
952 596 * @access public
953 597 * @static
954 598 *
@@ -1036,16 +680,8 @@
1036 680
1037 681 return $meta;
1038 682 }
1039 683
1040 - public function update_json_meta( $key, $value ) {
1041 - return $this->update_meta(
1042 - $key,
1043 - // `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1044 - wp_slash( wp_json_encode( $value ) )
1045 - );
1046 - }
1047 -
1048 684 /**
1049 685 * @since 2.0.0
1050 686 * @access public
1051 687 *
@@ -1052,10 +688,8 @@
1052 688 * @param null $data
1053 689 * @param bool $with_html_content
1054 690 *
1055 691 * @return array
1056 - *
1057 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1058 692 */
1059 693 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1060 694 if ( ! static::get_property( 'has_elements' ) ) {
1061 695 return [];
@@ -1064,23 +698,8 @@
1064 698 if ( is_null( $data ) ) {
1065 699 $data = $this->get_elements_data();
1066 700 }
1067 701
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 702 // Change the current documents, so widgets can use `documents->get_current` and other post data
1084 703 Plugin::$instance->documents->switch_to_document( $this );
1085 704
1086 705 $editor_data = [];
@@ -1085,15 +704,8 @@
1085 704
1086 705 $editor_data = [];
1087 706
1088 707 foreach ( $data as $element_data ) {
1089 - if ( ! is_array( $element_data ) ) {
1090 - throw new \Exception( 'Invalid data: ' . wp_json_encode( [
1091 - 'data' => $data,
1092 - 'element' => $element_data,
1093 - ] ) );
1094 - }
1095 -
1096 708 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1097 709
1098 710 if ( ! $element ) {
1099 711 continue;
@@ -1098,17 +710,11 @@
1098 710 if ( ! $element ) {
1099 711 continue;
1100 712 }
1101 713
1102 - if ( $this->is_saving ) {
1103 - $element_data = $element->get_data_for_save();
1104 - } else {
1105 - $element_data = $element->get_raw_data( $with_html_content );
1106 - }
714 + $editor_data[] = $element->get_raw_data( $with_html_content );
715 + } // End foreach().
1107 716
1108 - $editor_data[] = $element_data;
1109 - }
1110 -
1111 717 Plugin::$instance->documents->restore_document();
1112 718
1113 719 return $editor_data;
1114 720 }
@@ -1120,18 +726,18 @@
1120 726 * @param string $status
1121 727 *
1122 728 * @return array
1123 729 */
1124 - public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1125 - $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' );
1126 732
1127 - if ( self::STATUS_DRAFT === $status ) {
733 + if ( DB::STATUS_DRAFT === $status ) {
1128 734 $autosave = $this->get_newer_autosave();
1129 735
1130 736 if ( is_object( $autosave ) ) {
1131 737 $autosave_elements = Plugin::$instance->documents
1132 738 ->get( $autosave->get_post()->ID )
1133 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
739 + ->get_json_meta( '_elementor_data' );
1134 740 }
1135 741 }
1136 742
1137 743 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1151,17 +757,8 @@
1151 757 return $elements;
1152 758 }
1153 759
1154 760 /**
1155 - * Get document setting from DB.
1156 - *
1157 - * @return array
1158 - */
1159 - public function get_db_document_settings() {
1160 - return $this->get_meta( static::PAGE_META_KEY );
1161 - }
1162 -
1163 - /**
1164 761 * @since 2.3.0
1165 762 * @access public
1166 763 */
1167 764 public function convert_to_elementor() {
@@ -1192,20 +789,28 @@
1192 789 ];
1193 790 }
1194 791
1195 792 // TODO: Better coding to start template for editor
1196 - $converted_blocks = [
793 + return [
1197 794 [
1198 795 'id' => Utils::generate_random_string(),
1199 - 'elType' => $widget_type::get_type(),
1200 - 'widgetType' => $widget_type->get_name(),
1201 - '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 + ],
1202 811 ],
1203 812 ];
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 813 }
1209 814
1210 815 /**
1211 816 * @since 2.1.3
@@ -1215,11 +820,21 @@
1215 820 if ( ! $elements_data ) {
1216 821 $elements_data = $this->get_elements_data();
1217 822 }
1218 823
824 + $is_legacy_mode_active = Plugin::instance()->get_legacy_mode( 'elementWrappers' );
825 +
1219 826 ?>
1220 - <div <?php Utils::print_html_attributes( $this->get_container_attributes() ); ?>>
1221 - <?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 } ?>
1222 837 </div>
1223 838 <?php
1224 839 }
1225 840
@@ -1236,13 +851,10 @@
1236 851 * @access public
1237 852 */
1238 853 public function get_panel_page_settings() {
1239 854 return [
1240 - 'title' => sprintf(
1241 - /* translators: %s: Document title. */
1242 - esc_html__( '%s Settings', 'elementor' ),
1243 - static::get_title()
1244 - ),
855 + /* translators: %s: Document title */
856 + 'title' => sprintf( __( '%s Settings', 'elementor' ), static::get_title() ),
1245 857 ];
1246 858 }
1247 859
1248 860 /**
@@ -1282,78 +894,9 @@
1282 894
1283 895 return $deleted && ! is_wp_error( $deleted );
1284 896 }
1285 897
1286 - public function force_delete() {
1287 - $deleted = wp_delete_post( $this->post->ID, true );
1288 -
1289 - return $deleted && ! is_wp_error( $deleted );
1290 - }
1291 -
1292 898 /**
1293 - * On import update dynamic content (e.g. post and term IDs).
1294 - *
1295 - * @since 3.8.0
1296 - *
1297 - * @param array $config The config of the passed element.
1298 - * @param array $data The data that requires updating/replacement when imported.
1299 - * @param array|null $controls The available controls.
1300 - *
1301 - * @return array Element data.
1302 - */
1303 - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
1304 - foreach ( $config as &$element_config ) {
1305 - $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1306 -
1307 - if ( is_null( $element_instance ) ) {
1308 - continue;
1309 - }
1310 -
1311 - if ( $element_instance->has_own_method( 'on_import_replace_dynamic_content' ) ) {
1312 - // TODO: Remove this check in the future.
1313 - $element_config = $element_instance::on_import_replace_dynamic_content( $element_config, $data['post_ids'] );
1314 - } else {
1315 - $element_config = $element_instance::on_import_update_dynamic_content( $element_config, $data, $element_instance->get_controls() );
1316 - }
1317 -
1318 - $element_config['elements'] = static::on_import_update_dynamic_content( $element_config['elements'], $data );
1319 - }
1320 -
1321 - return $config;
1322 - }
1323 -
1324 - /**
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 899 * Save editor elements.
1357 900 *
1358 901 * Save data from the editor to the database.
1359 902 *
@@ -1368,9 +911,9 @@
1368 911 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1369 912 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1370 913
1371 914 // 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 );
915 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1373 916
1374 917 /**
1375 918 * Before saving data.
1376 919 *
@@ -1384,14 +927,8 @@
1384 927 do_action( 'elementor/db/before_save', $this->post->post_status, $is_meta_updated );
1385 928
1386 929 Plugin::$instance->db->save_plain_text( $this->post->ID );
1387 930
1388 - $elements_iteration_actions = $this->get_elements_iteration_actions();
1389 -
1390 - if ( $elements_iteration_actions ) {
1391 - $this->iterate_elements( $elements, $elements_iteration_actions, 'save' );
1392 - }
1393 -
1394 931 /**
1395 932 * After saving data.
1396 933 *
1397 934 * Fires after Elementor saves data to the database.
@@ -1438,8 +975,9 @@
1438 975 *
1439 976 * @since 2.5.12
1440 977 *
1441 978 * @param \Elementor\Core\Base\Document $this The current document.
979 + *
1442 980 */
1443 981 do_action( 'elementor/document/save_version', $this );
1444 982 }
1445 983 }
@@ -1476,9 +1014,9 @@
1476 1014 * @since 2.0.4
1477 1015 * @access public
1478 1016 *
1479 1017 * @param string $key Meta data key.
1480 - * @param mixed $value Meta data value.
1018 + * @param string $value Meta data value.
1481 1019 *
1482 1020 * @return bool|int
1483 1021 */
1484 1022 public function update_main_meta( $key, $value ) {
@@ -1553,46 +1091,19 @@
1553 1091 $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) );
1554 1092 $display_name = get_the_author_meta( 'display_name', $post->post_author );
1555 1093
1556 1094 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 - );
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 );
1563 1097 } 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 - );
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 );
1570 1100 }
1571 1101
1572 1102 return $last_edited;
1573 1103 }
1574 1104
1575 -
1576 1105 /**
1577 - * @return bool
1578 - */
1579 - public function is_saving() {
1580 - return $this->is_saving;
1581 - }
1582 -
1583 - /**
1584 - * @param $is_saving
1585 - *
1586 - * @return $this
1587 - */
1588 - public function set_is_saving( $is_saving ) {
1589 - $this->is_saving = $is_saving;
1590 -
1591 - return $this;
1592 - }
1593 -
1594 - /**
1595 1106 * @since 2.0.0
1596 1107 * @access public
1597 1108 *
1598 1109 * @param array $data
@@ -1606,9 +1117,9 @@
1606 1117 } else {
1607 1118 $this->post = get_post( $data['post_id'] );
1608 1119
1609 1120 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
1121 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1611 1122 }
1612 1123 }
1613 1124
1614 1125 // Each Control_Stack is based on a unique ID.
@@ -1626,170 +1137,8 @@
1626 1137
1627 1138 parent::__construct( $data );
1628 1139 }
1629 1140
1630 - /**
1631 - * Get Export Data
1632 - *
1633 - * Filters a document's data on export
1634 - *
1635 - * @since 3.2.0
1636 - * @access public
1637 - *
1638 - * @return array The data to export
1639 - */
1640 - public function get_export_data() {
1641 - $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1642 - $element_data['id'] = Utils::generate_random_string();
1643 -
1644 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1645 -
1646 - $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1647 -
1648 - // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1649 - if ( ! $element ) {
1650 - return null;
1651 - }
1652 -
1653 - return $this->process_element_import_export( $element, 'on_export' );
1654 - } );
1655 -
1656 - return [
1657 - 'content' => $content,
1658 - 'settings' => $this->get_data( 'settings' ),
1659 - 'metadata' => $this->get_export_metadata(),
1660 - ];
1661 - }
1662 -
1663 - public function get_export_summary() {
1664 - return [
1665 - 'title' => $this->post->post_title,
1666 - 'doc_type' => $this->get_name(),
1667 - 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1668 - ];
1669 - }
1670 -
1671 - /**
1672 - * Get Import Data
1673 - *
1674 - * Filters a document's data on import
1675 - *
1676 - * @since 3.2.0
1677 - * @access public
1678 - *
1679 - * @return array The data to import
1680 - */
1681 - public function get_import_data( array $data ) {
1682 - $data['content'] = Plugin::$instance->db->iterate_data( $data['content'], function( $element_data ) {
1683 - $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1684 -
1685 - // If the widget/element isn't exist, like a plugin that creates a widget but deactivated
1686 - if ( ! $element ) {
1687 - return null;
1688 - }
1689 -
1690 - return $this->process_element_import_export( $element, 'on_import' );
1691 - } );
1692 -
1693 - if ( ! empty( $data['settings'] ) ) {
1694 - $template_model = new Page_Model( [
1695 - 'id' => 0,
1696 - 'settings' => $data['settings'],
1697 - ] );
1698 -
1699 - $page_data = $this->process_element_import_export( $template_model, 'on_import' );
1700 -
1701 - $data['settings'] = $page_data['settings'];
1702 - }
1703 -
1704 - return $data;
1705 - }
1706 -
1707 - /**
1708 - * Import
1709 - *
1710 - * Allows to import an external data to a document
1711 - *
1712 - * @since 3.2.0
1713 - * @access public
1714 - *
1715 - * @param array $data
1716 - */
1717 - public function import( array $data ) {
1718 - $data = $this->get_import_data( $data );
1719 -
1720 - $this->save( [
1721 - 'elements' => $data['content'],
1722 - 'settings' => $data['settings'],
1723 - ] );
1724 -
1725 - if ( $data['import_settings']['thumbnail'] ) {
1726 - $attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( [ 'url' => $data['import_settings']['thumbnail'] ] );
1727 -
1728 - set_post_thumbnail( $this->get_main_post(), $attachment['id'] );
1729 - }
1730 -
1731 - if ( ! empty( $data['metadata'] ) ) {
1732 - foreach ( $data['metadata'] as $key => $value ) {
1733 - $this->update_meta( $key, $value );
1734 - }
1735 - }
1736 - }
1737 -
1738 - public function process_element_import_export( Controls_Stack $element, $method, $element_data = null ) {
1739 - if ( null === $element_data ) {
1740 - $element_data = $element->get_data();
1741 - }
1742 -
1743 - if ( method_exists( $element, $method ) ) {
1744 - // TODO: Use the internal element data without parameters.
1745 - $element_data = $element->{$method}( $element_data );
1746 - }
1747 -
1748 - foreach ( $element->get_controls() as $control ) {
1749 - $control_class = Plugin::$instance->controls_manager->get_control( $control['type'] );
1750 -
1751 - // If the control isn't exist, like a plugin that creates the control but deactivated.
1752 - if ( ! $control_class ) {
1753 - return $element_data;
1754 - }
1755 -
1756 - // Do not add default value to the final settings, if there is no value at the
1757 - // data before the methods `on_import` or `on_export` called.
1758 - $has_value = isset( $element_data['settings'][ $control['name'] ] );
1759 -
1760 - if ( $has_value && method_exists( $control_class, $method ) ) {
1761 - $element_data['settings'][ $control['name'] ] = $control_class->{$method}(
1762 - $element_data['settings'][ $control['name'] ],
1763 - $control
1764 - );
1765 - }
1766 -
1767 - // On Export, check if the control has an argument 'export' => false.
1768 - if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) {
1769 - unset( $element_data['settings'][ $control['name'] ] );
1770 - }
1771 - }
1772 -
1773 - return $element_data;
1774 - }
1775 -
1776 - protected function get_export_metadata() {
1777 - $metadata = get_post_meta( $this->get_main_id() );
1778 -
1779 - foreach ( $metadata as $meta_key => $meta_value ) {
1780 - if ( is_protected_meta( $meta_key, 'post' ) ) {
1781 - unset( $metadata[ $meta_key ] );
1782 -
1783 - continue;
1784 - }
1785 -
1786 - $metadata[ $meta_key ] = $meta_value[0];
1787 - }
1788 -
1789 - return $metadata;
1790 - }
1791 -
1792 1141 protected function get_remote_library_config() {
1793 1142 $config = [
1794 1143 'type' => 'block',
1795 1144 'default_route' => 'templates/blocks',
@@ -1813,92 +1162,11 @@
1813 1162 }
1814 1163
1815 1164 /**
1816 1165 * @since 2.1.3
1817 - * @access public
1166 + * @access protected
1818 1167 */
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();
1823 -
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;
1835 - }
1836 -
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 -
1168 + protected function print_elements( $elements_data ) {
1901 1169 foreach ( $elements_data as $element_data ) {
1902 1170 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1903 1171
1904 1172 if ( ! $element ) {
@@ -1908,80 +1176,13 @@
1908 1176 $element->print_element();
1909 1177 }
1910 1178 }
1911 1179
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 1180 protected function register_document_controls() {
1980 1181 $this->start_controls_section(
1981 1182 'document_settings',
1982 1183 [
1983 - 'label' => esc_html__( 'General Settings', 'elementor' ),
1184 + 'label' => __( 'General Settings', 'elementor' ),
1984 1185 'tab' => Controls_Manager::TAB_SETTINGS,
1985 1186 ]
1986 1187 );
1987 1188
@@ -1987,12 +1188,13 @@
1987 1188
1988 1189 $this->add_control(
1989 1190 'post_title',
1990 1191 [
1991 - 'label' => esc_html__( 'Title', 'elementor' ),
1192 + 'label' => __( 'Title', 'elementor' ),
1992 1193 'type' => Controls_Manager::TEXT,
1993 1194 'default' => $this->post->post_title,
1994 1195 'label_block' => true,
1196 + 'separator' => 'none',
1995 1197 ]
1996 1198 );
1997 1199
1998 1200 $post_type_object = get_post_type_object( $this->post->post_type );
@@ -1997,21 +1199,21 @@
1997 1199
1998 1200 $post_type_object = get_post_type_object( $this->post->post_type );
1999 1201
2000 1202 $can_publish = $post_type_object && current_user_can( $post_type_object->cap->publish_posts );
2001 - $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;
2002 1204
2003 1205 if ( $is_published || $can_publish || ! Plugin::$instance->editor->is_edit_mode() ) {
2004 1206
2005 1207 $statuses = $this->get_post_statuses();
2006 1208 if ( 'future' === $this->get_main_post()->post_status ) {
2007 - $statuses['future'] = esc_html__( 'Future', 'elementor' );
1209 + $statuses['future'] = __( 'Future', 'elementor' );
2008 1210 }
2009 1211
2010 1212 $this->add_control(
2011 1213 'post_status',
2012 1214 [
2013 - 'label' => esc_html__( 'Status', 'elementor' ),
1215 + 'label' => __( 'Status', 'elementor' ),
2014 1216 'type' => Controls_Manager::SELECT,
2015 1217 'default' => $this->get_main_post()->post_status,
2016 1218 'options' => $statuses,
2017 1219 ]
@@ -2026,91 +1228,6 @@
2026 1228 }
2027 1229
2028 1230 protected function get_have_a_look_url() {
2029 1231 return $this->get_permalink();
2030 - }
2031 -
2032 - public function handle_revisions_changed( $post_has_changed, $last_revision, $post ) {
2033 - // In case default, didn't determine the changes.
2034 - if ( ! $post_has_changed ) {
2035 - $last_revision_id = $last_revision->ID;
2036 - $last_revision_document = Plugin::instance()->documents->get( $last_revision_id );
2037 - $post_document = Plugin::instance()->documents->get( $post->ID );
2038 -
2039 - $last_revision_settings = $last_revision_document->get_settings();
2040 - $post_settings = $post_document->get_settings();
2041 -
2042 - // TODO: Its better to add crc32 signature for each revision and then only compare one part of the checksum.
2043 - $post_has_changed = $last_revision_settings !== $post_settings;
2044 - }
2045 -
2046 - return $post_has_changed;
2047 - }
2048 -
2049 - private function add_handle_revisions_changed_filter() {
2050 - add_filter( 'wp_save_post_revision_post_has_changed', [ $this, 'handle_revisions_changed' ], 10, 3 );
2051 - }
2052 -
2053 - private function remove_handle_revisions_changed_filter() {
2054 - remove_filter( 'wp_save_post_revision_post_has_changed', [ $this, 'handle_revisions_changed' ] );
2055 - }
2056 -
2057 - private function get_runtime_elements_iteration_actions() {
2058 - $runtime_elements_iteration_actions = [];
2059 -
2060 - $elements_iteration_actions = $this->get_elements_iteration_actions();
2061 -
2062 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2063 - if ( $elements_iteration_action->is_action_needed() ) {
2064 - $runtime_elements_iteration_actions[] = $elements_iteration_action;
2065 - }
2066 - }
2067 -
2068 - return $runtime_elements_iteration_actions;
2069 - }
2070 -
2071 - private function iterate_elements( $elements, $elements_iteration_actions, $mode ) {
2072 - $unique_page_elements = [];
2073 -
2074 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2075 - $elements_iteration_action->set_mode( $mode );
2076 - }
2077 -
2078 - Plugin::$instance->db->iterate_data( $elements, function( array $element_data ) use ( &$unique_page_elements, $elements_iteration_actions ) {
2079 - $element_type = 'widget' === $element_data['elType'] ? $element_data['widgetType'] : $element_data['elType'];
2080 -
2081 - $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
2082 -
2083 - if ( $element ) {
2084 - if ( ! in_array( $element_type, $unique_page_elements, true ) ) {
2085 - $unique_page_elements[] = $element_type;
2086 -
2087 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2088 - $elements_iteration_action->unique_element_action( $element );
2089 - }
2090 - }
2091 -
2092 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2093 - $elements_iteration_action->element_action( $element );
2094 - }
2095 - }
2096 -
2097 - return $element_data;
2098 - } );
2099 -
2100 - foreach ( $elements_iteration_actions as $elements_iteration_action ) {
2101 - $elements_iteration_action->after_elements_iteration();
2102 - }
2103 - }
2104 -
2105 - private function get_elements_iteration_actions() {
2106 - if ( ! $this->elements_iteration_actions ) {
2107 - $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2108 - }
2109 -
2110 - return $this->elements_iteration_actions;
2111 - }
2112 -
2113 - public function get_elementor_version() {
2114 - return $this->get_main_meta( '_elementor_version' );
2115 1232 }
2116 1233 }