| @@ -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; |
| @@ -18,12 +17,11 @@ | ||
| 18 | 17 | use Elementor\Utils; |
| 19 | 18 | use Elementor\Widget_Base; |
| 20 | 19 | use Elementor\Core\Settings\Page\Manager as PageManager; |
| 21 | 20 | use ElementorPro\Modules\Library\Widgets\Template; |
| 22 | -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; | |
| 23 | 21 | |
| 24 | 22 | if ( ! defined( 'ABSPATH' ) ) { |
| 25 | - exit; // Exit if accessed directly. | |
| 23 | + exit; // Exit if accessed directly | |
| 26 | 24 | } |
| 27 | 25 | |
| 28 | 26 | /** |
| 29 | 27 | * Elementor document. |
| @@ -40,16 +38,11 @@ | ||
| 40 | 38 | * Document type meta key. |
| 41 | 39 | */ |
| 42 | 40 | const TYPE_META_KEY = '_elementor_template_type'; |
| 43 | 41 | const PAGE_META_KEY = '_elementor_page_settings'; |
| 44 | - const ELEMENTOR_DATA_META_KEY = '_elementor_data'; | |
| 45 | 42 | |
| 46 | 43 | const BUILT_WITH_ELEMENTOR_META_KEY = '_elementor_edit_mode'; |
| 47 | 44 | |
| 48 | - const CACHE_META_KEY = '_elementor_element_cache'; | |
| 49 | - | |
| 50 | - const UNEDITABLE_WITH_ELEMENTOR_TYPES = [ 'kit' ]; | |
| 51 | - | |
| 52 | 45 | /** |
| 53 | 46 | * Document publish status. |
| 54 | 47 | */ |
| 55 | 48 | const STATUS_PUBLISH = 'publish'; |
| @@ -73,11 +66,9 @@ | ||
| 73 | 66 | * Document pending status. |
| 74 | 67 | */ |
| 75 | 68 | const STATUS_PENDING = 'pending'; |
| 76 | 69 | |
| 77 | - /** | |
| 78 | - * @var int | |
| 79 | - */ | |
| 70 | + | |
| 80 | 71 | private $main_id; |
| 81 | 72 | |
| 82 | 73 | /** |
| 83 | 74 | * @var bool |
| @@ -103,44 +94,8 @@ | ||
| 103 | 94 | */ |
| 104 | 95 | protected $post; |
| 105 | 96 | |
| 106 | 97 | /** |
| 107 | - * @param array $internal_elements | |
| 108 | - * | |
| 109 | - * @return array[] | |
| 110 | - */ | |
| 111 | - private function get_container_elements_data( array $internal_elements ): array { | |
| 112 | - return [ | |
| 113 | - [ | |
| 114 | - 'id' => Utils::generate_random_string(), | |
| 115 | - 'elType' => 'container', | |
| 116 | - 'elements' => $internal_elements, | |
| 117 | - ], | |
| 118 | - ]; | |
| 119 | - } | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * @param array $internal_elements | |
| 123 | - * | |
| 124 | - * @return array[] | |
| 125 | - */ | |
| 126 | - private function get_sections_elements_data( array $internal_elements ): array { | |
| 127 | - return [ | |
| 128 | - [ | |
| 129 | - 'id' => Utils::generate_random_string(), | |
| 130 | - 'elType' => 'section', | |
| 131 | - 'elements' => [ | |
| 132 | - [ | |
| 133 | - 'id' => Utils::generate_random_string(), | |
| 134 | - 'elType' => 'column', | |
| 135 | - 'elements' => $internal_elements, | |
| 136 | - ], | |
| 137 | - ], | |
| 138 | - ], | |
| 139 | - ]; | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | 98 | * @since 2.1.0 |
| 144 | 99 | * @access protected |
| 145 | 100 | * @static |
| 146 | 101 | */ |
| @@ -166,15 +121,8 @@ | ||
| 166 | 121 | 'edit_capability' => '', |
| 167 | 122 | 'show_in_finder' => true, |
| 168 | 123 | 'show_on_admin_bar' => true, |
| 169 | 124 | '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 | 125 | ]; |
| 178 | 126 | } |
| 179 | 127 | |
| 180 | 128 | /** |
| @@ -191,70 +139,20 @@ | ||
| 191 | 139 | |
| 192 | 140 | return [ |
| 193 | 141 | 'title' => static::get_title(), // JS Container title. |
| 194 | 142 | 'widgets_settings' => [], |
| 195 | - 'elements_categories' => self::get_filtered_editor_panel_categories(), | |
| 143 | + 'elements_categories' => static::get_editor_panel_categories(), | |
| 196 | 144 | 'default_route' => $default_route, |
| 197 | 145 | 'has_elements' => static::get_property( 'has_elements' ), |
| 198 | 146 | 'support_kit' => static::get_property( 'support_kit' ), |
| 199 | 147 | 'messages' => [ |
| 200 | - 'publish_notification' => sprintf( | |
| 201 | - /* translators: %s: Document title. */ | |
| 202 | - esc_html__( 'Hurray! Your %s is live.', 'elementor' ), | |
| 203 | - static::get_title() | |
| 204 | - ), | |
| 148 | + /* translators: %s: Document title. */ | |
| 149 | + 'publish_notification' => sprintf( esc_html__( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ), | |
| 205 | 150 | ], |
| 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 | 151 | ]; |
| 213 | 152 | } |
| 214 | 153 | |
| 215 | - public static function get_filtered_editor_panel_categories(): array { | |
| 216 | - $categories = static::get_editor_panel_categories(); | |
| 217 | - $has_pro = Utils::has_pro(); | |
| 218 | - | |
| 219 | - foreach ( $categories as $index => $category ) { | |
| 220 | - if ( isset( $category['promotion'] ) ) { | |
| 221 | - $categories = self::get_panel_category_item( $category['promotion'], $index, $categories, $has_pro ); | |
| 222 | - } | |
| 223 | - } | |
| 224 | - | |
| 225 | - return $categories; | |
| 226 | - } | |
| 227 | - | |
| 228 | 154 | /** |
| 229 | - * @param $promotion | |
| 230 | - * @param $index | |
| 231 | - * @param array $categories | |
| 232 | - * | |
| 233 | - * @return array | |
| 234 | - */ | |
| 235 | - 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 ) { | |
| 244 | - $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data( | |
| 245 | - $promotion, | |
| 246 | - 'elementor/panel/' . $index . '/custom_promotion', | |
| 247 | - 'url' | |
| 248 | - ); | |
| 249 | - } else { | |
| 250 | - unset( $categories[ $index ]['promotion'] ); | |
| 251 | - } | |
| 252 | - | |
| 253 | - return $categories; | |
| 254 | - } | |
| 255 | - | |
| 256 | - /** | |
| 257 | 155 | * Get element title. |
| 258 | 156 | * |
| 259 | 157 | * Retrieve the element title. |
| 260 | 158 | * |
| @@ -272,13 +170,9 @@ | ||
| 272 | 170 | return static::get_title(); |
| 273 | 171 | } |
| 274 | 172 | |
| 275 | 173 | public static function get_add_new_title() { |
| 276 | - return sprintf( | |
| 277 | - /* translators: %s: Document title. */ | |
| 278 | - esc_html__( 'Add New %s', 'elementor' ), | |
| 279 | - static::get_title() | |
| 280 | - ); | |
| 174 | + return sprintf( esc_html__( 'Add New %s', 'elementor' ), static::get_title() ); | |
| 281 | 175 | } |
| 282 | 176 | |
| 283 | 177 | /** |
| 284 | 178 | * Get property. |
| @@ -559,10 +453,12 @@ | ||
| 559 | 453 | * |
| 560 | 454 | * @since 2.0.0 |
| 561 | 455 | * @access public |
| 562 | 456 | * |
| 457 | + * | |
| 563 | 458 | * @return bool|Document |
| 564 | 459 | */ |
| 460 | + | |
| 565 | 461 | public function get_newer_autosave() { |
| 566 | 462 | $autosave = $this->get_autosave(); |
| 567 | 463 | |
| 568 | 464 | // Detect if there exists an autosave newer than the post. |
| @@ -617,12 +513,8 @@ | ||
| 617 | 513 | |
| 618 | 514 | if ( $autosave_id ) { |
| 619 | 515 | $document = Plugin::$instance->documents->get( $autosave_id ); |
| 620 | 516 | } elseif ( $create ) { |
| 621 | - if ( ! function_exists( 'wp_create_post_autosave' ) ) { | |
| 622 | - require_once ABSPATH . 'wp-admin/includes/post.php'; | |
| 623 | - } | |
| 624 | - | |
| 625 | 517 | $autosave_id = wp_create_post_autosave( [ |
| 626 | 518 | 'post_ID' => $this->post->ID, |
| 627 | 519 | 'post_type' => $this->post->post_type, |
| 628 | 520 | 'post_title' => $this->post->post_title, |
| @@ -651,14 +543,14 @@ | ||
| 651 | 543 | * Fired by `post_row_actions` and `page_row_actions` filters. |
| 652 | 544 | * |
| 653 | 545 | * @access public |
| 654 | 546 | * |
| 655 | - * @param array $actions An array of row action links. | |
| 547 | + * @param array $actions An array of row action links. | |
| 656 | 548 | * |
| 657 | 549 | * @return array An updated array of row action links. |
| 658 | 550 | */ |
| 659 | 551 | public function filter_admin_row_actions( $actions ) { |
| 660 | - if ( $this->is_editable_with_elementor() ) { | |
| 552 | + if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) { | |
| 661 | 553 | $actions['edit_with_elementor'] = sprintf( |
| 662 | 554 | '<a href="%1$s">%2$s</a>', |
| 663 | 555 | $this->get_edit_url(), |
| 664 | 556 | __( 'Edit with Elementor', 'elementor' ) |
| @@ -667,16 +559,8 @@ | ||
| 667 | 559 | |
| 668 | 560 | return $actions; |
| 669 | 561 | } |
| 670 | 562 | |
| 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 | 563 | /** |
| 680 | 564 | * @since 2.0.0 |
| 681 | 565 | * @access public |
| 682 | 566 | */ |
| @@ -746,16 +630,19 @@ | ||
| 746 | 630 | |
| 747 | 631 | do_action( 'elementor/document/before_get_config', $this ); |
| 748 | 632 | |
| 749 | 633 | 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(); | |
| 634 | + $container_config = []; | |
| 635 | + $experiments_manager = Plugin::$instance->experiments; | |
| 754 | 636 | |
| 637 | + if ( $experiments_manager->is_feature_active( 'container' ) ) { | |
| 638 | + $container_config = [ | |
| 639 | + 'container' => Plugin::$instance->elements_manager->get_element_types( 'container' )->get_config(), | |
| 640 | + ]; | |
| 641 | + } | |
| 642 | + | |
| 755 | 643 | $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() ); | |
| 644 | + $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config(); | |
| 758 | 645 | } |
| 759 | 646 | |
| 760 | 647 | $additional_config = []; |
| 761 | 648 | |
| @@ -810,16 +697,8 @@ | ||
| 810 | 697 | * @return bool |
| 811 | 698 | */ |
| 812 | 699 | public function save( $data ) { |
| 813 | 700 | /** |
| 814 | - * Set locale to "C" to avoid issues with comma as decimal separator. | |
| 815 | - * | |
| 816 | - * @see https://github.com/elementor/elementor/issues/10992 | |
| 817 | - */ | |
| 818 | - $original_lc = setlocale( LC_NUMERIC, 0 ); | |
| 819 | - setlocale( LC_NUMERIC, 'C' ); | |
| 820 | - | |
| 821 | - /** | |
| 822 | 701 | * Document save data. |
| 823 | 702 | * |
| 824 | 703 | * Filter the document data before saving process starts. |
| 825 | 704 | * |
| @@ -853,11 +732,9 @@ | ||
| 853 | 732 | */ |
| 854 | 733 | do_action( 'elementor/document/before_save', $this, $data ); |
| 855 | 734 | |
| 856 | 735 | 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 | - } ); | |
| 736 | + $data = wp_kses_post_deep( $data ); | |
| 860 | 737 | } |
| 861 | 738 | |
| 862 | 739 | if ( ! empty( $data['settings'] ) ) { |
| 863 | 740 | if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) { |
| @@ -884,11 +761,8 @@ | ||
| 884 | 761 | $post_css = Post_CSS::create( $this->post->ID ); |
| 885 | 762 | |
| 886 | 763 | $post_css->delete(); |
| 887 | 764 | |
| 888 | - // Remove Document Cache | |
| 889 | - $this->delete_cache(); | |
| 890 | - | |
| 891 | 765 | /** |
| 892 | 766 | * After document save. |
| 893 | 767 | * |
| 894 | 768 | * Fires when document save is complete. |
| @@ -903,10 +777,8 @@ | ||
| 903 | 777 | $this->set_is_saving( false ); |
| 904 | 778 | |
| 905 | 779 | $this->remove_handle_revisions_changed_filter(); |
| 906 | 780 | |
| 907 | - setlocale( LC_NUMERIC, $original_lc ); | |
| 908 | - | |
| 909 | 781 | return true; |
| 910 | 782 | } |
| 911 | 783 | |
| 912 | 784 | public function refresh_post() { |
| @@ -942,9 +814,9 @@ | ||
| 942 | 814 | * |
| 943 | 815 | * @return bool Whether the post was built with Elementor. |
| 944 | 816 | */ |
| 945 | 817 | public function is_built_with_elementor() { |
| 946 | - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 818 | + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 947 | 819 | } |
| 948 | 820 | |
| 949 | 821 | /** |
| 950 | 822 | * Mark the post as "built with elementor" or not. |
| @@ -1054,9 +926,9 @@ | ||
| 1054 | 926 | return $meta; |
| 1055 | 927 | } |
| 1056 | 928 | |
| 1057 | 929 | public function update_json_meta( $key, $value ) { |
| 1058 | - return $this->update_meta( | |
| 930 | + $this->update_meta( | |
| 1059 | 931 | $key, |
| 1060 | 932 | // `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1061 | 933 | wp_slash( wp_json_encode( $value ) ) |
| 1062 | 934 | ); |
| @@ -1069,10 +941,8 @@ | ||
| 1069 | 941 | * @param null $data |
| 1070 | 942 | * @param bool $with_html_content |
| 1071 | 943 | * |
| 1072 | 944 | * @return array |
| 1073 | - * | |
| 1074 | - * @throws \Exception If elements retrieval fails or data processing errors occur. | |
| 1075 | 945 | */ |
| 1076 | 946 | public function get_elements_raw_data( $data = null, $with_html_content = false ) { |
| 1077 | 947 | if ( ! static::get_property( 'has_elements' ) ) { |
| 1078 | 948 | return []; |
| @@ -1081,23 +951,8 @@ | ||
| 1081 | 951 | if ( is_null( $data ) ) { |
| 1082 | 952 | $data = $this->get_elements_data(); |
| 1083 | 953 | } |
| 1084 | 954 | |
| 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 | 955 | // Change the current documents, so widgets can use `documents->get_current` and other post data |
| 1101 | 956 | Plugin::$instance->documents->switch_to_document( $this ); |
| 1102 | 957 | |
| 1103 | 958 | $editor_data = []; |
| @@ -1122,9 +977,9 @@ | ||
| 1122 | 977 | $element_data = $element->get_raw_data( $with_html_content ); |
| 1123 | 978 | } |
| 1124 | 979 | |
| 1125 | 980 | $editor_data[] = $element_data; |
| 1126 | - } | |
| 981 | + } // End foreach(). | |
| 1127 | 982 | |
| 1128 | 983 | Plugin::$instance->documents->restore_document(); |
| 1129 | 984 | |
| 1130 | 985 | return $editor_data; |
| @@ -1138,9 +993,9 @@ | ||
| 1138 | 993 | * |
| 1139 | 994 | * @return array |
| 1140 | 995 | */ |
| 1141 | 996 | public function get_elements_data( $status = self::STATUS_PUBLISH ) { |
| 1142 | - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 997 | + $elements = $this->get_json_meta( '_elementor_data' ); | |
| 1143 | 998 | |
| 1144 | 999 | if ( self::STATUS_DRAFT === $status ) { |
| 1145 | 1000 | $autosave = $this->get_newer_autosave(); |
| 1146 | 1001 | |
| @@ -1146,9 +1001,9 @@ | ||
| 1146 | 1001 | |
| 1147 | 1002 | if ( is_object( $autosave ) ) { |
| 1148 | 1003 | $autosave_elements = Plugin::$instance->documents |
| 1149 | 1004 | ->get( $autosave->get_post()->ID ) |
| 1150 | - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 1005 | + ->get_json_meta( '_elementor_data' ); | |
| 1151 | 1006 | } |
| 1152 | 1007 | } |
| 1153 | 1008 | |
| 1154 | 1009 | if ( Plugin::$instance->editor->is_edit_mode() ) { |
| @@ -1209,20 +1064,28 @@ | ||
| 1209 | 1064 | ]; |
| 1210 | 1065 | } |
| 1211 | 1066 | |
| 1212 | 1067 | // TODO: Better coding to start template for editor |
| 1213 | - $converted_blocks = [ | |
| 1068 | + return [ | |
| 1214 | 1069 | [ |
| 1215 | 1070 | 'id' => Utils::generate_random_string(), |
| 1216 | - 'elType' => $widget_type::get_type(), | |
| 1217 | - 'widgetType' => $widget_type->get_name(), | |
| 1218 | - 'settings' => $settings, | |
| 1071 | + 'elType' => 'section', | |
| 1072 | + 'elements' => [ | |
| 1073 | + [ | |
| 1074 | + 'id' => Utils::generate_random_string(), | |
| 1075 | + 'elType' => 'column', | |
| 1076 | + 'elements' => [ | |
| 1077 | + [ | |
| 1078 | + 'id' => Utils::generate_random_string(), | |
| 1079 | + 'elType' => $widget_type::get_type(), | |
| 1080 | + 'widgetType' => $widget_type->get_name(), | |
| 1081 | + 'settings' => $settings, | |
| 1082 | + ], | |
| 1083 | + ], | |
| 1084 | + ], | |
| 1085 | + ], | |
| 1219 | 1086 | ], |
| 1220 | 1087 | ]; |
| 1221 | - | |
| 1222 | - return Plugin::$instance->experiments->is_feature_active( 'container' ) | |
| 1223 | - ? $this->get_container_elements_data( $converted_blocks ) | |
| 1224 | - : $this->get_sections_elements_data( $converted_blocks ); | |
| 1225 | 1088 | } |
| 1226 | 1089 | |
| 1227 | 1090 | /** |
| 1228 | 1091 | * @since 2.1.3 |
| @@ -1232,11 +1095,20 @@ | ||
| 1232 | 1095 | if ( ! $elements_data ) { |
| 1233 | 1096 | $elements_data = $this->get_elements_data(); |
| 1234 | 1097 | } |
| 1235 | 1098 | |
| 1099 | + $is_dom_optimization_active = Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ); | |
| 1236 | 1100 | ?> |
| 1237 | 1101 | <div <?php Utils::print_html_attributes( $this->get_container_attributes() ); ?>> |
| 1102 | + <?php if ( ! $is_dom_optimization_active ) : ?> | |
| 1103 | + <div class="elementor-inner"> | |
| 1104 | + <div class="elementor-section-wrap"> | |
| 1105 | + <?php endif; ?> | |
| 1238 | 1106 | <?php $this->print_elements( $elements_data ); ?> |
| 1107 | + <?php if ( ! $is_dom_optimization_active ) : ?> | |
| 1108 | + </div> | |
| 1109 | + </div> | |
| 1110 | + <?php endif; ?> | |
| 1239 | 1111 | </div> |
| 1240 | 1112 | <?php |
| 1241 | 1113 | } |
| 1242 | 1114 | |
| @@ -1253,13 +1125,10 @@ | ||
| 1253 | 1125 | * @access public |
| 1254 | 1126 | */ |
| 1255 | 1127 | public function get_panel_page_settings() { |
| 1256 | 1128 | return [ |
| 1257 | - 'title' => sprintf( | |
| 1258 | - /* translators: %s: Document title. */ | |
| 1259 | - esc_html__( '%s Settings', 'elementor' ), | |
| 1260 | - static::get_title() | |
| 1261 | - ), | |
| 1129 | + /* translators: %s: Document title. */ | |
| 1130 | + 'title' => sprintf( esc_html__( '%s Settings', 'elementor' ), static::get_title() ), | |
| 1262 | 1131 | ]; |
| 1263 | 1132 | } |
| 1264 | 1133 | |
| 1265 | 1134 | /** |
| @@ -1316,9 +1185,9 @@ | ||
| 1316 | 1185 | * @param array|null $controls The available controls. |
| 1317 | 1186 | * |
| 1318 | 1187 | * @return array Element data. |
| 1319 | 1188 | */ |
| 1320 | - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array { | |
| 1189 | + public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array { | |
| 1321 | 1190 | foreach ( $config as &$element_config ) { |
| 1322 | 1191 | $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config ); |
| 1323 | 1192 | |
| 1324 | 1193 | if ( is_null( $element_instance ) ) { |
| @@ -1385,9 +1254,9 @@ | ||
| 1385 | 1254 | // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1386 | 1255 | $json_value = wp_slash( wp_json_encode( $editor_data ) ); |
| 1387 | 1256 | |
| 1388 | 1257 | // 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 ); | |
| 1258 | + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value ); | |
| 1390 | 1259 | |
| 1391 | 1260 | /** |
| 1392 | 1261 | * Before saving data. |
| 1393 | 1262 | * |
| @@ -1455,8 +1324,9 @@ | ||
| 1455 | 1324 | * |
| 1456 | 1325 | * @since 2.5.12 |
| 1457 | 1326 | * |
| 1458 | 1327 | * @param \Elementor\Core\Base\Document $this The current document. |
| 1328 | + * | |
| 1459 | 1329 | */ |
| 1460 | 1330 | do_action( 'elementor/document/save_version', $this ); |
| 1461 | 1331 | } |
| 1462 | 1332 | } |
| @@ -1493,9 +1363,9 @@ | ||
| 1493 | 1363 | * @since 2.0.4 |
| 1494 | 1364 | * @access public |
| 1495 | 1365 | * |
| 1496 | 1366 | * @param string $key Meta data key. |
| 1497 | - * @param mixed $value Meta data value. | |
| 1367 | + * @param string $value Meta data value. | |
| 1498 | 1368 | * |
| 1499 | 1369 | * @return bool|int |
| 1500 | 1370 | */ |
| 1501 | 1371 | public function update_main_meta( $key, $value ) { |
| @@ -1570,21 +1440,13 @@ | ||
| 1570 | 1440 | $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) ); |
| 1571 | 1441 | $display_name = get_the_author_meta( 'display_name', $post->post_author ); |
| 1572 | 1442 | |
| 1573 | 1443 | if ( $autosave_post || 'revision' === $post->post_type ) { |
| 1574 | - $last_edited = sprintf( | |
| 1575 | - /* translators: 1: Saving date, 2: Author display name. */ | |
| 1576 | - esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), | |
| 1577 | - '<time>' . $date . '</time>', | |
| 1578 | - $display_name | |
| 1579 | - ); | |
| 1444 | + /* translators: 1: Saving date, 2: Author display name. */ | |
| 1445 | + $last_edited = sprintf( esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name ); | |
| 1580 | 1446 | } else { |
| 1581 | - $last_edited = sprintf( | |
| 1582 | - /* translators: 1: Editing date, 2: Author display name. */ | |
| 1583 | - esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), | |
| 1584 | - '<time>' . $date . '</time>', | |
| 1585 | - $display_name | |
| 1586 | - ); | |
| 1447 | + /* translators: 1: Editing date, 2: Author display name. */ | |
| 1448 | + $last_edited = sprintf( esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name ); | |
| 1587 | 1449 | } |
| 1588 | 1450 | |
| 1589 | 1451 | return $last_edited; |
| 1590 | 1452 | } |
| @@ -1623,9 +1485,9 @@ | ||
| 1623 | 1485 | } else { |
| 1624 | 1486 | $this->post = get_post( $data['post_id'] ); |
| 1625 | 1487 | |
| 1626 | 1488 | 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 | |
| 1489 | + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND ); | |
| 1628 | 1490 | } |
| 1629 | 1491 | } |
| 1630 | 1492 | |
| 1631 | 1493 | // Each Control_Stack is based on a unique ID. |
| @@ -1643,9 +1505,9 @@ | ||
| 1643 | 1505 | |
| 1644 | 1506 | parent::__construct( $data ); |
| 1645 | 1507 | } |
| 1646 | 1508 | |
| 1647 | - /** | |
| 1509 | + /* | |
| 1648 | 1510 | * Get Export Data |
| 1649 | 1511 | * |
| 1650 | 1512 | * Filters a document's data on export |
| 1651 | 1513 | * |
| @@ -1657,13 +1519,11 @@ | ||
| 1657 | 1519 | public function get_export_data() { |
| 1658 | 1520 | $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) { |
| 1659 | 1521 | $element_data['id'] = Utils::generate_random_string(); |
| 1660 | 1522 | |
| 1661 | - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data ); | |
| 1662 | - | |
| 1663 | 1523 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1664 | 1524 | |
| 1665 | - // If the widget/element does not exist, like a plugin that creates a widget but deactivated. | |
| 1525 | + // If the widget/element isn't exist, like a plugin that creates a widget but deactivated | |
| 1666 | 1526 | if ( ! $element ) { |
| 1667 | 1527 | return null; |
| 1668 | 1528 | } |
| 1669 | 1529 | |
| @@ -1684,9 +1544,9 @@ | ||
| 1684 | 1544 | 'thumbnail' => get_the_post_thumbnail_url( $this->post ), |
| 1685 | 1545 | ]; |
| 1686 | 1546 | } |
| 1687 | 1547 | |
| 1688 | - /** | |
| 1548 | + /* | |
| 1689 | 1549 | * Get Import Data |
| 1690 | 1550 | * |
| 1691 | 1551 | * Filters a document's data on import |
| 1692 | 1552 | * |
| @@ -1830,92 +1690,18 @@ | ||
| 1830 | 1690 | } |
| 1831 | 1691 | |
| 1832 | 1692 | /** |
| 1833 | 1693 | * @since 2.1.3 |
| 1834 | - * @access public | |
| 1694 | + * @access protected | |
| 1835 | 1695 | */ |
| 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(); | |
| 1696 | + protected function print_elements( $elements_data ) { | |
| 1697 | + // Collect all data updaters that should be updated on runtime. | |
| 1698 | + $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions(); | |
| 1840 | 1699 | |
| 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; | |
| 1700 | + if ( $runtime_elements_iteration_actions ) { | |
| 1701 | + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); | |
| 1852 | 1702 | } |
| 1853 | 1703 | |
| 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 | 1704 | foreach ( $elements_data as $element_data ) { |
| 1919 | 1705 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1920 | 1706 | |
| 1921 | 1707 | if ( ! $element ) { |
| @@ -1925,75 +1711,8 @@ | ||
| 1925 | 1711 | $element->print_element(); |
| 1926 | 1712 | } |
| 1927 | 1713 | } |
| 1928 | 1714 | |
| 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 | 1715 | protected function register_document_controls() { |
| 1997 | 1716 | $this->start_controls_section( |
| 1998 | 1717 | 'document_settings', |
| 1999 | 1718 | [ |
| @@ -2124,10 +1843,6 @@ | ||
| 2124 | 1843 | $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this ); |
| 2125 | 1844 | } |
| 2126 | 1845 | |
| 2127 | 1846 | return $this->elements_iteration_actions; |
| 2128 | - } | |
| 2129 | - | |
| 2130 | - public function get_elementor_version() { | |
| 2131 | - return $this->get_main_meta( '_elementor_version' ); | |
| 2132 | 1847 | } |
| 2133 | 1848 | } |