PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.0-dev4
Elementor Website Builder – more than just a page builder v3.22.0-dev4
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 +38 -113 4.2.03.22.0-dev4 View file →
@@ -5,9 +5,8 @@
5 5 use Elementor\Core\Base\Elements_Iteration_Actions\Base as Elements_Iteration_Action;
6 6 use Elementor\Core\Behaviors\Interfaces\Lock_Behavior;
7 7 use Elementor\Core\Files\CSS\Post as Post_CSS;
8 8 use Elementor\Core\Settings\Page\Model as Page_Model;
9 -use Elementor\Core\Utils\Collection;
10 9 use Elementor\Core\Utils\Exceptions;
11 10 use Elementor\Includes\Elements\Container;
12 11 use Elementor\Plugin;
13 12 use Elementor\Controls_Manager;
@@ -21,9 +20,9 @@
21 20 use ElementorPro\Modules\Library\Widgets\Template;
22 21 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
23 22
24 23 if ( ! defined( 'ABSPATH' ) ) {
25 - exit; // Exit if accessed directly.
24 + exit; // Exit if accessed directly
26 25 }
27 26
28 27 /**
29 28 * Elementor document.
@@ -40,16 +39,13 @@
40 39 * Document type meta key.
41 40 */
42 41 const TYPE_META_KEY = '_elementor_template_type';
43 42 const PAGE_META_KEY = '_elementor_page_settings';
44 - const ELEMENTOR_DATA_META_KEY = '_elementor_data';
45 43
46 44 const BUILT_WITH_ELEMENTOR_META_KEY = '_elementor_edit_mode';
47 45
48 46 const CACHE_META_KEY = '_elementor_element_cache';
49 47
50 - const UNEDITABLE_WITH_ELEMENTOR_TYPES = [ 'kit' ];
51 -
52 48 /**
53 49 * Document publish status.
54 50 */
55 51 const STATUS_PUBLISH = 'publish';
@@ -169,12 +165,8 @@
169 165 'support_kit' => false,
170 166 'show_navigator' => true,
171 167 'allow_adding_widgets' => true,
172 168 '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 169 ];
178 170 }
179 171
180 172 /**
@@ -204,12 +196,8 @@
204 196 ),
205 197 ],
206 198 'show_navigator' => static::get_property( 'show_navigator' ),
207 199 '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 200 ];
213 201 }
214 202
215 203 public static function get_filtered_editor_panel_categories(): array {
@@ -232,16 +220,9 @@
232 220 *
233 221 * @return array
234 222 */
235 223 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 ) {
224 + if ( ! $has_pro ) {
244 225 $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data(
245 226 $promotion,
246 227 'elementor/panel/' . $index . '/custom_promotion',
247 228 'url'
@@ -559,10 +540,12 @@
559 540 *
560 541 * @since 2.0.0
561 542 * @access public
562 543 *
544 + *
563 545 * @return bool|Document
564 546 */
547 +
565 548 public function get_newer_autosave() {
566 549 $autosave = $this->get_autosave();
567 550
568 551 // Detect if there exists an autosave newer than the post.
@@ -617,12 +600,8 @@
617 600
618 601 if ( $autosave_id ) {
619 602 $document = Plugin::$instance->documents->get( $autosave_id );
620 603 } elseif ( $create ) {
621 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
622 - require_once ABSPATH . 'wp-admin/includes/post.php';
623 - }
624 -
625 604 $autosave_id = wp_create_post_autosave( [
626 605 'post_ID' => $this->post->ID,
627 606 'post_type' => $this->post->post_type,
628 607 'post_title' => $this->post->post_title,
@@ -651,14 +630,14 @@
651 630 * Fired by `post_row_actions` and `page_row_actions` filters.
652 631 *
653 632 * @access public
654 633 *
655 - * @param array $actions An array of row action links.
634 + * @param array $actions An array of row action links.
656 635 *
657 636 * @return array An updated array of row action links.
658 637 */
659 638 public function filter_admin_row_actions( $actions ) {
660 - if ( $this->is_editable_with_elementor() ) {
639 + if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) {
661 640 $actions['edit_with_elementor'] = sprintf(
662 641 '<a href="%1$s">%2$s</a>',
663 642 $this->get_edit_url(),
664 643 __( 'Edit with Elementor', 'elementor' )
@@ -667,16 +646,8 @@
667 646
668 647 return $actions;
669 648 }
670 649
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 650 /**
680 651 * @since 2.0.0
681 652 * @access public
682 653 */
@@ -746,16 +717,19 @@
746 717
747 718 do_action( 'elementor/document/before_get_config', $this );
748 719
749 720 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();
721 + $container_config = [];
722 + $experiments_manager = Plugin::$instance->experiments;
754 723
724 + if ( $experiments_manager->is_feature_active( 'container' ) ) {
725 + $container_config = [
726 + 'container' => Plugin::$instance->elements_manager->get_element_types( 'container' )->get_config(),
727 + ];
728 + }
729 +
755 730 $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() );
731 + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config();
758 732 }
759 733
760 734 $additional_config = [];
761 735
@@ -853,11 +827,9 @@
853 827 */
854 828 do_action( 'elementor/document/before_save', $this, $data );
855 829
856 830 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 - } );
831 + $data = wp_kses_post_deep( $data );
860 832 }
861 833
862 834 if ( ! empty( $data['settings'] ) ) {
863 835 if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
@@ -942,9 +914,9 @@
942 914 *
943 915 * @return bool Whether the post was built with Elementor.
944 916 */
945 917 public function is_built_with_elementor() {
946 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
918 + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
947 919 }
948 920
949 921 /**
950 922 * Mark the post as "built with elementor" or not.
@@ -1054,9 +1026,9 @@
1054 1026 return $meta;
1055 1027 }
1056 1028
1057 1029 public function update_json_meta( $key, $value ) {
1058 - return $this->update_meta(
1030 + $this->update_meta(
1059 1031 $key,
1060 1032 // `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1061 1033 wp_slash( wp_json_encode( $value ) )
1062 1034 );
@@ -1069,10 +1041,8 @@
1069 1041 * @param null $data
1070 1042 * @param bool $with_html_content
1071 1043 *
1072 1044 * @return array
1073 - *
1074 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1075 1045 */
1076 1046 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1077 1047 if ( ! static::get_property( 'has_elements' ) ) {
1078 1048 return [];
@@ -1081,23 +1051,8 @@
1081 1051 if ( is_null( $data ) ) {
1082 1052 $data = $this->get_elements_data();
1083 1053 }
1084 1054
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 1055 // Change the current documents, so widgets can use `documents->get_current` and other post data
1101 1056 Plugin::$instance->documents->switch_to_document( $this );
1102 1057
1103 1058 $editor_data = [];
@@ -1122,9 +1077,9 @@
1122 1077 $element_data = $element->get_raw_data( $with_html_content );
1123 1078 }
1124 1079
1125 1080 $editor_data[] = $element_data;
1126 - }
1081 + } // End foreach().
1127 1082
1128 1083 Plugin::$instance->documents->restore_document();
1129 1084
1130 1085 return $editor_data;
@@ -1138,9 +1093,9 @@
1138 1093 *
1139 1094 * @return array
1140 1095 */
1141 1096 public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1142 - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1097 + $elements = $this->get_json_meta( '_elementor_data' );
1143 1098
1144 1099 if ( self::STATUS_DRAFT === $status ) {
1145 1100 $autosave = $this->get_newer_autosave();
1146 1101
@@ -1146,9 +1101,9 @@
1146 1101
1147 1102 if ( is_object( $autosave ) ) {
1148 1103 $autosave_elements = Plugin::$instance->documents
1149 1104 ->get( $autosave->get_post()->ID )
1150 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1105 + ->get_json_meta( '_elementor_data' );
1151 1106 }
1152 1107 }
1153 1108
1154 1109 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1316,9 +1271,9 @@
1316 1271 * @param array|null $controls The available controls.
1317 1272 *
1318 1273 * @return array Element data.
1319 1274 */
1320 - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
1275 + public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array {
1321 1276 foreach ( $config as &$element_config ) {
1322 1277 $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1323 1278
1324 1279 if ( is_null( $element_instance ) ) {
@@ -1385,9 +1340,9 @@
1385 1340 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1386 1341 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1387 1342
1388 1343 // 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 );
1344 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1390 1345
1391 1346 /**
1392 1347 * Before saving data.
1393 1348 *
@@ -1455,8 +1410,9 @@
1455 1410 *
1456 1411 * @since 2.5.12
1457 1412 *
1458 1413 * @param \Elementor\Core\Base\Document $this The current document.
1414 + *
1459 1415 */
1460 1416 do_action( 'elementor/document/save_version', $this );
1461 1417 }
1462 1418 }
@@ -1493,9 +1449,9 @@
1493 1449 * @since 2.0.4
1494 1450 * @access public
1495 1451 *
1496 1452 * @param string $key Meta data key.
1497 - * @param mixed $value Meta data value.
1453 + * @param mixed $value Meta data value.
1498 1454 *
1499 1455 * @return bool|int
1500 1456 */
1501 1457 public function update_main_meta( $key, $value ) {
@@ -1623,9 +1579,9 @@
1623 1579 } else {
1624 1580 $this->post = get_post( $data['post_id'] );
1625 1581
1626 1582 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
1583 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1628 1584 }
1629 1585 }
1630 1586
1631 1587 // Each Control_Stack is based on a unique ID.
@@ -1643,9 +1599,9 @@
1643 1599
1644 1600 parent::__construct( $data );
1645 1601 }
1646 1602
1647 - /**
1603 + /*
1648 1604 * Get Export Data
1649 1605 *
1650 1606 * Filters a document's data on export
1651 1607 *
@@ -1657,10 +1613,8 @@
1657 1613 public function get_export_data() {
1658 1614 $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1659 1615 $element_data['id'] = Utils::generate_random_string();
1660 1616
1661 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1662 -
1663 1617 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1664 1618
1665 1619 // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1666 1620 if ( ! $element ) {
@@ -1684,9 +1638,9 @@
1684 1638 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1685 1639 ];
1686 1640 }
1687 1641
1688 - /**
1642 + /*
1689 1643 * Get Import Data
1690 1644 *
1691 1645 * Filters a document's data on import
1692 1646 *
@@ -1830,25 +1784,14 @@
1830 1784 }
1831 1785
1832 1786 /**
1833 1787 * @since 2.1.3
1834 - * @access public
1788 + * @access protected
1835 1789 */
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 -
1790 + protected function print_elements( $elements_data ) {
1791 + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) {
1841 1792 $this->do_print_elements( $elements_data );
1842 1793
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 1794 return;
1852 1795 }
1853 1796
1854 1797 $cached_data = $this->get_document_cache();
@@ -1901,21 +1844,20 @@
1901 1844 }
1902 1845 }
1903 1846
1904 1847 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
1848 + echo do_shortcode( $cached_data['content'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1912 1849 }
1913 1850 }
1914 1851
1915 1852 protected function do_print_elements( $elements_data ) {
1916 - $this->update_runtime_elements( $elements_data );
1853 + // Collect all data updaters that should be updated on runtime.
1854 + $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions();
1917 1855
1856 + if ( $runtime_elements_iteration_actions ) {
1857 + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1858 + }
1859 +
1918 1860 foreach ( $elements_data as $element_data ) {
1919 1861 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1920 1862
1921 1863 if ( ! $element ) {
@@ -1925,21 +1867,8 @@
1925 1867 $element->print_element();
1926 1868 }
1927 1869 }
1928 1870
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 1871 public function set_document_cache( $value ) {
1943 1872 $expiration_hours = get_option( 'elementor_element_cache_ttl', '' );
1944 1873
1945 1874 if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) {
@@ -2124,10 +2053,6 @@
2124 2053 $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2125 2054 }
2126 2055
2127 2056 return $this->elements_iteration_actions;
2128 - }
2129 -
2130 - public function get_elementor_version() {
2131 - return $this->get_main_meta( '_elementor_version' );
2132 2057 }
2133 2058 }