PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.4
Elementor Website Builder – more than just a page builder v3.24.4
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 -103 4.2.33.24.4 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';
@@ -232,16 +228,9 @@
232 228 *
233 229 * @return array
234 230 */
235 231 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 ) {
232 + if ( ! $has_pro ) {
244 233 $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data(
245 234 $promotion,
246 235 'elementor/panel/' . $index . '/custom_promotion',
247 236 'url'
@@ -559,10 +548,12 @@
559 548 *
560 549 * @since 2.0.0
561 550 * @access public
562 551 *
552 + *
563 553 * @return bool|Document
564 554 */
555 +
565 556 public function get_newer_autosave() {
566 557 $autosave = $this->get_autosave();
567 558
568 559 // Detect if there exists an autosave newer than the post.
@@ -617,12 +608,8 @@
617 608
618 609 if ( $autosave_id ) {
619 610 $document = Plugin::$instance->documents->get( $autosave_id );
620 611 } elseif ( $create ) {
621 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
622 - require_once ABSPATH . 'wp-admin/includes/post.php';
623 - }
624 -
625 612 $autosave_id = wp_create_post_autosave( [
626 613 'post_ID' => $this->post->ID,
627 614 'post_type' => $this->post->post_type,
628 615 'post_title' => $this->post->post_title,
@@ -651,14 +638,14 @@
651 638 * Fired by `post_row_actions` and `page_row_actions` filters.
652 639 *
653 640 * @access public
654 641 *
655 - * @param array $actions An array of row action links.
642 + * @param array $actions An array of row action links.
656 643 *
657 644 * @return array An updated array of row action links.
658 645 */
659 646 public function filter_admin_row_actions( $actions ) {
660 - if ( $this->is_editable_with_elementor() ) {
647 + if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) {
661 648 $actions['edit_with_elementor'] = sprintf(
662 649 '<a href="%1$s">%2$s</a>',
663 650 $this->get_edit_url(),
664 651 __( 'Edit with Elementor', 'elementor' )
@@ -667,16 +654,8 @@
667 654
668 655 return $actions;
669 656 }
670 657
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 658 /**
680 659 * @since 2.0.0
681 660 * @access public
682 661 */
@@ -746,16 +725,19 @@
746 725
747 726 do_action( 'elementor/document/before_get_config', $this );
748 727
749 728 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();
729 + $container_config = [];
730 + $experiments_manager = Plugin::$instance->experiments;
754 731
732 + if ( $experiments_manager->is_feature_active( 'container' ) ) {
733 + $container_config = [
734 + 'container' => Plugin::$instance->elements_manager->get_element_types( 'container' )->get_config(),
735 + ];
736 + }
737 +
755 738 $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() );
739 + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config();
758 740 }
759 741
760 742 $additional_config = [];
761 743
@@ -853,9 +835,9 @@
853 835 */
854 836 do_action( 'elementor/document/before_save', $this, $data );
855 837
856 838 if ( ! current_user_can( 'unfiltered_html' ) ) {
857 - $data = Utils::kses_post_deep( $data );
839 + $data = wp_kses_post_deep( $data );
858 840 }
859 841
860 842 if ( ! empty( $data['settings'] ) ) {
861 843 if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
@@ -940,9 +922,9 @@
940 922 *
941 923 * @return bool Whether the post was built with Elementor.
942 924 */
943 925 public function is_built_with_elementor() {
944 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
926 + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
945 927 }
946 928
947 929 /**
948 930 * Mark the post as "built with elementor" or not.
@@ -1052,9 +1034,9 @@
1052 1034 return $meta;
1053 1035 }
1054 1036
1055 1037 public function update_json_meta( $key, $value ) {
1056 - return $this->update_meta(
1038 + $this->update_meta(
1057 1039 $key,
1058 1040 // `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1059 1041 wp_slash( wp_json_encode( $value ) )
1060 1042 );
@@ -1067,10 +1049,8 @@
1067 1049 * @param null $data
1068 1050 * @param bool $with_html_content
1069 1051 *
1070 1052 * @return array
1071 - *
1072 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1073 1053 */
1074 1054 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1075 1055 if ( ! static::get_property( 'has_elements' ) ) {
1076 1056 return [];
@@ -1079,23 +1059,8 @@
1079 1059 if ( is_null( $data ) ) {
1080 1060 $data = $this->get_elements_data();
1081 1061 }
1082 1062
1083 - /**
1084 - * Filters document elements data after loading.
1085 - *
1086 - * Allows modification of elements data when loading (not saving).
1087 - * Useful for migrations, transformations, or data enrichment.
1088 - *
1089 - * @since 3.35.0
1090 - *
1091 - * @param array $data The elements data array.
1092 - * @param \Elementor\Core\Base\Document $document The document instance.
1093 - */
1094 - if ( ! $this->is_saving ) {
1095 - $data = apply_filters( 'elementor/document/load/data', $data, $this );
1096 - }
1097 -
1098 1063 // Change the current documents, so widgets can use `documents->get_current` and other post data
1099 1064 Plugin::$instance->documents->switch_to_document( $this );
1100 1065
1101 1066 $editor_data = [];
@@ -1120,9 +1085,9 @@
1120 1085 $element_data = $element->get_raw_data( $with_html_content );
1121 1086 }
1122 1087
1123 1088 $editor_data[] = $element_data;
1124 - }
1089 + } // End foreach().
1125 1090
1126 1091 Plugin::$instance->documents->restore_document();
1127 1092
1128 1093 return $editor_data;
@@ -1136,9 +1101,9 @@
1136 1101 *
1137 1102 * @return array
1138 1103 */
1139 1104 public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1140 - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1105 + $elements = $this->get_json_meta( '_elementor_data' );
1141 1106
1142 1107 if ( self::STATUS_DRAFT === $status ) {
1143 1108 $autosave = $this->get_newer_autosave();
1144 1109
@@ -1144,9 +1109,9 @@
1144 1109
1145 1110 if ( is_object( $autosave ) ) {
1146 1111 $autosave_elements = Plugin::$instance->documents
1147 1112 ->get( $autosave->get_post()->ID )
1148 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1113 + ->get_json_meta( '_elementor_data' );
1149 1114 }
1150 1115 }
1151 1116
1152 1117 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1314,9 +1279,9 @@
1314 1279 * @param array|null $controls The available controls.
1315 1280 *
1316 1281 * @return array Element data.
1317 1282 */
1318 - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
1283 + public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array {
1319 1284 foreach ( $config as &$element_config ) {
1320 1285 $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1321 1286
1322 1287 if ( is_null( $element_instance ) ) {
@@ -1383,9 +1348,9 @@
1383 1348 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1384 1349 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1385 1350
1386 1351 // Don't use `update_post_meta` that can't handle `revision` post type
1387 - $is_meta_updated = update_metadata( 'post', $this->post->ID, self::ELEMENTOR_DATA_META_KEY, $json_value );
1352 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1388 1353
1389 1354 /**
1390 1355 * Before saving data.
1391 1356 *
@@ -1453,8 +1418,9 @@
1453 1418 *
1454 1419 * @since 2.5.12
1455 1420 *
1456 1421 * @param \Elementor\Core\Base\Document $this The current document.
1422 + *
1457 1423 */
1458 1424 do_action( 'elementor/document/save_version', $this );
1459 1425 }
1460 1426 }
@@ -1491,9 +1457,9 @@
1491 1457 * @since 2.0.4
1492 1458 * @access public
1493 1459 *
1494 1460 * @param string $key Meta data key.
1495 - * @param mixed $value Meta data value.
1461 + * @param mixed $value Meta data value.
1496 1462 *
1497 1463 * @return bool|int
1498 1464 */
1499 1465 public function update_main_meta( $key, $value ) {
@@ -1621,9 +1587,9 @@
1621 1587 } else {
1622 1588 $this->post = get_post( $data['post_id'] );
1623 1589
1624 1590 if ( ! $this->post ) {
1625 - throw new \Exception( sprintf( 'Post ID #%s does not exist.', esc_html( $data['post_id'] ) ), Exceptions::NOT_FOUND ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
1591 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1626 1592 }
1627 1593 }
1628 1594
1629 1595 // Each Control_Stack is based on a unique ID.
@@ -1641,9 +1607,9 @@
1641 1607
1642 1608 parent::__construct( $data );
1643 1609 }
1644 1610
1645 - /**
1611 + /*
1646 1612 * Get Export Data
1647 1613 *
1648 1614 * Filters a document's data on export
1649 1615 *
@@ -1655,10 +1621,8 @@
1655 1621 public function get_export_data() {
1656 1622 $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1657 1623 $element_data['id'] = Utils::generate_random_string();
1658 1624
1659 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1660 -
1661 1625 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1662 1626
1663 1627 // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1664 1628 if ( ! $element ) {
@@ -1682,9 +1646,9 @@
1682 1646 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1683 1647 ];
1684 1648 }
1685 1649
1686 - /**
1650 + /*
1687 1651 * Get Import Data
1688 1652 *
1689 1653 * Filters a document's data on import
1690 1654 *
@@ -1828,25 +1792,14 @@
1828 1792 }
1829 1793
1830 1794 /**
1831 1795 * @since 2.1.3
1832 - * @access public
1796 + * @access protected
1833 1797 */
1834 - public function print_elements( $elements_data ) {
1835 - $is_element_cache_active = 'disable' !== get_option( 'elementor_element_cache_ttl', '' );
1836 - if ( ! $is_element_cache_active ) {
1837 - ob_start();
1838 -
1798 + protected function print_elements( $elements_data ) {
1799 + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) {
1839 1800 $this->do_print_elements( $elements_data );
1840 1801
1841 - $content = ob_get_clean();
1842 -
1843 - if ( has_blocks( $content ) ) {
1844 - $content = do_blocks( $content );
1845 - }
1846 -
1847 - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1848 -
1849 1802 return;
1850 1803 }
1851 1804
1852 1805 $cached_data = $this->get_document_cache();
@@ -1899,21 +1852,20 @@
1899 1852 }
1900 1853 }
1901 1854
1902 1855 if ( ! empty( $cached_data['content'] ) ) {
1903 - $content = do_shortcode( $cached_data['content'] );
1904 -
1905 - if ( has_blocks( $content ) ) {
1906 - $content = do_blocks( $content );
1907 - }
1908 -
1909 - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1856 + echo do_shortcode( $cached_data['content'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1910 1857 }
1911 1858 }
1912 1859
1913 1860 protected function do_print_elements( $elements_data ) {
1914 - $this->update_runtime_elements( $elements_data );
1861 + // Collect all data updaters that should be updated on runtime.
1862 + $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions();
1915 1863
1864 + if ( $runtime_elements_iteration_actions ) {
1865 + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1866 + }
1867 +
1916 1868 foreach ( $elements_data as $element_data ) {
1917 1869 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1918 1870
1919 1871 if ( ! $element ) {
@@ -1923,21 +1875,8 @@
1923 1875 $element->print_element();
1924 1876 }
1925 1877 }
1926 1878
1927 - public function update_runtime_elements( $elements_data = null ) {
1928 - if ( null === $elements_data ) {
1929 - $elements_data = $this->get_elements_data();
1930 - }
1931 -
1932 - // Collect all data updaters that should be updated on runtime.
1933 - $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions();
1934 -
1935 - if ( $runtime_elements_iteration_actions ) {
1936 - $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1937 - }
1938 - }
1939 -
1940 1879 public function set_document_cache( $value ) {
1941 1880 $expiration_hours = get_option( 'elementor_element_cache_ttl', '' );
1942 1881
1943 1882 if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) {
@@ -2122,10 +2061,6 @@
2122 2061 $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2123 2062 }
2124 2063
2125 2064 return $this->elements_iteration_actions;
2126 - }
2127 -
2128 - public function get_elementor_version() {
2129 - return $this->get_main_meta( '_elementor_version' );
2130 2065 }
2131 2066 }