PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.0-dev3
Elementor Website Builder – more than just a page builder v3.20.0-dev3
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 +32 -216 4.0.73.20.0-dev3 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,14 +39,11 @@
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 - const CACHE_META_KEY = '_elementor_element_cache';
49 -
50 46 /**
51 47 * Document publish status.
52 48 */
53 49 const STATUS_PUBLISH = 'publish';
@@ -164,15 +160,8 @@
164 160 'edit_capability' => '',
165 161 'show_in_finder' => true,
166 162 'show_on_admin_bar' => true,
167 163 '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 164 ];
176 165 }
177 166
178 167 /**
@@ -200,14 +189,8 @@
200 189 esc_html__( 'Hurray! Your %s is live.', 'elementor' ),
201 190 static::get_title()
202 191 ),
203 192 ],
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 193 ];
211 194 }
212 195
213 196 public static function get_filtered_editor_panel_categories(): array {
@@ -550,10 +533,12 @@
550 533 *
551 534 * @since 2.0.0
552 535 * @access public
553 536 *
537 + *
554 538 * @return bool|Document
555 539 */
540 +
556 541 public function get_newer_autosave() {
557 542 $autosave = $this->get_autosave();
558 543
559 544 // Detect if there exists an autosave newer than the post.
@@ -608,12 +593,8 @@
608 593
609 594 if ( $autosave_id ) {
610 595 $document = Plugin::$instance->documents->get( $autosave_id );
611 596 } elseif ( $create ) {
612 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
613 - require_once ABSPATH . 'wp-admin/includes/post.php';
614 - }
615 -
616 597 $autosave_id = wp_create_post_autosave( [
617 598 'post_ID' => $this->post->ID,
618 599 'post_type' => $this->post->post_type,
619 600 'post_title' => $this->post->post_title,
@@ -642,9 +623,9 @@
642 623 * Fired by `post_row_actions` and `page_row_actions` filters.
643 624 *
644 625 * @access public
645 626 *
646 - * @param array $actions An array of row action links.
627 + * @param array $actions An array of row action links.
647 628 *
648 629 * @return array An updated array of row action links.
649 630 */
650 631 public function filter_admin_row_actions( $actions ) {
@@ -729,16 +710,19 @@
729 710
730 711 do_action( 'elementor/document/before_get_config', $this );
731 712
732 713 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();
714 + $container_config = [];
715 + $experiments_manager = Plugin::$instance->experiments;
737 716
717 + if ( $experiments_manager->is_feature_active( 'container' ) ) {
718 + $container_config = [
719 + 'container' => Plugin::$instance->elements_manager->get_element_types( 'container' )->get_config(),
720 + ];
721 + }
722 +
738 723 $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() );
724 + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config();
741 725 }
742 726
743 727 $additional_config = [];
744 728
@@ -836,11 +820,9 @@
836 820 */
837 821 do_action( 'elementor/document/before_save', $this, $data );
838 822
839 823 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 - } );
824 + $data = wp_kses_post_deep( $data );
843 825 }
844 826
845 827 if ( ! empty( $data['settings'] ) ) {
846 828 if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
@@ -867,11 +849,8 @@
867 849 $post_css = Post_CSS::create( $this->post->ID );
868 850
869 851 $post_css->delete();
870 852
871 - // Remove Document Cache
872 - $this->delete_cache();
873 -
874 853 /**
875 854 * After document save.
876 855 *
877 856 * Fires when document save is complete.
@@ -925,9 +904,9 @@
925 904 *
926 905 * @return bool Whether the post was built with Elementor.
927 906 */
928 907 public function is_built_with_elementor() {
929 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
908 + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
930 909 }
931 910
932 911 /**
933 912 * Mark the post as "built with elementor" or not.
@@ -1037,9 +1016,9 @@
1037 1016 return $meta;
1038 1017 }
1039 1018
1040 1019 public function update_json_meta( $key, $value ) {
1041 - return $this->update_meta(
1020 + $this->update_meta(
1042 1021 $key,
1043 1022 // `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1044 1023 wp_slash( wp_json_encode( $value ) )
1045 1024 );
@@ -1052,10 +1031,8 @@
1052 1031 * @param null $data
1053 1032 * @param bool $with_html_content
1054 1033 *
1055 1034 * @return array
1056 - *
1057 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1058 1035 */
1059 1036 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1060 1037 if ( ! static::get_property( 'has_elements' ) ) {
1061 1038 return [];
@@ -1064,23 +1041,8 @@
1064 1041 if ( is_null( $data ) ) {
1065 1042 $data = $this->get_elements_data();
1066 1043 }
1067 1044
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 1045 // Change the current documents, so widgets can use `documents->get_current` and other post data
1084 1046 Plugin::$instance->documents->switch_to_document( $this );
1085 1047
1086 1048 $editor_data = [];
@@ -1105,9 +1067,9 @@
1105 1067 $element_data = $element->get_raw_data( $with_html_content );
1106 1068 }
1107 1069
1108 1070 $editor_data[] = $element_data;
1109 - }
1071 + } // End foreach().
1110 1072
1111 1073 Plugin::$instance->documents->restore_document();
1112 1074
1113 1075 return $editor_data;
@@ -1121,9 +1083,9 @@
1121 1083 *
1122 1084 * @return array
1123 1085 */
1124 1086 public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1125 - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1087 + $elements = $this->get_json_meta( '_elementor_data' );
1126 1088
1127 1089 if ( self::STATUS_DRAFT === $status ) {
1128 1090 $autosave = $this->get_newer_autosave();
1129 1091
@@ -1129,9 +1091,9 @@
1129 1091
1130 1092 if ( is_object( $autosave ) ) {
1131 1093 $autosave_elements = Plugin::$instance->documents
1132 1094 ->get( $autosave->get_post()->ID )
1133 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1095 + ->get_json_meta( '_elementor_data' );
1134 1096 }
1135 1097 }
1136 1098
1137 1099 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1299,9 +1261,9 @@
1299 1261 * @param array|null $controls The available controls.
1300 1262 *
1301 1263 * @return array Element data.
1302 1264 */
1303 - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
1265 + public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array {
1304 1266 foreach ( $config as &$element_config ) {
1305 1267 $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1306 1268
1307 1269 if ( is_null( $element_instance ) ) {
@@ -1368,9 +1330,9 @@
1368 1330 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1369 1331 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1370 1332
1371 1333 // 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 );
1334 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1373 1335
1374 1336 /**
1375 1337 * Before saving data.
1376 1338 *
@@ -1438,8 +1400,9 @@
1438 1400 *
1439 1401 * @since 2.5.12
1440 1402 *
1441 1403 * @param \Elementor\Core\Base\Document $this The current document.
1404 + *
1442 1405 */
1443 1406 do_action( 'elementor/document/save_version', $this );
1444 1407 }
1445 1408 }
@@ -1476,9 +1439,9 @@
1476 1439 * @since 2.0.4
1477 1440 * @access public
1478 1441 *
1479 1442 * @param string $key Meta data key.
1480 - * @param mixed $value Meta data value.
1443 + * @param string $value Meta data value.
1481 1444 *
1482 1445 * @return bool|int
1483 1446 */
1484 1447 public function update_main_meta( $key, $value ) {
@@ -1606,9 +1569,9 @@
1606 1569 } else {
1607 1570 $this->post = get_post( $data['post_id'] );
1608 1571
1609 1572 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
1573 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1611 1574 }
1612 1575 }
1613 1576
1614 1577 // Each Control_Stack is based on a unique ID.
@@ -1626,9 +1589,9 @@
1626 1589
1627 1590 parent::__construct( $data );
1628 1591 }
1629 1592
1630 - /**
1593 + /*
1631 1594 * Get Export Data
1632 1595 *
1633 1596 * Filters a document's data on export
1634 1597 *
@@ -1640,10 +1603,8 @@
1640 1603 public function get_export_data() {
1641 1604 $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1642 1605 $element_data['id'] = Utils::generate_random_string();
1643 1606
1644 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1645 -
1646 1607 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1647 1608
1648 1609 // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1649 1610 if ( ! $element ) {
@@ -1667,9 +1628,9 @@
1667 1628 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1668 1629 ];
1669 1630 }
1670 1631
1671 - /**
1632 + /*
1672 1633 * Get Import Data
1673 1634 *
1674 1635 * Filters a document's data on import
1675 1636 *
@@ -1813,92 +1774,18 @@
1813 1774 }
1814 1775
1815 1776 /**
1816 1777 * @since 2.1.3
1817 - * @access public
1778 + * @access protected
1818 1779 */
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();
1780 + protected function print_elements( $elements_data ) {
1781 + // Collect all data updaters that should be updated on runtime.
1782 + $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions();
1823 1783
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;
1784 + if ( $runtime_elements_iteration_actions ) {
1785 + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1835 1786 }
1836 1787
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 -
1901 1788 foreach ( $elements_data as $element_data ) {
1902 1789 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1903 1790
1904 1791 if ( ! $element ) {
@@ -1908,75 +1795,8 @@
1908 1795 $element->print_element();
1909 1796 }
1910 1797 }
1911 1798
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 1799 protected function register_document_controls() {
1980 1800 $this->start_controls_section(
1981 1801 'document_settings',
1982 1802 [
@@ -2107,10 +1927,6 @@
2107 1927 $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2108 1928 }
2109 1929
2110 1930 return $this->elements_iteration_actions;
2111 - }
2112 -
2113 - public function get_elementor_version() {
2114 - return $this->get_main_meta( '_elementor_version' );
2115 1931 }
2116 1932 }