PluginProbe
Elementor Website Builder – more than just a page builder / 3.21.3
Elementor Website Builder – more than just a page builder v3.21.3
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 +34 -235 4.2.03.21.3 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,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 - const UNEDITABLE_WITH_ELEMENTOR_TYPES = [ 'kit' ];
51 -
52 46 /**
53 47 * Document publish status.
54 48 */
55 49 const STATUS_PUBLISH = 'publish';
@@ -166,15 +160,8 @@
166 160 'edit_capability' => '',
167 161 'show_in_finder' => true,
168 162 'show_on_admin_bar' => true,
169 163 'support_kit' => false,
170 - 'show_navigator' => true,
171 - 'allow_adding_widgets' => true,
172 - '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 164 ];
178 165 }
179 166
180 167 /**
@@ -202,14 +189,8 @@
202 189 esc_html__( 'Hurray! Your %s is live.', 'elementor' ),
203 190 static::get_title()
204 191 ),
205 192 ],
206 - 'show_navigator' => static::get_property( 'show_navigator' ),
207 - '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 193 ];
213 194 }
214 195
215 196 public static function get_filtered_editor_panel_categories(): array {
@@ -232,16 +213,9 @@
232 213 *
233 214 * @return array
234 215 */
235 216 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 ) {
217 + if ( ! $has_pro ) {
244 218 $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data(
245 219 $promotion,
246 220 'elementor/panel/' . $index . '/custom_promotion',
247 221 'url'
@@ -559,10 +533,12 @@
559 533 *
560 534 * @since 2.0.0
561 535 * @access public
562 536 *
537 + *
563 538 * @return bool|Document
564 539 */
540 +
565 541 public function get_newer_autosave() {
566 542 $autosave = $this->get_autosave();
567 543
568 544 // Detect if there exists an autosave newer than the post.
@@ -617,12 +593,8 @@
617 593
618 594 if ( $autosave_id ) {
619 595 $document = Plugin::$instance->documents->get( $autosave_id );
620 596 } elseif ( $create ) {
621 - if ( ! function_exists( 'wp_create_post_autosave' ) ) {
622 - require_once ABSPATH . 'wp-admin/includes/post.php';
623 - }
624 -
625 597 $autosave_id = wp_create_post_autosave( [
626 598 'post_ID' => $this->post->ID,
627 599 'post_type' => $this->post->post_type,
628 600 'post_title' => $this->post->post_title,
@@ -651,14 +623,14 @@
651 623 * Fired by `post_row_actions` and `page_row_actions` filters.
652 624 *
653 625 * @access public
654 626 *
655 - * @param array $actions An array of row action links.
627 + * @param array $actions An array of row action links.
656 628 *
657 629 * @return array An updated array of row action links.
658 630 */
659 631 public function filter_admin_row_actions( $actions ) {
660 - if ( $this->is_editable_with_elementor() ) {
632 + if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) {
661 633 $actions['edit_with_elementor'] = sprintf(
662 634 '<a href="%1$s">%2$s</a>',
663 635 $this->get_edit_url(),
664 636 __( 'Edit with Elementor', 'elementor' )
@@ -667,16 +639,8 @@
667 639
668 640 return $actions;
669 641 }
670 642
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 643 /**
680 644 * @since 2.0.0
681 645 * @access public
682 646 */
@@ -746,16 +710,19 @@
746 710
747 711 do_action( 'elementor/document/before_get_config', $this );
748 712
749 713 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();
714 + $container_config = [];
715 + $experiments_manager = Plugin::$instance->experiments;
754 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 +
755 723 $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() );
724 + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config();
758 725 }
759 726
760 727 $additional_config = [];
761 728
@@ -853,11 +820,9 @@
853 820 */
854 821 do_action( 'elementor/document/before_save', $this, $data );
855 822
856 823 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 - } );
824 + $data = wp_kses_post_deep( $data );
860 825 }
861 826
862 827 if ( ! empty( $data['settings'] ) ) {
863 828 if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
@@ -884,11 +849,8 @@
884 849 $post_css = Post_CSS::create( $this->post->ID );
885 850
886 851 $post_css->delete();
887 852
888 - // Remove Document Cache
889 - $this->delete_cache();
890 -
891 853 /**
892 854 * After document save.
893 855 *
894 856 * Fires when document save is complete.
@@ -942,9 +904,9 @@
942 904 *
943 905 * @return bool Whether the post was built with Elementor.
944 906 */
945 907 public function is_built_with_elementor() {
946 - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
908 + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY );
947 909 }
948 910
949 911 /**
950 912 * Mark the post as "built with elementor" or not.
@@ -1054,9 +1016,9 @@
1054 1016 return $meta;
1055 1017 }
1056 1018
1057 1019 public function update_json_meta( $key, $value ) {
1058 - return $this->update_meta(
1020 + $this->update_meta(
1059 1021 $key,
1060 1022 // `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1061 1023 wp_slash( wp_json_encode( $value ) )
1062 1024 );
@@ -1069,10 +1031,8 @@
1069 1031 * @param null $data
1070 1032 * @param bool $with_html_content
1071 1033 *
1072 1034 * @return array
1073 - *
1074 - * @throws \Exception If elements retrieval fails or data processing errors occur.
1075 1035 */
1076 1036 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
1077 1037 if ( ! static::get_property( 'has_elements' ) ) {
1078 1038 return [];
@@ -1081,23 +1041,8 @@
1081 1041 if ( is_null( $data ) ) {
1082 1042 $data = $this->get_elements_data();
1083 1043 }
1084 1044
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 1045 // Change the current documents, so widgets can use `documents->get_current` and other post data
1101 1046 Plugin::$instance->documents->switch_to_document( $this );
1102 1047
1103 1048 $editor_data = [];
@@ -1122,9 +1067,9 @@
1122 1067 $element_data = $element->get_raw_data( $with_html_content );
1123 1068 }
1124 1069
1125 1070 $editor_data[] = $element_data;
1126 - }
1071 + } // End foreach().
1127 1072
1128 1073 Plugin::$instance->documents->restore_document();
1129 1074
1130 1075 return $editor_data;
@@ -1138,9 +1083,9 @@
1138 1083 *
1139 1084 * @return array
1140 1085 */
1141 1086 public function get_elements_data( $status = self::STATUS_PUBLISH ) {
1142 - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1087 + $elements = $this->get_json_meta( '_elementor_data' );
1143 1088
1144 1089 if ( self::STATUS_DRAFT === $status ) {
1145 1090 $autosave = $this->get_newer_autosave();
1146 1091
@@ -1146,9 +1091,9 @@
1146 1091
1147 1092 if ( is_object( $autosave ) ) {
1148 1093 $autosave_elements = Plugin::$instance->documents
1149 1094 ->get( $autosave->get_post()->ID )
1150 - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY );
1095 + ->get_json_meta( '_elementor_data' );
1151 1096 }
1152 1097 }
1153 1098
1154 1099 if ( Plugin::$instance->editor->is_edit_mode() ) {
@@ -1316,9 +1261,9 @@
1316 1261 * @param array|null $controls The available controls.
1317 1262 *
1318 1263 * @return array Element data.
1319 1264 */
1320 - 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 {
1321 1266 foreach ( $config as &$element_config ) {
1322 1267 $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config );
1323 1268
1324 1269 if ( is_null( $element_instance ) ) {
@@ -1385,9 +1330,9 @@
1385 1330 // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta`
1386 1331 $json_value = wp_slash( wp_json_encode( $editor_data ) );
1387 1332
1388 1333 // 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 );
1334 + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value );
1390 1335
1391 1336 /**
1392 1337 * Before saving data.
1393 1338 *
@@ -1455,8 +1400,9 @@
1455 1400 *
1456 1401 * @since 2.5.12
1457 1402 *
1458 1403 * @param \Elementor\Core\Base\Document $this The current document.
1404 + *
1459 1405 */
1460 1406 do_action( 'elementor/document/save_version', $this );
1461 1407 }
1462 1408 }
@@ -1493,9 +1439,9 @@
1493 1439 * @since 2.0.4
1494 1440 * @access public
1495 1441 *
1496 1442 * @param string $key Meta data key.
1497 - * @param mixed $value Meta data value.
1443 + * @param string $value Meta data value.
1498 1444 *
1499 1445 * @return bool|int
1500 1446 */
1501 1447 public function update_main_meta( $key, $value ) {
@@ -1623,9 +1569,9 @@
1623 1569 } else {
1624 1570 $this->post = get_post( $data['post_id'] );
1625 1571
1626 1572 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
1573 + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND );
1628 1574 }
1629 1575 }
1630 1576
1631 1577 // Each Control_Stack is based on a unique ID.
@@ -1643,9 +1589,9 @@
1643 1589
1644 1590 parent::__construct( $data );
1645 1591 }
1646 1592
1647 - /**
1593 + /*
1648 1594 * Get Export Data
1649 1595 *
1650 1596 * Filters a document's data on export
1651 1597 *
@@ -1657,10 +1603,8 @@
1657 1603 public function get_export_data() {
1658 1604 $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) {
1659 1605 $element_data['id'] = Utils::generate_random_string();
1660 1606
1661 - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data );
1662 -
1663 1607 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1664 1608
1665 1609 // If the widget/element does not exist, like a plugin that creates a widget but deactivated.
1666 1610 if ( ! $element ) {
@@ -1684,9 +1628,9 @@
1684 1628 'thumbnail' => get_the_post_thumbnail_url( $this->post ),
1685 1629 ];
1686 1630 }
1687 1631
1688 - /**
1632 + /*
1689 1633 * Get Import Data
1690 1634 *
1691 1635 * Filters a document's data on import
1692 1636 *
@@ -1830,92 +1774,18 @@
1830 1774 }
1831 1775
1832 1776 /**
1833 1777 * @since 2.1.3
1834 - * @access public
1778 + * @access protected
1835 1779 */
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();
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();
1840 1783
1841 - $this->do_print_elements( $elements_data );
1842 -
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 - return;
1784 + if ( $runtime_elements_iteration_actions ) {
1785 + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' );
1852 1786 }
1853 1787
1854 - $cached_data = $this->get_document_cache();
1855 -
1856 - if ( false === $cached_data ) {
1857 - add_filter( 'elementor/element/should_render_shortcode', '__return_true' );
1858 -
1859 - $scripts_to_queue = [];
1860 - $styles_to_queue = [];
1861 -
1862 - global $wp_scripts, $wp_styles;
1863 -
1864 - $should_store_scripts = $wp_scripts instanceof \WP_Scripts && $wp_styles instanceof \WP_Styles;
1865 - if ( $should_store_scripts ) {
1866 - $scripts_ignored = $wp_scripts->queue;
1867 - $styles_ignored = $wp_styles->queue;
1868 - }
1869 -
1870 - ob_start();
1871 -
1872 - $this->do_print_elements( $elements_data );
1873 -
1874 - if ( $should_store_scripts ) {
1875 - $scripts_to_queue = array_values( array_diff( $wp_scripts->queue, $scripts_ignored ) );
1876 - $styles_to_queue = array_values( array_diff( $wp_styles->queue, $styles_ignored ) );
1877 - }
1878 -
1879 - $cached_data = [
1880 - 'content' => ob_get_clean(),
1881 - 'scripts' => $scripts_to_queue,
1882 - 'styles' => $styles_to_queue,
1883 - ];
1884 -
1885 - if ( $this->should_store_cache_elements() ) {
1886 - $this->set_document_cache( $cached_data );
1887 - }
1888 -
1889 - remove_filter( 'elementor/element/should_render_shortcode', '__return_true' );
1890 - } else {
1891 - if ( ! empty( $cached_data['scripts'] ) ) {
1892 - foreach ( $cached_data['scripts'] as $script_handle ) {
1893 - wp_enqueue_script( $script_handle );
1894 - }
1895 - }
1896 -
1897 - if ( ! empty( $cached_data['styles'] ) ) {
1898 - foreach ( $cached_data['styles'] as $style_handle ) {
1899 - wp_enqueue_style( $style_handle );
1900 - }
1901 - }
1902 - }
1903 -
1904 - 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
1912 - }
1913 - }
1914 -
1915 - protected function do_print_elements( $elements_data ) {
1916 - $this->update_runtime_elements( $elements_data );
1917 -
1918 1788 foreach ( $elements_data as $element_data ) {
1919 1789 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
1920 1790
1921 1791 if ( ! $element ) {
@@ -1925,75 +1795,8 @@
1925 1795 $element->print_element();
1926 1796 }
1927 1797 }
1928 1798
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 - public function set_document_cache( $value ) {
1943 - $expiration_hours = get_option( 'elementor_element_cache_ttl', '' );
1944 -
1945 - if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) {
1946 - $expiration_hours = '24';
1947 - }
1948 -
1949 - $expiration_hours = absint( $expiration_hours );
1950 -
1951 - $expiration = '+' . $expiration_hours . ' hours';
1952 -
1953 - $data = [
1954 - 'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ),
1955 - 'value' => $value,
1956 - ];
1957 -
1958 - $this->update_json_meta( static::CACHE_META_KEY, $data );
1959 - }
1960 -
1961 - private function get_document_cache() {
1962 - $cache = $this->get_json_meta( static::CACHE_META_KEY );
1963 -
1964 - if ( empty( $cache['timeout'] ) ) {
1965 - return false;
1966 - }
1967 -
1968 - if ( current_time( 'timestamp' ) > $cache['timeout'] ) {
1969 - return false;
1970 - }
1971 -
1972 - if ( ! is_array( $cache['value'] ) ) {
1973 - return false;
1974 - }
1975 -
1976 - return $cache['value'];
1977 - }
1978 -
1979 - protected function delete_cache() {
1980 - $this->delete_meta( static::CACHE_META_KEY );
1981 - }
1982 -
1983 - private function should_store_cache_elements() {
1984 - static $should_store_cache_elements = null;
1985 -
1986 - if ( null === $should_store_cache_elements ) {
1987 - $should_store_cache_elements = (
1988 - ! is_admin()
1989 - && ! Plugin::$instance->preview->is_preview_mode()
1990 - );
1991 - }
1992 -
1993 - return $should_store_cache_elements;
1994 - }
1995 -
1996 1799 protected function register_document_controls() {
1997 1800 $this->start_controls_section(
1998 1801 'document_settings',
1999 1802 [
@@ -2124,10 +1927,6 @@
2124 1927 $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this );
2125 1928 }
2126 1929
2127 1930 return $this->elements_iteration_actions;
2128 - }
2129 -
2130 - public function get_elementor_version() {
2131 - return $this->get_main_meta( '_elementor_version' );
2132 1931 }
2133 1932 }