PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.8
Elementor Website Builder – more than just a page builder v3.24.8
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 +36 -86 4.1.0-dev33.24.8 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,9 +39,8 @@
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';
@@ -550,10 +548,12 @@
550 548 *
551 549 * @since 2.0.0
552 550 * @access public
553 551 *
552 + *
554 553 * @return bool|Document
555 554 */
555 +
556 556 public function get_newer_autosave() {
557 557 $autosave = $this->get_autosave();
558 558
559 559 // Detect if there exists an autosave newer than the post.
@@ -608,12 +608,8 @@
608 608
609 609 if ( $autosave_id ) {
610 610 $document = Plugin::$instance->documents->get( $autosave_id );
611 611 } elseif ( $create ) {
612 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
613 - require_once ABSPATH . 'wp-admin/includes/post.php';
614 - }
615 -
616 612 $autosave_id = wp_create_post_autosave( [
617 613 'post_ID' => $this->post->ID,
618 614 'post_type' => $this->post->post_type,
619 615 'post_title' => $this->post->post_title,
@@ -642,9 +638,9 @@
642 638 * Fired by `post_row_actions` and `page_row_actions` filters.
643 639 *
644 640 * @access public
645 641 *
646 - * @param array $actions An array of row action links.
642 + * @param array $actions An array of row action links.
647 643 *
648 644 * @return array An updated array of row action links.
649 645 */
650 646 public function filter_admin_row_actions( $actions ) {
@@ -729,16 +725,19 @@
729 725
730 726 do_action( 'elementor/document/before_get_config', $this );
731 727
732 728 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();
729 + $container_config = [];
730 + $experiments_manager = Plugin::$instance->experiments;
737 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 +
738 738 $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() );
739 + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config();
741 740 }
742 741
743 742 $additional_config = [];
744 743
@@ -836,11 +835,9 @@
836 835 */
837 836 do_action( 'elementor/document/before_save', $this, $data );
838 837
839 838 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 - } );
839 + $data = wp_kses_post_deep( $data );
843 840 }
844 841
845 842 if ( ! empty( $data['settings'] ) ) {
846 843 if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
@@ -925,9 +922,9 @@
925 922 *
926 923 * @return bool Whether the post was built with Elementor.
927 924 */
928 925 public function is_built_with_elementor() {
929 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
926 + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
930 927 }
931 928
932 929 /**
933 930 * Mark the post as "built with elementor" or not.
@@ -1037,9 +1034,9 @@
1037 1034 return $meta;
1038 1035 }
1039 1036
1040 1037 public function update_json_meta( $key, $value ) {
1041 - return $this->update_meta(
1038 + $this->update_meta(
1042 1039 $key,
1043 1040 // `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1044 1041 wp_slash( wp_json_encode( $value ) )
1045 1042 );
@@ -1052,10 +1049,8 @@
1052 1049 * @param null $data
1053 1050 * @param bool $with_html_content
1054 1051 *
1055 1052 * @return array
1056 - *
1057 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1058 1053 */
1059 1054 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1060 1055 if ( ! static::get_property( 'has_elements' ) ) {
1061 1056 return [];
@@ -1064,23 +1059,8 @@
1064 1059 if ( is_null( $data ) ) {
1065 1060 $data = $this->get_elements_data();
1066 1061 }
1067 1062
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 1063 // Change the current documents, so widgets can use `documents->get_current` and other post data
1084 1064 Plugin::$instance->documents->switch_to_document( $this );
1085 1065
1086 1066 $editor_data = [];
@@ -1105,9 +1085,9 @@
1105 1085 $element_data = $element->get_raw_data( $with_html_content );
1106 1086 }
1107 1087
1108 1088 $editor_data[] = $element_data;
1109 - }
1089 + } // End foreach().
1110 1090
1111 1091 Plugin::$instance->documents->restore_document();
1112 1092
1113 1093 return $editor_data;
@@ -1121,9 +1101,9 @@
1121 1101 *
1122 1102 * @return array
1123 1103 */
1124 1104 public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1125 - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1105 + $elements = $this->get_json_meta( '_elementor_data' );
1126 1106
1127 1107 if ( self::STATUS_DRAFT === $status ) {
1128 1108 $autosave = $this->get_newer_autosave();
1129 1109
@@ -1129,9 +1109,9 @@
1129 1109
1130 1110 if ( is_object( $autosave ) ) {
1131 1111 $autosave_elements = Plugin::$instance->documents
1132 1112 ->get( $autosave->get_post()->ID )
1133 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1113 + ->get_json_meta( '_elementor_data' );
1134 1114 }
1135 1115 }
1136 1116
1137 1117 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1299,9 +1279,9 @@
1299 1279 * @param array|null $controls The available controls.
1300 1280 *
1301 1281 * @return array Element data.
1302 1282 */
1303 - 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 {
1304 1284 foreach ( $config as &$element_config ) {
1305 1285 $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1306 1286
1307 1287 if ( is_null( $element_instance ) ) {
@@ -1368,9 +1348,9 @@
1368 1348 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1369 1349 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1370 1350
1371 1351 // 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 );
1352 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1373 1353
1374 1354 /**
1375 1355 * Before saving data.
1376 1356 *
@@ -1438,8 +1418,9 @@
1438 1418 *
1439 1419 * @since 2.5.12
1440 1420 *
1441 1421 * @param \Elementor\Core\Base\Document $this The current document.
1422 + *
1442 1423 */
1443 1424 do_action( 'elementor/document/save_version', $this );
1444 1425 }
1445 1426 }
@@ -1476,9 +1457,9 @@
1476 1457 * @since 2.0.4
1477 1458 * @access public
1478 1459 *
1479 1460 * @param string $key Meta data key.
1480 - * @param mixed $value Meta data value.
1461 + * @param mixed $value Meta data value.
1481 1462 *
1482 1463 * @return bool|int
1483 1464 */
1484 1465 public function update_main_meta( $key, $value ) {
@@ -1606,9 +1587,9 @@
1606 1587 } else {
1607 1588 $this->post = get_post( $data['post_id'] );
1608 1589
1609 1590 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
1591 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1611 1592 }
1612 1593 }
1613 1594
1614 1595 // Each Control_Stack is based on a unique ID.
@@ -1626,9 +1607,9 @@
1626 1607
1627 1608 parent::__construct( $data );
1628 1609 }
1629 1610
1630 - /**
1611 + /*
1631 1612 * Get Export Data
1632 1613 *
1633 1614 * Filters a document's data on export
1634 1615 *
@@ -1640,10 +1621,8 @@
1640 1621 public function get_export_data() {
1641 1622 $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1642 1623 $element_data['id'] = Utils::generate_random_string();
1643 1624
1644 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1645 -
1646 1625 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1647 1626
1648 1627 // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1649 1628 if ( ! $element ) {
@@ -1667,9 +1646,9 @@
1667 1646 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1668 1647 ];
1669 1648 }
1670 1649
1671 - /**
1650 + /*
1672 1651 * Get Import Data
1673 1652 *
1674 1653 * Filters a document's data on import
1675 1654 *
@@ -1813,25 +1792,14 @@
1813 1792 }
1814 1793
1815 1794 /**
1816 1795 * @since 2.1.3
1817 - * @access public
1796 + * @access protected
1818 1797 */
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 -
1798 + protected function print_elements( $elements_data ) {
1799 + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) {
1824 1800 $this->do_print_elements( $elements_data );
1825 1801
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 1802 return;
1835 1803 }
1836 1804
1837 1805 $cached_data = $this->get_document_cache();
@@ -1884,21 +1852,20 @@
1884 1852 }
1885 1853 }
1886 1854
1887 1855 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
1856 + echo do_shortcode( $cached_data['content'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1895 1857 }
1896 1858 }
1897 1859
1898 1860 protected function do_print_elements( $elements_data ) {
1899 - $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();
1900 1863
1864 + if ( $runtime_elements_iteration_actions ) {
1865 + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1866 + }
1867 +
1901 1868 foreach ( $elements_data as $element_data ) {
1902 1869 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1903 1870
1904 1871 if ( ! $element ) {
@@ -1908,21 +1875,8 @@
1908 1875 $element->print_element();
1909 1876 }
1910 1877 }
1911 1878
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 1879 public function set_document_cache( $value ) {
1926 1880 $expiration_hours = get_option( 'elementor_element_cache_ttl', '' );
1927 1881
1928 1882 if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) {
@@ -2107,10 +2061,6 @@
2107 2061 $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2108 2062 }
2109 2063
2110 2064 return $this->elements_iteration_actions;
2111 - }
2112 -
2113 - public function get_elementor_version() {
2114 - return $this->get_main_meta( '_elementor_version' );
2115 2065 }
2116 2066 }