| @@ -2,14 +2,11 @@ | ||
| 2 | 2 | namespace Elementor\Core\Base; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Elements_Iteration_Actions\Assets as Assets_Iteration_Action; |
| 5 | 5 | use Elementor\Core\Base\Elements_Iteration_Actions\Base as Elements_Iteration_Action; |
| 6 | -use Elementor\Core\Behaviors\Interfaces\Lock_Behavior; | |
| 7 | 6 | use Elementor\Core\Files\CSS\Post as Post_CSS; |
| 8 | 7 | use Elementor\Core\Settings\Page\Model as Page_Model; |
| 9 | -use Elementor\Core\Utils\Collection; | |
| 10 | 8 | use Elementor\Core\Utils\Exceptions; |
| 11 | -use Elementor\Includes\Elements\Container; | |
| 12 | 9 | use Elementor\Plugin; |
| 13 | 10 | use Elementor\Controls_Manager; |
| 14 | 11 | use Elementor\Controls_Stack; |
| 15 | 12 | use Elementor\TemplateLibrary\Source_Local; |
| @@ -17,13 +14,11 @@ | ||
| 17 | 14 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 18 | 15 | use Elementor\Utils; |
| 19 | 16 | use Elementor\Widget_Base; |
| 20 | 17 | use Elementor\Core\Settings\Page\Manager as PageManager; |
| 21 | -use ElementorPro\Modules\Library\Widgets\Template; | |
| 22 | -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; | |
| 23 | 18 | |
| 24 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 25 | - exit; // Exit if accessed directly. | |
| 20 | + exit; // Exit if accessed directly | |
| 26 | 21 | } |
| 27 | 22 | |
| 28 | 23 | /** |
| 29 | 24 | * Elementor document. |
| @@ -40,14 +35,11 @@ | ||
| 40 | 35 | * Document type meta key. |
| 41 | 36 | */ |
| 42 | 37 | const TYPE_META_KEY = '_elementor_template_type'; |
| 43 | 38 | const PAGE_META_KEY = '_elementor_page_settings'; |
| 44 | - const ELEMENTOR_DATA_META_KEY = '_elementor_data'; | |
| 45 | 39 | |
| 46 | 40 | const BUILT_WITH_ELEMENTOR_META_KEY = '_elementor_edit_mode'; |
| 47 | 41 | |
| 48 | - const CACHE_META_KEY = '_elementor_element_cache'; | |
| 49 | - | |
| 50 | 42 | /** |
| 51 | 43 | * Document publish status. |
| 52 | 44 | */ |
| 53 | 45 | const STATUS_PUBLISH = 'publish'; |
| @@ -71,11 +63,9 @@ | ||
| 71 | 63 | * Document pending status. |
| 72 | 64 | */ |
| 73 | 65 | const STATUS_PENDING = 'pending'; |
| 74 | 66 | |
| 75 | - /** | |
| 76 | - * @var int | |
| 77 | - */ | |
| 67 | + | |
| 78 | 68 | private $main_id; |
| 79 | 69 | |
| 80 | 70 | /** |
| 81 | 71 | * @var bool |
| @@ -101,44 +91,8 @@ | ||
| 101 | 91 | */ |
| 102 | 92 | protected $post; |
| 103 | 93 | |
| 104 | 94 | /** |
| 105 | - * @param array $internal_elements | |
| 106 | - * | |
| 107 | - * @return array[] | |
| 108 | - */ | |
| 109 | - private function get_container_elements_data( array $internal_elements ): array { | |
| 110 | - return [ | |
| 111 | - [ | |
| 112 | - 'id' => Utils::generate_random_string(), | |
| 113 | - 'elType' => 'container', | |
| 114 | - 'elements' => $internal_elements, | |
| 115 | - ], | |
| 116 | - ]; | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * @param array $internal_elements | |
| 121 | - * | |
| 122 | - * @return array[] | |
| 123 | - */ | |
| 124 | - private function get_sections_elements_data( array $internal_elements ): array { | |
| 125 | - return [ | |
| 126 | - [ | |
| 127 | - 'id' => Utils::generate_random_string(), | |
| 128 | - 'elType' => 'section', | |
| 129 | - 'elements' => [ | |
| 130 | - [ | |
| 131 | - 'id' => Utils::generate_random_string(), | |
| 132 | - 'elType' => 'column', | |
| 133 | - 'elements' => $internal_elements, | |
| 134 | - ], | |
| 135 | - ], | |
| 136 | - ], | |
| 137 | - ]; | |
| 138 | - } | |
| 139 | - | |
| 140 | - /** | |
| 141 | 95 | * @since 2.1.0 |
| 142 | 96 | * @access protected |
| 143 | 97 | * @static |
| 144 | 98 | */ |
| @@ -164,15 +118,8 @@ | ||
| 164 | 118 | 'edit_capability' => '', |
| 165 | 119 | 'show_in_finder' => true, |
| 166 | 120 | 'show_on_admin_bar' => true, |
| 167 | 121 | '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 | 122 | ]; |
| 176 | 123 | } |
| 177 | 124 | |
| 178 | 125 | /** |
| @@ -189,63 +136,20 @@ | ||
| 189 | 136 | |
| 190 | 137 | return [ |
| 191 | 138 | 'title' => static::get_title(), // JS Container title. |
| 192 | 139 | 'widgets_settings' => [], |
| 193 | - 'elements_categories' => self::get_filtered_editor_panel_categories(), | |
| 140 | + 'elements_categories' => static::get_editor_panel_categories(), | |
| 194 | 141 | 'default_route' => $default_route, |
| 195 | 142 | 'has_elements' => static::get_property( 'has_elements' ), |
| 196 | 143 | 'support_kit' => static::get_property( 'support_kit' ), |
| 197 | 144 | 'messages' => [ |
| 198 | - 'publish_notification' => sprintf( | |
| 199 | - /* translators: %s: Document title. */ | |
| 200 | - esc_html__( 'Hurray! Your %s is live.', 'elementor' ), | |
| 201 | - static::get_title() | |
| 202 | - ), | |
| 145 | + /* translators: %s: the document title. */ | |
| 146 | + 'publish_notification' => sprintf( esc_html__( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ), | |
| 203 | 147 | ], |
| 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 | 148 | ]; |
| 211 | 149 | } |
| 212 | 150 | |
| 213 | - public static function get_filtered_editor_panel_categories(): array { | |
| 214 | - $categories = static::get_editor_panel_categories(); | |
| 215 | - $has_pro = Utils::has_pro(); | |
| 216 | - | |
| 217 | - foreach ( $categories as $index => $category ) { | |
| 218 | - if ( isset( $category['promotion'] ) ) { | |
| 219 | - $categories = self::get_panel_category_item( $category['promotion'], $index, $categories, $has_pro ); | |
| 220 | - } | |
| 221 | - } | |
| 222 | - | |
| 223 | - return $categories; | |
| 224 | - } | |
| 225 | - | |
| 226 | 151 | /** |
| 227 | - * @param $promotion | |
| 228 | - * @param $index | |
| 229 | - * @param array $categories | |
| 230 | - * | |
| 231 | - * @return array | |
| 232 | - */ | |
| 233 | - private static function get_panel_category_item( $promotion, $index, array $categories, bool $has_pro ): array { | |
| 234 | - if ( ! $has_pro ) { | |
| 235 | - $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data( | |
| 236 | - $promotion, | |
| 237 | - 'elementor/panel/' . $index . '/custom_promotion', | |
| 238 | - 'url' | |
| 239 | - ); | |
| 240 | - } else { | |
| 241 | - unset( $categories[ $index ]['promotion'] ); | |
| 242 | - } | |
| 243 | - | |
| 244 | - return $categories; | |
| 245 | - } | |
| 246 | - | |
| 247 | - /** | |
| 248 | 152 | * Get element title. |
| 249 | 153 | * |
| 250 | 154 | * Retrieve the element title. |
| 251 | 155 | * |
| @@ -262,16 +166,8 @@ | ||
| 262 | 166 | public static function get_plural_title() { |
| 263 | 167 | return static::get_title(); |
| 264 | 168 | } |
| 265 | 169 | |
| 266 | - public static function get_add_new_title() { | |
| 267 | - return sprintf( | |
| 268 | - /* translators: %s: Document title. */ | |
| 269 | - esc_html__( 'Add New %s', 'elementor' ), | |
| 270 | - static::get_title() | |
| 271 | - ); | |
| 272 | - } | |
| 273 | - | |
| 274 | 170 | /** |
| 275 | 171 | * Get property. |
| 276 | 172 | * |
| 277 | 173 | * Retrieve the document property. |
| @@ -303,18 +199,11 @@ | ||
| 303 | 199 | return get_called_class(); |
| 304 | 200 | } |
| 305 | 201 | |
| 306 | 202 | public static function get_create_url() { |
| 307 | - $properties = static::get_properties(); | |
| 203 | + $base_create_url = Plugin::$instance->documents->get_create_new_post_url( Source_Local::CPT ); | |
| 308 | 204 | |
| 309 | - // BC Support - Each document should define it own CPT this code is for BC support. | |
| 310 | - $cpt = Source_Local::CPT; | |
| 311 | - | |
| 312 | - if ( isset( $properties['cpt'][0] ) ) { | |
| 313 | - $cpt = $properties['cpt'][0]; | |
| 314 | - } | |
| 315 | - | |
| 316 | - return Plugin::$instance->documents->get_create_new_post_url( $cpt, static::get_type() ); | |
| 205 | + return add_query_arg( [ 'template_type' => static::get_type() ], $base_create_url ); | |
| 317 | 206 | } |
| 318 | 207 | |
| 319 | 208 | public function get_name() { |
| 320 | 209 | return static::get_type(); |
| @@ -358,15 +247,8 @@ | ||
| 358 | 247 | return $this->main_id; |
| 359 | 248 | } |
| 360 | 249 | |
| 361 | 250 | /** |
| 362 | - * @return null|Lock_Behavior | |
| 363 | - */ | |
| 364 | - public static function get_lock_behavior_v2() { | |
| 365 | - return null; | |
| 366 | - } | |
| 367 | - | |
| 368 | - /** | |
| 369 | 251 | * @since 2.0.0 |
| 370 | 252 | * @access public |
| 371 | 253 | * |
| 372 | 254 | * @param $data |
| @@ -418,16 +300,12 @@ | ||
| 418 | 300 | |
| 419 | 301 | if ( Plugin::$instance->preview->is_preview() ) { |
| 420 | 302 | $attributes['data-elementor-title'] = static::get_title(); |
| 421 | 303 | } else { |
| 422 | - $elementor_settings = $this->get_frontend_settings(); | |
| 423 | - if ( ! empty( $elementor_settings ) ) { | |
| 424 | - $attributes['data-elementor-settings'] = wp_json_encode( $elementor_settings ); | |
| 425 | - } | |
| 304 | + $attributes['data-elementor-settings'] = wp_json_encode( $this->get_frontend_settings() ); | |
| 426 | 305 | } |
| 427 | 306 | |
| 428 | - // apply this filter to allow the attributes to be modified by different sources | |
| 429 | - return apply_filters( 'elementor/document/wrapper_attributes', $attributes, $this ); | |
| 307 | + return $attributes; | |
| 430 | 308 | } |
| 431 | 309 | |
| 432 | 310 | /** |
| 433 | 311 | * @since 2.0.0 |
| @@ -437,12 +315,12 @@ | ||
| 437 | 315 | $main_post_id = $this->get_main_id(); |
| 438 | 316 | $document = $this; |
| 439 | 317 | |
| 440 | 318 | // Ajax request from editor. |
| 441 | - $initial_document_id = Utils::get_super_global_value( $_POST, 'initial_document_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 442 | - | |
| 443 | - if ( ! empty( $initial_document_id ) ) { | |
| 444 | - $document = Plugin::$instance->documents->get( $initial_document_id ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 319 | + // PHPCS - only reading the value from $_POST['initial_document_id']. | |
| 320 | + if ( ! empty( $_POST['initial_document_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 321 | + // PHPCS - only reading the value from $_POST['initial_document_id']. | |
| 322 | + $document = Plugin::$instance->documents->get( $_POST['initial_document_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 445 | 323 | } |
| 446 | 324 | |
| 447 | 325 | $url = get_preview_post_link( |
| 448 | 326 | $document->get_main_id(), |
| @@ -489,62 +367,8 @@ | ||
| 489 | 367 | return $url; |
| 490 | 368 | } |
| 491 | 369 | |
| 492 | 370 | /** |
| 493 | - * Get All Post Type URL | |
| 494 | - * | |
| 495 | - * Get url of the page which display all the posts of the current active document's post type. | |
| 496 | - * | |
| 497 | - * @since 3.7.0 | |
| 498 | - * | |
| 499 | - * @return string $url | |
| 500 | - */ | |
| 501 | - public function get_all_post_type_url() { | |
| 502 | - $post_type = get_post_type( $this->get_main_id() ); | |
| 503 | - | |
| 504 | - $url = get_admin_url() . 'edit.php'; | |
| 505 | - | |
| 506 | - if ( 'post' !== $post_type ) { | |
| 507 | - $url .= '?post_type=' . $post_type; | |
| 508 | - } | |
| 509 | - | |
| 510 | - /** | |
| 511 | - * Document "display all post type" URL. | |
| 512 | - * | |
| 513 | - * @since 3.7.0 | |
| 514 | - * | |
| 515 | - * @param string $url The URL. | |
| 516 | - * @param Document $this The document instance. | |
| 517 | - */ | |
| 518 | - $url = apply_filters( 'elementor/document/urls/all_post_type', $url, $this ); | |
| 519 | - | |
| 520 | - return $url; | |
| 521 | - } | |
| 522 | - | |
| 523 | - /** | |
| 524 | - * Get Main WP dashboard URL. | |
| 525 | - * | |
| 526 | - * @since 3.7.0 | |
| 527 | - * | |
| 528 | - * @return string $url | |
| 529 | - */ | |
| 530 | - protected function get_main_dashboard_url() { | |
| 531 | - $url = get_dashboard_url(); | |
| 532 | - | |
| 533 | - /** | |
| 534 | - * Document "Main Dashboard" URL. | |
| 535 | - * | |
| 536 | - * @since 3.7.0 | |
| 537 | - * | |
| 538 | - * @param string $url The URL. | |
| 539 | - * @param Document $this The document instance. | |
| 540 | - */ | |
| 541 | - $url = apply_filters( 'elementor/document/urls/main_dashboard', $url, $this ); | |
| 542 | - | |
| 543 | - return $url; | |
| 544 | - } | |
| 545 | - | |
| 546 | - /** | |
| 547 | 371 | * Get auto-saved post revision. |
| 548 | 372 | * |
| 549 | 373 | * Retrieve the auto-saved post revision that is newer than current post. |
| 550 | 374 | * |
| @@ -550,10 +374,12 @@ | ||
| 550 | 374 | * |
| 551 | 375 | * @since 2.0.0 |
| 552 | 376 | * @access public |
| 553 | 377 | * |
| 378 | + * | |
| 554 | 379 | * @return bool|Document |
| 555 | 380 | */ |
| 381 | + | |
| 556 | 382 | public function get_newer_autosave() { |
| 557 | 383 | $autosave = $this->get_autosave(); |
| 558 | 384 | |
| 559 | 385 | // Detect if there exists an autosave newer than the post. |
| @@ -608,12 +434,8 @@ | ||
| 608 | 434 | |
| 609 | 435 | if ( $autosave_id ) { |
| 610 | 436 | $document = Plugin::$instance->documents->get( $autosave_id ); |
| 611 | 437 | } elseif ( $create ) { |
| 612 | - if ( ! function_exists( 'wp_create_post_autosave' ) ) { | |
| 613 | - require_once ABSPATH . 'wp-admin/includes/post.php'; | |
| 614 | - } | |
| 615 | - | |
| 616 | 438 | $autosave_id = wp_create_post_autosave( [ |
| 617 | 439 | 'post_ID' => $this->post->ID, |
| 618 | 440 | 'post_type' => $this->post->post_type, |
| 619 | 441 | 'post_title' => $this->post->post_title, |
| @@ -642,9 +464,9 @@ | ||
| 642 | 464 | * Fired by `post_row_actions` and `page_row_actions` filters. |
| 643 | 465 | * |
| 644 | 466 | * @access public |
| 645 | 467 | * |
| 646 | - * @param array $actions An array of row action links. | |
| 468 | + * @param array $actions An array of row action links. | |
| 647 | 469 | * |
| 648 | 470 | * @return array An updated array of row action links. |
| 649 | 471 | */ |
| 650 | 472 | public function filter_admin_row_actions( $actions ) { |
| @@ -684,12 +506,10 @@ | ||
| 684 | 506 | if ( $locked_user ) { |
| 685 | 507 | $locked_user = $locked_user->display_name; |
| 686 | 508 | } |
| 687 | 509 | |
| 688 | - $post = $this->get_main_post(); | |
| 510 | + $post_type_object = get_post_type_object( $this->get_main_post()->post_type ); | |
| 689 | 511 | |
| 690 | - $post_type_object = get_post_type_object( $post->post_type ); | |
| 691 | - | |
| 692 | 512 | $settings = SettingsManager::get_settings_managers_config(); |
| 693 | 513 | |
| 694 | 514 | $config = [ |
| 695 | 515 | 'id' => $this->get_main_id(), |
| @@ -707,56 +527,23 @@ | ||
| 707 | 527 | // Deprecated config since 2.9.0. |
| 708 | 528 | 'locked' => $locked_user, |
| 709 | 529 | ], |
| 710 | 530 | 'urls' => [ |
| 711 | - 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(), // WP post type edit page | |
| 712 | - 'all_post_type' => $this->get_all_post_type_url(), | |
| 531 | + 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(), | |
| 713 | 532 | 'preview' => $this->get_preview_url(), |
| 714 | 533 | 'wp_preview' => $this->get_wp_preview_url(), |
| 715 | 534 | 'permalink' => $this->get_permalink(), |
| 716 | 535 | 'have_a_look' => $this->get_have_a_look_url(), |
| 717 | - 'main_dashboard' => $this->get_main_dashboard_url(), | |
| 718 | 536 | ], |
| 719 | 537 | ]; |
| 720 | 538 | |
| 721 | - $post_status_object = get_post_status_object( $post->post_status ); | |
| 722 | - | |
| 723 | - if ( $post_status_object ) { | |
| 724 | - $config['status'] = [ | |
| 725 | - 'value' => $post_status_object->name, | |
| 726 | - 'label' => $post_status_object->label, | |
| 727 | - ]; | |
| 728 | - } | |
| 729 | - | |
| 730 | - do_action( 'elementor/document/before_get_config', $this ); | |
| 731 | - | |
| 732 | 539 | 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(); | |
| 737 | - | |
| 738 | 540 | $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() ); | |
| 541 | + $config['widgets'] = Plugin::$instance->widgets_manager->get_widget_types_config(); | |
| 741 | 542 | } |
| 742 | 543 | |
| 743 | - $additional_config = []; | |
| 544 | + $additional_config = apply_filters( 'elementor/document/config', [], $this->get_main_id() ); | |
| 744 | 545 | |
| 745 | - /** | |
| 746 | - * Additional document configuration. | |
| 747 | - * | |
| 748 | - * Filters the document configuration by adding additional configuration. | |
| 749 | - * External developers can use this hook to add custom configuration in | |
| 750 | - * addition to Elementor's initial configuration. | |
| 751 | - * | |
| 752 | - * Use the $post_id to add custom configuration for different pages. | |
| 753 | - * | |
| 754 | - * @param array $additional_config The additional document configuration. | |
| 755 | - * @param int $post_id The post ID of the document. | |
| 756 | - */ | |
| 757 | - $additional_config = apply_filters( 'elementor/document/config', $additional_config, $this->get_main_id() ); | |
| 758 | - | |
| 759 | 546 | if ( ! empty( $additional_config ) ) { |
| 760 | 547 | $config = array_replace_recursive( $config, $additional_config ); |
| 761 | 548 | } |
| 762 | 549 | |
| @@ -768,16 +555,13 @@ | ||
| 768 | 555 | * @access protected |
| 769 | 556 | */ |
| 770 | 557 | protected function register_controls() { |
| 771 | 558 | $this->register_document_controls(); |
| 772 | - | |
| 773 | 559 | /** |
| 774 | 560 | * Register document controls. |
| 775 | 561 | * |
| 776 | 562 | * Fires after Elementor registers the document controls. |
| 777 | 563 | * |
| 778 | - * External developers can use this hook to add new controls to the document. | |
| 779 | - * | |
| 780 | 564 | * @since 2.0.0 |
| 781 | 565 | * |
| 782 | 566 | * @param Document $this The document instance. |
| 783 | 567 | */ |
| @@ -793,27 +577,14 @@ | ||
| 793 | 577 | * @return bool |
| 794 | 578 | */ |
| 795 | 579 | public function save( $data ) { |
| 796 | 580 | /** |
| 797 | - * Set locale to "C" to avoid issues with comma as decimal separator. | |
| 581 | + * Fires when document save starts on Elementor. | |
| 798 | 582 | * |
| 799 | - * @see https://github.com/elementor/elementor/issues/10992 | |
| 800 | - */ | |
| 801 | - $original_lc = setlocale( LC_NUMERIC, 0 ); | |
| 802 | - setlocale( LC_NUMERIC, 'C' ); | |
| 803 | - | |
| 804 | - /** | |
| 805 | - * Document save data. | |
| 583 | + * @param array $data. | |
| 584 | + * @param \Elementor\Core\Base\Document $this The current document. | |
| 806 | 585 | * |
| 807 | - * Filter the document data before saving process starts. | |
| 808 | - * | |
| 809 | - * External developers can use this hook to change the data before | |
| 810 | - * saving it to the database. | |
| 811 | - * | |
| 812 | 586 | * @since 3.3.0 |
| 813 | - * | |
| 814 | - * @param array $data The document data. | |
| 815 | - * @param \Elementor\Core\Base\Document $this The document instance. | |
| 816 | 587 | */ |
| 817 | 588 | $data = apply_filters( 'elementor/document/save/data', $data, $this ); |
| 818 | 589 | |
| 819 | 590 | $this->add_handle_revisions_changed_filter(); |
| @@ -836,11 +607,9 @@ | ||
| 836 | 607 | */ |
| 837 | 608 | do_action( 'elementor/document/before_save', $this, $data ); |
| 838 | 609 | |
| 839 | 610 | 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 | - } ); | |
| 611 | + $data = wp_kses_post_deep( $data ); | |
| 843 | 612 | } |
| 844 | 613 | |
| 845 | 614 | if ( ! empty( $data['settings'] ) ) { |
| 846 | 615 | if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) { |
| @@ -867,11 +636,8 @@ | ||
| 867 | 636 | $post_css = Post_CSS::create( $this->post->ID ); |
| 868 | 637 | |
| 869 | 638 | $post_css->delete(); |
| 870 | 639 | |
| 871 | - // Remove Document Cache | |
| 872 | - $this->delete_cache(); | |
| 873 | - | |
| 874 | 640 | /** |
| 875 | 641 | * After document save. |
| 876 | 642 | * |
| 877 | 643 | * Fires when document save is complete. |
| @@ -886,10 +652,8 @@ | ||
| 886 | 652 | $this->set_is_saving( false ); |
| 887 | 653 | |
| 888 | 654 | $this->remove_handle_revisions_changed_filter(); |
| 889 | 655 | |
| 890 | - setlocale( LC_NUMERIC, $original_lc ); | |
| 891 | - | |
| 892 | 656 | return true; |
| 893 | 657 | } |
| 894 | 658 | |
| 895 | 659 | public function refresh_post() { |
| @@ -925,9 +689,9 @@ | ||
| 925 | 689 | * |
| 926 | 690 | * @return bool Whether the post was built with Elementor. |
| 927 | 691 | */ |
| 928 | 692 | public function is_built_with_elementor() { |
| 929 | - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 693 | + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 930 | 694 | } |
| 931 | 695 | |
| 932 | 696 | /** |
| 933 | 697 | * Mark the post as "built with elementor" or not. |
| @@ -1036,16 +800,8 @@ | ||
| 1036 | 800 | |
| 1037 | 801 | return $meta; |
| 1038 | 802 | } |
| 1039 | 803 | |
| 1040 | - public function update_json_meta( $key, $value ) { | |
| 1041 | - return $this->update_meta( | |
| 1042 | - $key, | |
| 1043 | - // `wp_slash` in order to avoid the unslashing during the `update_post_meta` | |
| 1044 | - wp_slash( wp_json_encode( $value ) ) | |
| 1045 | - ); | |
| 1046 | - } | |
| 1047 | - | |
| 1048 | 804 | /** |
| 1049 | 805 | * @since 2.0.0 |
| 1050 | 806 | * @access public |
| 1051 | 807 | * |
| @@ -1052,10 +808,8 @@ | ||
| 1052 | 808 | * @param null $data |
| 1053 | 809 | * @param bool $with_html_content |
| 1054 | 810 | * |
| 1055 | 811 | * @return array |
| 1056 | - * | |
| 1057 | - * @throws \Exception If elements retrieval fails or data processing errors occur. | |
| 1058 | 812 | */ |
| 1059 | 813 | public function get_elements_raw_data( $data = null, $with_html_content = false ) { |
| 1060 | 814 | if ( ! static::get_property( 'has_elements' ) ) { |
| 1061 | 815 | return []; |
| @@ -1064,23 +818,8 @@ | ||
| 1064 | 818 | if ( is_null( $data ) ) { |
| 1065 | 819 | $data = $this->get_elements_data(); |
| 1066 | 820 | } |
| 1067 | 821 | |
| 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 | 822 | // Change the current documents, so widgets can use `documents->get_current` and other post data |
| 1084 | 823 | Plugin::$instance->documents->switch_to_document( $this ); |
| 1085 | 824 | |
| 1086 | 825 | $editor_data = []; |
| @@ -1085,15 +824,8 @@ | ||
| 1085 | 824 | |
| 1086 | 825 | $editor_data = []; |
| 1087 | 826 | |
| 1088 | 827 | foreach ( $data as $element_data ) { |
| 1089 | - if ( ! is_array( $element_data ) ) { | |
| 1090 | - throw new \Exception( 'Invalid data: ' . wp_json_encode( [ | |
| 1091 | - 'data' => $data, | |
| 1092 | - 'element' => $element_data, | |
| 1093 | - ] ) ); | |
| 1094 | - } | |
| 1095 | - | |
| 1096 | 828 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1097 | 829 | |
| 1098 | 830 | if ( ! $element ) { |
| 1099 | 831 | continue; |
| @@ -1098,17 +830,11 @@ | ||
| 1098 | 830 | if ( ! $element ) { |
| 1099 | 831 | continue; |
| 1100 | 832 | } |
| 1101 | 833 | |
| 1102 | - if ( $this->is_saving ) { | |
| 1103 | - $element_data = $element->get_data_for_save(); | |
| 1104 | - } else { | |
| 1105 | - $element_data = $element->get_raw_data( $with_html_content ); | |
| 1106 | - } | |
| 834 | + $editor_data[] = $element->get_raw_data( $with_html_content ); | |
| 835 | + } // End foreach(). | |
| 1107 | 836 | |
| 1108 | - $editor_data[] = $element_data; | |
| 1109 | - } | |
| 1110 | - | |
| 1111 | 837 | Plugin::$instance->documents->restore_document(); |
| 1112 | 838 | |
| 1113 | 839 | return $editor_data; |
| 1114 | 840 | } |
| @@ -1121,9 +847,9 @@ | ||
| 1121 | 847 | * |
| 1122 | 848 | * @return array |
| 1123 | 849 | */ |
| 1124 | 850 | public function get_elements_data( $status = self::STATUS_PUBLISH ) { |
| 1125 | - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 851 | + $elements = $this->get_json_meta( '_elementor_data' ); | |
| 1126 | 852 | |
| 1127 | 853 | if ( self::STATUS_DRAFT === $status ) { |
| 1128 | 854 | $autosave = $this->get_newer_autosave(); |
| 1129 | 855 | |
| @@ -1129,9 +855,9 @@ | ||
| 1129 | 855 | |
| 1130 | 856 | if ( is_object( $autosave ) ) { |
| 1131 | 857 | $autosave_elements = Plugin::$instance->documents |
| 1132 | 858 | ->get( $autosave->get_post()->ID ) |
| 1133 | - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 859 | + ->get_json_meta( '_elementor_data' ); | |
| 1134 | 860 | } |
| 1135 | 861 | } |
| 1136 | 862 | |
| 1137 | 863 | if ( Plugin::$instance->editor->is_edit_mode() ) { |
| @@ -1192,20 +918,28 @@ | ||
| 1192 | 918 | ]; |
| 1193 | 919 | } |
| 1194 | 920 | |
| 1195 | 921 | // TODO: Better coding to start template for editor |
| 1196 | - $converted_blocks = [ | |
| 922 | + return [ | |
| 1197 | 923 | [ |
| 1198 | 924 | 'id' => Utils::generate_random_string(), |
| 1199 | - 'elType' => $widget_type::get_type(), | |
| 1200 | - 'widgetType' => $widget_type->get_name(), | |
| 1201 | - 'settings' => $settings, | |
| 925 | + 'elType' => 'section', | |
| 926 | + 'elements' => [ | |
| 927 | + [ | |
| 928 | + 'id' => Utils::generate_random_string(), | |
| 929 | + 'elType' => 'column', | |
| 930 | + 'elements' => [ | |
| 931 | + [ | |
| 932 | + 'id' => Utils::generate_random_string(), | |
| 933 | + 'elType' => $widget_type::get_type(), | |
| 934 | + 'widgetType' => $widget_type->get_name(), | |
| 935 | + 'settings' => $settings, | |
| 936 | + ], | |
| 937 | + ], | |
| 938 | + ], | |
| 939 | + ], | |
| 1202 | 940 | ], |
| 1203 | 941 | ]; |
| 1204 | - | |
| 1205 | - return Plugin::$instance->experiments->is_feature_active( 'container' ) | |
| 1206 | - ? $this->get_container_elements_data( $converted_blocks ) | |
| 1207 | - : $this->get_sections_elements_data( $converted_blocks ); | |
| 1208 | 942 | } |
| 1209 | 943 | |
| 1210 | 944 | /** |
| 1211 | 945 | * @since 2.1.3 |
| @@ -1215,11 +949,20 @@ | ||
| 1215 | 949 | if ( ! $elements_data ) { |
| 1216 | 950 | $elements_data = $this->get_elements_data(); |
| 1217 | 951 | } |
| 1218 | 952 | |
| 953 | + $is_dom_optimization_active = Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ); | |
| 1219 | 954 | ?> |
| 1220 | 955 | <div <?php Utils::print_html_attributes( $this->get_container_attributes() ); ?>> |
| 1221 | - <?php $this->print_elements( $elements_data ); ?> | |
| 956 | + <?php if ( ! $is_dom_optimization_active ) { ?> | |
| 957 | + <div class="elementor-inner"> | |
| 958 | + <?php } ?> | |
| 959 | + <div class="elementor-section-wrap"> | |
| 960 | + <?php $this->print_elements( $elements_data ); ?> | |
| 961 | + </div> | |
| 962 | + <?php if ( ! $is_dom_optimization_active ) { ?> | |
| 963 | + </div> | |
| 964 | + <?php } ?> | |
| 1222 | 965 | </div> |
| 1223 | 966 | <?php |
| 1224 | 967 | } |
| 1225 | 968 | |
| @@ -1236,13 +979,10 @@ | ||
| 1236 | 979 | * @access public |
| 1237 | 980 | */ |
| 1238 | 981 | public function get_panel_page_settings() { |
| 1239 | 982 | return [ |
| 1240 | - 'title' => sprintf( | |
| 1241 | - /* translators: %s: Document title. */ | |
| 1242 | - esc_html__( '%s Settings', 'elementor' ), | |
| 1243 | - static::get_title() | |
| 1244 | - ), | |
| 983 | + /* translators: %s: Document title */ | |
| 984 | + 'title' => sprintf( esc_html__( '%s Settings', 'elementor' ), static::get_title() ), | |
| 1245 | 985 | ]; |
| 1246 | 986 | } |
| 1247 | 987 | |
| 1248 | 988 | /** |
| @@ -1282,78 +1022,9 @@ | ||
| 1282 | 1022 | |
| 1283 | 1023 | return $deleted && ! is_wp_error( $deleted ); |
| 1284 | 1024 | } |
| 1285 | 1025 | |
| 1286 | - public function force_delete() { | |
| 1287 | - $deleted = wp_delete_post( $this->post->ID, true ); | |
| 1288 | - | |
| 1289 | - return $deleted && ! is_wp_error( $deleted ); | |
| 1290 | - } | |
| 1291 | - | |
| 1292 | 1026 | /** |
| 1293 | - * On import update dynamic content (e.g. post and term IDs). | |
| 1294 | - * | |
| 1295 | - * @since 3.8.0 | |
| 1296 | - * | |
| 1297 | - * @param array $config The config of the passed element. | |
| 1298 | - * @param array $data The data that requires updating/replacement when imported. | |
| 1299 | - * @param array|null $controls The available controls. | |
| 1300 | - * | |
| 1301 | - * @return array Element data. | |
| 1302 | - */ | |
| 1303 | - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array { | |
| 1304 | - foreach ( $config as &$element_config ) { | |
| 1305 | - $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config ); | |
| 1306 | - | |
| 1307 | - if ( is_null( $element_instance ) ) { | |
| 1308 | - continue; | |
| 1309 | - } | |
| 1310 | - | |
| 1311 | - if ( $element_instance->has_own_method( 'on_import_replace_dynamic_content' ) ) { | |
| 1312 | - // TODO: Remove this check in the future. | |
| 1313 | - $element_config = $element_instance::on_import_replace_dynamic_content( $element_config, $data['post_ids'] ); | |
| 1314 | - } else { | |
| 1315 | - $element_config = $element_instance::on_import_update_dynamic_content( $element_config, $data, $element_instance->get_controls() ); | |
| 1316 | - } | |
| 1317 | - | |
| 1318 | - $element_config['elements'] = static::on_import_update_dynamic_content( $element_config['elements'], $data ); | |
| 1319 | - } | |
| 1320 | - | |
| 1321 | - return $config; | |
| 1322 | - } | |
| 1323 | - | |
| 1324 | - /** | |
| 1325 | - * Update dynamic settings in the document for import. | |
| 1326 | - * | |
| 1327 | - * @param array $settings The settings of the document. | |
| 1328 | - * @param array $config Import config to update the settings. | |
| 1329 | - * | |
| 1330 | - * @return array | |
| 1331 | - */ | |
| 1332 | - public function on_import_update_settings( array $settings, array $config ): array { | |
| 1333 | - $controls = $this->get_controls(); | |
| 1334 | - $controls_manager = Plugin::$instance->controls_manager; | |
| 1335 | - | |
| 1336 | - foreach ( $settings as $key => $value ) { | |
| 1337 | - | |
| 1338 | - if ( ! isset( $controls[ $key ] ) ) { | |
| 1339 | - continue; | |
| 1340 | - } | |
| 1341 | - | |
| 1342 | - $control = $controls[ $key ]; | |
| 1343 | - $control_instance = $controls_manager->get_control( $control['type'] ); | |
| 1344 | - | |
| 1345 | - if ( ! $control_instance ) { | |
| 1346 | - continue; | |
| 1347 | - } | |
| 1348 | - | |
| 1349 | - $settings[ $key ] = $control_instance->on_import_update_settings( $value, $control, $config ); | |
| 1350 | - } | |
| 1351 | - | |
| 1352 | - return $settings; | |
| 1353 | - } | |
| 1354 | - | |
| 1355 | - /** | |
| 1356 | 1027 | * Save editor elements. |
| 1357 | 1028 | * |
| 1358 | 1029 | * Save data from the editor to the database. |
| 1359 | 1030 | * |
| @@ -1368,9 +1039,9 @@ | ||
| 1368 | 1039 | // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1369 | 1040 | $json_value = wp_slash( wp_json_encode( $editor_data ) ); |
| 1370 | 1041 | |
| 1371 | 1042 | // 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 ); | |
| 1043 | + $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value ); | |
| 1373 | 1044 | |
| 1374 | 1045 | /** |
| 1375 | 1046 | * Before saving data. |
| 1376 | 1047 | * |
| @@ -1438,8 +1109,9 @@ | ||
| 1438 | 1109 | * |
| 1439 | 1110 | * @since 2.5.12 |
| 1440 | 1111 | * |
| 1441 | 1112 | * @param \Elementor\Core\Base\Document $this The current document. |
| 1113 | + * | |
| 1442 | 1114 | */ |
| 1443 | 1115 | do_action( 'elementor/document/save_version', $this ); |
| 1444 | 1116 | } |
| 1445 | 1117 | } |
| @@ -1476,9 +1148,9 @@ | ||
| 1476 | 1148 | * @since 2.0.4 |
| 1477 | 1149 | * @access public |
| 1478 | 1150 | * |
| 1479 | 1151 | * @param string $key Meta data key. |
| 1480 | - * @param mixed $value Meta data value. | |
| 1152 | + * @param string $value Meta data value. | |
| 1481 | 1153 | * |
| 1482 | 1154 | * @return bool|int |
| 1483 | 1155 | */ |
| 1484 | 1156 | public function update_main_meta( $key, $value ) { |
| @@ -1553,21 +1225,13 @@ | ||
| 1553 | 1225 | $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) ); |
| 1554 | 1226 | $display_name = get_the_author_meta( 'display_name', $post->post_author ); |
| 1555 | 1227 | |
| 1556 | 1228 | if ( $autosave_post || 'revision' === $post->post_type ) { |
| 1557 | - $last_edited = sprintf( | |
| 1558 | - /* translators: 1: Saving date, 2: Author display name. */ | |
| 1559 | - esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), | |
| 1560 | - '<time>' . $date . '</time>', | |
| 1561 | - $display_name | |
| 1562 | - ); | |
| 1229 | + /* translators: 1: Saving date, 2: Author display name */ | |
| 1230 | + $last_edited = sprintf( esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name ); | |
| 1563 | 1231 | } else { |
| 1564 | - $last_edited = sprintf( | |
| 1565 | - /* translators: 1: Editing date, 2: Author display name. */ | |
| 1566 | - esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), | |
| 1567 | - '<time>' . $date . '</time>', | |
| 1568 | - $display_name | |
| 1569 | - ); | |
| 1232 | + /* translators: 1: Editing date, 2: Author display name */ | |
| 1233 | + $last_edited = sprintf( esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), '<time>' . $date . '</time>', $display_name ); | |
| 1570 | 1234 | } |
| 1571 | 1235 | |
| 1572 | 1236 | return $last_edited; |
| 1573 | 1237 | } |
| @@ -1606,9 +1270,9 @@ | ||
| 1606 | 1270 | } else { |
| 1607 | 1271 | $this->post = get_post( $data['post_id'] ); |
| 1608 | 1272 | |
| 1609 | 1273 | 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 | |
| 1274 | + throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND ); | |
| 1611 | 1275 | } |
| 1612 | 1276 | } |
| 1613 | 1277 | |
| 1614 | 1278 | // Each Control_Stack is based on a unique ID. |
| @@ -1626,9 +1290,9 @@ | ||
| 1626 | 1290 | |
| 1627 | 1291 | parent::__construct( $data ); |
| 1628 | 1292 | } |
| 1629 | 1293 | |
| 1630 | - /** | |
| 1294 | + /* | |
| 1631 | 1295 | * Get Export Data |
| 1632 | 1296 | * |
| 1633 | 1297 | * Filters a document's data on export |
| 1634 | 1298 | * |
| @@ -1640,13 +1304,11 @@ | ||
| 1640 | 1304 | public function get_export_data() { |
| 1641 | 1305 | $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) { |
| 1642 | 1306 | $element_data['id'] = Utils::generate_random_string(); |
| 1643 | 1307 | |
| 1644 | - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data ); | |
| 1645 | - | |
| 1646 | 1308 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1647 | 1309 | |
| 1648 | - // If the widget/element does not exist, like a plugin that creates a widget but deactivated. | |
| 1310 | + // If the widget/element isn't exist, like a plugin that creates a widget but deactivated | |
| 1649 | 1311 | if ( ! $element ) { |
| 1650 | 1312 | return null; |
| 1651 | 1313 | } |
| 1652 | 1314 | |
| @@ -1667,9 +1329,9 @@ | ||
| 1667 | 1329 | 'thumbnail' => get_the_post_thumbnail_url( $this->post ), |
| 1668 | 1330 | ]; |
| 1669 | 1331 | } |
| 1670 | 1332 | |
| 1671 | - /** | |
| 1333 | + /* | |
| 1672 | 1334 | * Get Import Data |
| 1673 | 1335 | * |
| 1674 | 1336 | * Filters a document's data on import |
| 1675 | 1337 | * |
| @@ -1734,12 +1396,10 @@ | ||
| 1734 | 1396 | } |
| 1735 | 1397 | } |
| 1736 | 1398 | } |
| 1737 | 1399 | |
| 1738 | - public function process_element_import_export( Controls_Stack $element, $method, $element_data = null ) { | |
| 1739 | - if ( null === $element_data ) { | |
| 1740 | - $element_data = $element->get_data(); | |
| 1741 | - } | |
| 1400 | + private function process_element_import_export( Controls_Stack $element, $method ) { | |
| 1401 | + $element_data = $element->get_data(); | |
| 1742 | 1402 | |
| 1743 | 1403 | if ( method_exists( $element, $method ) ) { |
| 1744 | 1404 | // TODO: Use the internal element data without parameters. |
| 1745 | 1405 | $element_data = $element->{$method}( $element_data ); |
| @@ -1752,17 +1412,10 @@ | ||
| 1752 | 1412 | if ( ! $control_class ) { |
| 1753 | 1413 | return $element_data; |
| 1754 | 1414 | } |
| 1755 | 1415 | |
| 1756 | - // Do not add default value to the final settings, if there is no value at the | |
| 1757 | - // data before the methods `on_import` or `on_export` called. | |
| 1758 | - $has_value = isset( $element_data['settings'][ $control['name'] ] ); | |
| 1759 | - | |
| 1760 | - if ( $has_value && method_exists( $control_class, $method ) ) { | |
| 1761 | - $element_data['settings'][ $control['name'] ] = $control_class->{$method}( | |
| 1762 | - $element_data['settings'][ $control['name'] ], | |
| 1763 | - $control | |
| 1764 | - ); | |
| 1416 | + if ( method_exists( $control_class, $method ) ) { | |
| 1417 | + $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ), $control ); | |
| 1765 | 1418 | } |
| 1766 | 1419 | |
| 1767 | 1420 | // On Export, check if the control has an argument 'export' => false. |
| 1768 | 1421 | if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) { |
| @@ -1813,92 +1466,18 @@ | ||
| 1813 | 1466 | } |
| 1814 | 1467 | |
| 1815 | 1468 | /** |
| 1816 | 1469 | * @since 2.1.3 |
| 1817 | - * @access public | |
| 1470 | + * @access protected | |
| 1818 | 1471 | */ |
| 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(); | |
| 1472 | + protected function print_elements( $elements_data ) { | |
| 1473 | + // Collect all data updaters that should be updated on runtime. | |
| 1474 | + $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions(); | |
| 1823 | 1475 | |
| 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; | |
| 1476 | + if ( $runtime_elements_iteration_actions ) { | |
| 1477 | + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); | |
| 1835 | 1478 | } |
| 1836 | 1479 | |
| 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 | 1480 | foreach ( $elements_data as $element_data ) { |
| 1902 | 1481 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1903 | 1482 | |
| 1904 | 1483 | if ( ! $element ) { |
| @@ -1908,75 +1487,8 @@ | ||
| 1908 | 1487 | $element->print_element(); |
| 1909 | 1488 | } |
| 1910 | 1489 | } |
| 1911 | 1490 | |
| 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 | 1491 | protected function register_document_controls() { |
| 1980 | 1492 | $this->start_controls_section( |
| 1981 | 1493 | 'document_settings', |
| 1982 | 1494 | [ |
| @@ -1991,8 +1503,9 @@ | ||
| 1991 | 1503 | 'label' => esc_html__( 'Title', 'elementor' ), |
| 1992 | 1504 | 'type' => Controls_Manager::TEXT, |
| 1993 | 1505 | 'default' => $this->post->post_title, |
| 1994 | 1506 | 'label_block' => true, |
| 1507 | + 'separator' => 'none', | |
| 1995 | 1508 | ] |
| 1996 | 1509 | ); |
| 1997 | 1510 | |
| 1998 | 1511 | $post_type_object = get_post_type_object( $this->post->post_type ); |
| @@ -2107,10 +1620,6 @@ | ||
| 2107 | 1620 | $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this ); |
| 2108 | 1621 | } |
| 2109 | 1622 | |
| 2110 | 1623 | return $this->elements_iteration_actions; |
| 2111 | - } | |
| 2112 | - | |
| 2113 | - public function get_elementor_version() { | |
| 2114 | - return $this->get_main_meta( '_elementor_version' ); | |
| 2115 | 1624 | } |
| 2116 | 1625 | } |