| @@ -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'; |
| @@ -167,12 +165,8 @@ | ||
| 167 | 165 | 'support_kit' => false, |
| 168 | 166 | 'show_navigator' => true, |
| 169 | 167 | 'allow_adding_widgets' => true, |
| 170 | 168 | '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 | 169 | ]; |
| 176 | 170 | } |
| 177 | 171 | |
| 178 | 172 | /** |
| @@ -202,12 +196,8 @@ | ||
| 202 | 196 | ), |
| 203 | 197 | ], |
| 204 | 198 | 'show_navigator' => static::get_property( 'show_navigator' ), |
| 205 | 199 | '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 | 200 | ]; |
| 211 | 201 | } |
| 212 | 202 | |
| 213 | 203 | public static function get_filtered_editor_panel_categories(): array { |
| @@ -550,10 +540,12 @@ | ||
| 550 | 540 | * |
| 551 | 541 | * @since 2.0.0 |
| 552 | 542 | * @access public |
| 553 | 543 | * |
| 544 | + * | |
| 554 | 545 | * @return bool|Document |
| 555 | 546 | */ |
| 547 | + | |
| 556 | 548 | public function get_newer_autosave() { |
| 557 | 549 | $autosave = $this->get_autosave(); |
| 558 | 550 | |
| 559 | 551 | // Detect if there exists an autosave newer than the post. |
| @@ -608,12 +600,8 @@ | ||
| 608 | 600 | |
| 609 | 601 | if ( $autosave_id ) { |
| 610 | 602 | $document = Plugin::$instance->documents->get( $autosave_id ); |
| 611 | 603 | } elseif ( $create ) { |
| 612 | - if ( ! function_exists( 'wp_create_post_autosave' ) ) { | |
| 613 | - require_once ABSPATH . 'wp-admin/includes/post.php'; | |
| 614 | - } | |
| 615 | - | |
| 616 | 604 | $autosave_id = wp_create_post_autosave( [ |
| 617 | 605 | 'post_ID' => $this->post->ID, |
| 618 | 606 | 'post_type' => $this->post->post_type, |
| 619 | 607 | 'post_title' => $this->post->post_title, |
| @@ -642,9 +630,9 @@ | ||
| 642 | 630 | * Fired by `post_row_actions` and `page_row_actions` filters. |
| 643 | 631 | * |
| 644 | 632 | * @access public |
| 645 | 633 | * |
| 646 | - * @param array $actions An array of row action links. | |
| 634 | + * @param array $actions An array of row action links. | |
| 647 | 635 | * |
| 648 | 636 | * @return array An updated array of row action links. |
| 649 | 637 | */ |
| 650 | 638 | public function filter_admin_row_actions( $actions ) { |
| @@ -729,16 +717,19 @@ | ||
| 729 | 717 | |
| 730 | 718 | do_action( 'elementor/document/before_get_config', $this ); |
| 731 | 719 | |
| 732 | 720 | 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(); | |
| 721 | + $container_config = []; | |
| 722 | + $experiments_manager = Plugin::$instance->experiments; | |
| 737 | 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 | + | |
| 738 | 730 | $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() ); | |
| 731 | + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config(); | |
| 741 | 732 | } |
| 742 | 733 | |
| 743 | 734 | $additional_config = []; |
| 744 | 735 | |
| @@ -836,11 +827,9 @@ | ||
| 836 | 827 | */ |
| 837 | 828 | do_action( 'elementor/document/before_save', $this, $data ); |
| 838 | 829 | |
| 839 | 830 | 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 | - } ); | |
| 831 | + $data = wp_kses_post_deep( $data ); | |
| 843 | 832 | } |
| 844 | 833 | |
| 845 | 834 | if ( ! empty( $data['settings'] ) ) { |
| 846 | 835 | if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) { |
| @@ -925,9 +914,9 @@ | ||
| 925 | 914 | * |
| 926 | 915 | * @return bool Whether the post was built with Elementor. |
| 927 | 916 | */ |
| 928 | 917 | public function is_built_with_elementor() { |
| 929 | - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 918 | + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 930 | 919 | } |
| 931 | 920 | |
| 932 | 921 | /** |
| 933 | 922 | * Mark the post as "built with elementor" or not. |
| @@ -1037,9 +1026,9 @@ | ||
| 1037 | 1026 | return $meta; |
| 1038 | 1027 | } |
| 1039 | 1028 | |
| 1040 | 1029 | public function update_json_meta( $key, $value ) { |
| 1041 | - return $this->update_meta( | |
| 1030 | + $this->update_meta( | |
| 1042 | 1031 | $key, |
| 1043 | 1032 | // `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1044 | 1033 | wp_slash( wp_json_encode( $value ) ) |
| 1045 | 1034 | ); |
| @@ -1052,10 +1041,8 @@ | ||
| 1052 | 1041 | * @param null $data |
| 1053 | 1042 | * @param bool $with_html_content |
| 1054 | 1043 | * |
| 1055 | 1044 | * @return array |
| 1056 | - * | |
| 1057 | - * @throws \Exception If elements retrieval fails or data processing errors occur. | |
| 1058 | 1045 | */ |
| 1059 | 1046 | public function get_elements_raw_data( $data = null, $with_html_content = false ) { |
| 1060 | 1047 | if ( ! static::get_property( 'has_elements' ) ) { |
| 1061 | 1048 | return []; |
| @@ -1064,23 +1051,8 @@ | ||
| 1064 | 1051 | if ( is_null( $data ) ) { |
| 1065 | 1052 | $data = $this->get_elements_data(); |
| 1066 | 1053 | } |
| 1067 | 1054 | |
| 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 | 1055 | // Change the current documents, so widgets can use `documents->get_current` and other post data |
| 1084 | 1056 | Plugin::$instance->documents->switch_to_document( $this ); |
| 1085 | 1057 | |
| 1086 | 1058 | $editor_data = []; |
| @@ -1105,9 +1077,9 @@ | ||
| 1105 | 1077 | $element_data = $element->get_raw_data( $with_html_content ); |
| 1106 | 1078 | } |
| 1107 | 1079 | |
| 1108 | 1080 | $editor_data[] = $element_data; |
| 1109 | - } | |
| 1081 | + } // End foreach(). | |
| 1110 | 1082 | |
| 1111 | 1083 | Plugin::$instance->documents->restore_document(); |
| 1112 | 1084 | |
| 1113 | 1085 | return $editor_data; |
| @@ -1121,9 +1093,9 @@ | ||
| 1121 | 1093 | * |
| 1122 | 1094 | * @return array |
| 1123 | 1095 | */ |
| 1124 | 1096 | public function get_elements_data( $status = self::STATUS_PUBLISH ) { |
| 1125 | - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 1097 | + $elements = $this->get_json_meta( '_elementor_data' ); | |
| 1126 | 1098 | |
| 1127 | 1099 | if ( self::STATUS_DRAFT === $status ) { |
| 1128 | 1100 | $autosave = $this->get_newer_autosave(); |
| 1129 | 1101 | |
| @@ -1129,9 +1101,9 @@ | ||
| 1129 | 1101 | |
| 1130 | 1102 | if ( is_object( $autosave ) ) { |
| 1131 | 1103 | $autosave_elements = Plugin::$instance->documents |
| 1132 | 1104 | ->get( $autosave->get_post()->ID ) |
| 1133 | - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 1105 | + ->get_json_meta( '_elementor_data' ); | |
| 1134 | 1106 | } |
| 1135 | 1107 | } |
| 1136 | 1108 | |
| 1137 | 1109 | if ( Plugin::$instance->editor->is_edit_mode() ) { |
| @@ -1299,9 +1271,9 @@ | ||
| 1299 | 1271 | * @param array|null $controls The available controls. |
| 1300 | 1272 | * |
| 1301 | 1273 | * @return array Element data. |
| 1302 | 1274 | */ |
| 1303 | - 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 { | |
| 1304 | 1276 | foreach ( $config as &$element_config ) { |
| 1305 | 1277 | $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config ); |
| 1306 | 1278 | |
| 1307 | 1279 | if ( is_null( $element_instance ) ) { |
| @@ -1368,9 +1340,9 @@ | ||
| 1368 | 1340 | // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1369 | 1341 | $json_value = wp_slash( wp_json_encode( $editor_data ) ); |
| 1370 | 1342 | |
| 1371 | 1343 | // 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 ); | |
| 1344 | + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value ); | |
| 1373 | 1345 | |
| 1374 | 1346 | /** |
| 1375 | 1347 | * Before saving data. |
| 1376 | 1348 | * |
| @@ -1438,8 +1410,9 @@ | ||
| 1438 | 1410 | * |
| 1439 | 1411 | * @since 2.5.12 |
| 1440 | 1412 | * |
| 1441 | 1413 | * @param \Elementor\Core\Base\Document $this The current document. |
| 1414 | + * | |
| 1442 | 1415 | */ |
| 1443 | 1416 | do_action( 'elementor/document/save_version', $this ); |
| 1444 | 1417 | } |
| 1445 | 1418 | } |
| @@ -1476,9 +1449,9 @@ | ||
| 1476 | 1449 | * @since 2.0.4 |
| 1477 | 1450 | * @access public |
| 1478 | 1451 | * |
| 1479 | 1452 | * @param string $key Meta data key. |
| 1480 | - * @param mixed $value Meta data value. | |
| 1453 | + * @param mixed $value Meta data value. | |
| 1481 | 1454 | * |
| 1482 | 1455 | * @return bool|int |
| 1483 | 1456 | */ |
| 1484 | 1457 | public function update_main_meta( $key, $value ) { |
| @@ -1606,9 +1579,9 @@ | ||
| 1606 | 1579 | } else { |
| 1607 | 1580 | $this->post = get_post( $data['post_id'] ); |
| 1608 | 1581 | |
| 1609 | 1582 | 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 | |
| 1583 | + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND ); | |
| 1611 | 1584 | } |
| 1612 | 1585 | } |
| 1613 | 1586 | |
| 1614 | 1587 | // Each Control_Stack is based on a unique ID. |
| @@ -1626,9 +1599,9 @@ | ||
| 1626 | 1599 | |
| 1627 | 1600 | parent::__construct( $data ); |
| 1628 | 1601 | } |
| 1629 | 1602 | |
| 1630 | - /** | |
| 1603 | + /* | |
| 1631 | 1604 | * Get Export Data |
| 1632 | 1605 | * |
| 1633 | 1606 | * Filters a document's data on export |
| 1634 | 1607 | * |
| @@ -1640,10 +1613,8 @@ | ||
| 1640 | 1613 | public function get_export_data() { |
| 1641 | 1614 | $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) { |
| 1642 | 1615 | $element_data['id'] = Utils::generate_random_string(); |
| 1643 | 1616 | |
| 1644 | - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data ); | |
| 1645 | - | |
| 1646 | 1617 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1647 | 1618 | |
| 1648 | 1619 | // If the widget/element does not exist, like a plugin that creates a widget but deactivated. |
| 1649 | 1620 | if ( ! $element ) { |
| @@ -1667,9 +1638,9 @@ | ||
| 1667 | 1638 | 'thumbnail' => get_the_post_thumbnail_url( $this->post ), |
| 1668 | 1639 | ]; |
| 1669 | 1640 | } |
| 1670 | 1641 | |
| 1671 | - /** | |
| 1642 | + /* | |
| 1672 | 1643 | * Get Import Data |
| 1673 | 1644 | * |
| 1674 | 1645 | * Filters a document's data on import |
| 1675 | 1646 | * |
| @@ -1813,25 +1784,14 @@ | ||
| 1813 | 1784 | } |
| 1814 | 1785 | |
| 1815 | 1786 | /** |
| 1816 | 1787 | * @since 2.1.3 |
| 1817 | - * @access public | |
| 1788 | + * @access protected | |
| 1818 | 1789 | */ |
| 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 | - | |
| 1790 | + protected function print_elements( $elements_data ) { | |
| 1791 | + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) { | |
| 1824 | 1792 | $this->do_print_elements( $elements_data ); |
| 1825 | 1793 | |
| 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 | 1794 | return; |
| 1835 | 1795 | } |
| 1836 | 1796 | |
| 1837 | 1797 | $cached_data = $this->get_document_cache(); |
| @@ -1884,21 +1844,20 @@ | ||
| 1884 | 1844 | } |
| 1885 | 1845 | } |
| 1886 | 1846 | |
| 1887 | 1847 | 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 | |
| 1848 | + echo do_shortcode( $cached_data['content'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1895 | 1849 | } |
| 1896 | 1850 | } |
| 1897 | 1851 | |
| 1898 | 1852 | protected function do_print_elements( $elements_data ) { |
| 1899 | - $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(); | |
| 1900 | 1855 | |
| 1856 | + if ( $runtime_elements_iteration_actions ) { | |
| 1857 | + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); | |
| 1858 | + } | |
| 1859 | + | |
| 1901 | 1860 | foreach ( $elements_data as $element_data ) { |
| 1902 | 1861 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1903 | 1862 | |
| 1904 | 1863 | if ( ! $element ) { |
| @@ -1908,21 +1867,8 @@ | ||
| 1908 | 1867 | $element->print_element(); |
| 1909 | 1868 | } |
| 1910 | 1869 | } |
| 1911 | 1870 | |
| 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 | 1871 | public function set_document_cache( $value ) { |
| 1926 | 1872 | $expiration_hours = get_option( 'elementor_element_cache_ttl', '' ); |
| 1927 | 1873 | |
| 1928 | 1874 | if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) { |
| @@ -2107,10 +2053,6 @@ | ||
| 2107 | 2053 | $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this ); |
| 2108 | 2054 | } |
| 2109 | 2055 | |
| 2110 | 2056 | return $this->elements_iteration_actions; |
| 2111 | - } | |
| 2112 | - | |
| 2113 | - public function get_elementor_version() { | |
| 2114 | - return $this->get_main_meta( '_elementor_version' ); | |
| 2115 | 2057 | } |
| 2116 | 2058 | } |