| @@ -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,16 +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 | - const UNEDITABLE_WITH_ELEMENTOR_TYPES = [ 'kit' ]; | |
| 51 | - | |
| 52 | 42 | /** |
| 53 | 43 | * Document publish status. |
| 54 | 44 | */ |
| 55 | 45 | const STATUS_PUBLISH = 'publish'; |
| @@ -73,11 +63,9 @@ | ||
| 73 | 63 | * Document pending status. |
| 74 | 64 | */ |
| 75 | 65 | const STATUS_PENDING = 'pending'; |
| 76 | 66 | |
| 77 | - /** | |
| 78 | - * @var int | |
| 79 | - */ | |
| 67 | + | |
| 80 | 68 | private $main_id; |
| 81 | 69 | |
| 82 | 70 | /** |
| 83 | 71 | * @var bool |
| @@ -103,44 +91,8 @@ | ||
| 103 | 91 | */ |
| 104 | 92 | protected $post; |
| 105 | 93 | |
| 106 | 94 | /** |
| 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 | 95 | * @since 2.1.0 |
| 144 | 96 | * @access protected |
| 145 | 97 | * @static |
| 146 | 98 | */ |
| @@ -166,15 +118,8 @@ | ||
| 166 | 118 | 'edit_capability' => '', |
| 167 | 119 | 'show_in_finder' => true, |
| 168 | 120 | 'show_on_admin_bar' => true, |
| 169 | 121 | '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 | 122 | ]; |
| 178 | 123 | } |
| 179 | 124 | |
| 180 | 125 | /** |
| @@ -191,70 +136,20 @@ | ||
| 191 | 136 | |
| 192 | 137 | return [ |
| 193 | 138 | 'title' => static::get_title(), // JS Container title. |
| 194 | 139 | 'widgets_settings' => [], |
| 195 | - 'elements_categories' => self::get_filtered_editor_panel_categories(), | |
| 140 | + 'elements_categories' => static::get_editor_panel_categories(), | |
| 196 | 141 | 'default_route' => $default_route, |
| 197 | 142 | 'has_elements' => static::get_property( 'has_elements' ), |
| 198 | 143 | 'support_kit' => static::get_property( 'support_kit' ), |
| 199 | 144 | 'messages' => [ |
| 200 | - 'publish_notification' => sprintf( | |
| 201 | - /* translators: %s: Document title. */ | |
| 202 | - esc_html__( 'Hurray! Your %s is live.', 'elementor' ), | |
| 203 | - static::get_title() | |
| 204 | - ), | |
| 145 | + /* translators: %s: the document title. */ | |
| 146 | + 'publish_notification' => sprintf( esc_html__( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ), | |
| 205 | 147 | ], |
| 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 | 148 | ]; |
| 213 | 149 | } |
| 214 | 150 | |
| 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 | 151 | /** |
| 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 | 152 | * Get element title. |
| 258 | 153 | * |
| 259 | 154 | * Retrieve the element title. |
| 260 | 155 | * |
| @@ -271,16 +166,8 @@ | ||
| 271 | 166 | public static function get_plural_title() { |
| 272 | 167 | return static::get_title(); |
| 273 | 168 | } |
| 274 | 169 | |
| 275 | - 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 | - ); | |
| 281 | - } | |
| 282 | - | |
| 283 | 170 | /** |
| 284 | 171 | * Get property. |
| 285 | 172 | * |
| 286 | 173 | * Retrieve the document property. |
| @@ -312,18 +199,11 @@ | ||
| 312 | 199 | return get_called_class(); |
| 313 | 200 | } |
| 314 | 201 | |
| 315 | 202 | public static function get_create_url() { |
| 316 | - $properties = static::get_properties(); | |
| 203 | + $base_create_url = Plugin::$instance->documents->get_create_new_post_url( Source_Local::CPT ); | |
| 317 | 204 | |
| 318 | - // BC Support - Each document should define it own CPT this code is for BC support. | |
| 319 | - $cpt = Source_Local::CPT; | |
| 320 | - | |
| 321 | - if ( isset( $properties['cpt'][0] ) ) { | |
| 322 | - $cpt = $properties['cpt'][0]; | |
| 323 | - } | |
| 324 | - | |
| 325 | - 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 ); | |
| 326 | 206 | } |
| 327 | 207 | |
| 328 | 208 | public function get_name() { |
| 329 | 209 | return static::get_type(); |
| @@ -367,15 +247,8 @@ | ||
| 367 | 247 | return $this->main_id; |
| 368 | 248 | } |
| 369 | 249 | |
| 370 | 250 | /** |
| 371 | - * @return null|Lock_Behavior | |
| 372 | - */ | |
| 373 | - public static function get_lock_behavior_v2() { | |
| 374 | - return null; | |
| 375 | - } | |
| 376 | - | |
| 377 | - /** | |
| 378 | 251 | * @since 2.0.0 |
| 379 | 252 | * @access public |
| 380 | 253 | * |
| 381 | 254 | * @param $data |
| @@ -427,16 +300,12 @@ | ||
| 427 | 300 | |
| 428 | 301 | if ( Plugin::$instance->preview->is_preview() ) { |
| 429 | 302 | $attributes['data-elementor-title'] = static::get_title(); |
| 430 | 303 | } else { |
| 431 | - $elementor_settings = $this->get_frontend_settings(); | |
| 432 | - if ( ! empty( $elementor_settings ) ) { | |
| 433 | - $attributes['data-elementor-settings'] = wp_json_encode( $elementor_settings ); | |
| 434 | - } | |
| 304 | + $attributes['data-elementor-settings'] = wp_json_encode( $this->get_frontend_settings() ); | |
| 435 | 305 | } |
| 436 | 306 | |
| 437 | - // apply this filter to allow the attributes to be modified by different sources | |
| 438 | - return apply_filters( 'elementor/document/wrapper_attributes', $attributes, $this ); | |
| 307 | + return $attributes; | |
| 439 | 308 | } |
| 440 | 309 | |
| 441 | 310 | /** |
| 442 | 311 | * @since 2.0.0 |
| @@ -446,12 +315,12 @@ | ||
| 446 | 315 | $main_post_id = $this->get_main_id(); |
| 447 | 316 | $document = $this; |
| 448 | 317 | |
| 449 | 318 | // Ajax request from editor. |
| 450 | - $initial_document_id = Utils::get_super_global_value( $_POST, 'initial_document_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 451 | - | |
| 452 | - if ( ! empty( $initial_document_id ) ) { | |
| 453 | - $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 | |
| 454 | 323 | } |
| 455 | 324 | |
| 456 | 325 | $url = get_preview_post_link( |
| 457 | 326 | $document->get_main_id(), |
| @@ -498,62 +367,8 @@ | ||
| 498 | 367 | return $url; |
| 499 | 368 | } |
| 500 | 369 | |
| 501 | 370 | /** |
| 502 | - * Get All Post Type URL | |
| 503 | - * | |
| 504 | - * Get url of the page which display all the posts of the current active document's post type. | |
| 505 | - * | |
| 506 | - * @since 3.7.0 | |
| 507 | - * | |
| 508 | - * @return string $url | |
| 509 | - */ | |
| 510 | - public function get_all_post_type_url() { | |
| 511 | - $post_type = get_post_type( $this->get_main_id() ); | |
| 512 | - | |
| 513 | - $url = get_admin_url() . 'edit.php'; | |
| 514 | - | |
| 515 | - if ( 'post' !== $post_type ) { | |
| 516 | - $url .= '?post_type=' . $post_type; | |
| 517 | - } | |
| 518 | - | |
| 519 | - /** | |
| 520 | - * Document "display all post type" URL. | |
| 521 | - * | |
| 522 | - * @since 3.7.0 | |
| 523 | - * | |
| 524 | - * @param string $url The URL. | |
| 525 | - * @param Document $this The document instance. | |
| 526 | - */ | |
| 527 | - $url = apply_filters( 'elementor/document/urls/all_post_type', $url, $this ); | |
| 528 | - | |
| 529 | - return $url; | |
| 530 | - } | |
| 531 | - | |
| 532 | - /** | |
| 533 | - * Get Main WP dashboard URL. | |
| 534 | - * | |
| 535 | - * @since 3.7.0 | |
| 536 | - * | |
| 537 | - * @return string $url | |
| 538 | - */ | |
| 539 | - protected function get_main_dashboard_url() { | |
| 540 | - $url = get_dashboard_url(); | |
| 541 | - | |
| 542 | - /** | |
| 543 | - * Document "Main Dashboard" URL. | |
| 544 | - * | |
| 545 | - * @since 3.7.0 | |
| 546 | - * | |
| 547 | - * @param string $url The URL. | |
| 548 | - * @param Document $this The document instance. | |
| 549 | - */ | |
| 550 | - $url = apply_filters( 'elementor/document/urls/main_dashboard', $url, $this ); | |
| 551 | - | |
| 552 | - return $url; | |
| 553 | - } | |
| 554 | - | |
| 555 | - /** | |
| 556 | 371 | * Get auto-saved post revision. |
| 557 | 372 | * |
| 558 | 373 | * Retrieve the auto-saved post revision that is newer than current post. |
| 559 | 374 | * |
| @@ -559,10 +374,12 @@ | ||
| 559 | 374 | * |
| 560 | 375 | * @since 2.0.0 |
| 561 | 376 | * @access public |
| 562 | 377 | * |
| 378 | + * | |
| 563 | 379 | * @return bool|Document |
| 564 | 380 | */ |
| 381 | + | |
| 565 | 382 | public function get_newer_autosave() { |
| 566 | 383 | $autosave = $this->get_autosave(); |
| 567 | 384 | |
| 568 | 385 | // Detect if there exists an autosave newer than the post. |
| @@ -617,12 +434,8 @@ | ||
| 617 | 434 | |
| 618 | 435 | if ( $autosave_id ) { |
| 619 | 436 | $document = Plugin::$instance->documents->get( $autosave_id ); |
| 620 | 437 | } elseif ( $create ) { |
| 621 | - if ( ! function_exists( 'wp_create_post_autosave' ) ) { | |
| 622 | - require_once ABSPATH . 'wp-admin/includes/post.php'; | |
| 623 | - } | |
| 624 | - | |
| 625 | 438 | $autosave_id = wp_create_post_autosave( [ |
| 626 | 439 | 'post_ID' => $this->post->ID, |
| 627 | 440 | 'post_type' => $this->post->post_type, |
| 628 | 441 | 'post_title' => $this->post->post_title, |
| @@ -651,14 +464,14 @@ | ||
| 651 | 464 | * Fired by `post_row_actions` and `page_row_actions` filters. |
| 652 | 465 | * |
| 653 | 466 | * @access public |
| 654 | 467 | * |
| 655 | - * @param array $actions An array of row action links. | |
| 468 | + * @param array $actions An array of row action links. | |
| 656 | 469 | * |
| 657 | 470 | * @return array An updated array of row action links. |
| 658 | 471 | */ |
| 659 | 472 | public function filter_admin_row_actions( $actions ) { |
| 660 | - if ( $this->is_editable_with_elementor() ) { | |
| 473 | + if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) { | |
| 661 | 474 | $actions['edit_with_elementor'] = sprintf( |
| 662 | 475 | '<a href="%1$s">%2$s</a>', |
| 663 | 476 | $this->get_edit_url(), |
| 664 | 477 | __( 'Edit with Elementor', 'elementor' ) |
| @@ -667,16 +480,8 @@ | ||
| 667 | 480 | |
| 668 | 481 | return $actions; |
| 669 | 482 | } |
| 670 | 483 | |
| 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 | 484 | /** |
| 680 | 485 | * @since 2.0.0 |
| 681 | 486 | * @access public |
| 682 | 487 | */ |
| @@ -701,12 +506,10 @@ | ||
| 701 | 506 | if ( $locked_user ) { |
| 702 | 507 | $locked_user = $locked_user->display_name; |
| 703 | 508 | } |
| 704 | 509 | |
| 705 | - $post = $this->get_main_post(); | |
| 510 | + $post_type_object = get_post_type_object( $this->get_main_post()->post_type ); | |
| 706 | 511 | |
| 707 | - $post_type_object = get_post_type_object( $post->post_type ); | |
| 708 | - | |
| 709 | 512 | $settings = SettingsManager::get_settings_managers_config(); |
| 710 | 513 | |
| 711 | 514 | $config = [ |
| 712 | 515 | 'id' => $this->get_main_id(), |
| @@ -724,56 +527,23 @@ | ||
| 724 | 527 | // Deprecated config since 2.9.0. |
| 725 | 528 | 'locked' => $locked_user, |
| 726 | 529 | ], |
| 727 | 530 | 'urls' => [ |
| 728 | - 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(), // WP post type edit page | |
| 729 | - 'all_post_type' => $this->get_all_post_type_url(), | |
| 531 | + 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(), | |
| 730 | 532 | 'preview' => $this->get_preview_url(), |
| 731 | 533 | 'wp_preview' => $this->get_wp_preview_url(), |
| 732 | 534 | 'permalink' => $this->get_permalink(), |
| 733 | 535 | 'have_a_look' => $this->get_have_a_look_url(), |
| 734 | - 'main_dashboard' => $this->get_main_dashboard_url(), | |
| 735 | 536 | ], |
| 736 | 537 | ]; |
| 737 | 538 | |
| 738 | - $post_status_object = get_post_status_object( $post->post_status ); | |
| 739 | - | |
| 740 | - if ( $post_status_object ) { | |
| 741 | - $config['status'] = [ | |
| 742 | - 'value' => $post_status_object->name, | |
| 743 | - 'label' => $post_status_object->label, | |
| 744 | - ]; | |
| 745 | - } | |
| 746 | - | |
| 747 | - do_action( 'elementor/document/before_get_config', $this ); | |
| 748 | - | |
| 749 | 539 | 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(); | |
| 754 | - | |
| 755 | 540 | $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() ); | |
| 541 | + $config['widgets'] = Plugin::$instance->widgets_manager->get_widget_types_config(); | |
| 758 | 542 | } |
| 759 | 543 | |
| 760 | - $additional_config = []; | |
| 544 | + $additional_config = apply_filters( 'elementor/document/config', [], $this->get_main_id() ); | |
| 761 | 545 | |
| 762 | - /** | |
| 763 | - * Additional document configuration. | |
| 764 | - * | |
| 765 | - * Filters the document configuration by adding additional configuration. | |
| 766 | - * External developers can use this hook to add custom configuration in | |
| 767 | - * addition to Elementor's initial configuration. | |
| 768 | - * | |
| 769 | - * Use the $post_id to add custom configuration for different pages. | |
| 770 | - * | |
| 771 | - * @param array $additional_config The additional document configuration. | |
| 772 | - * @param int $post_id The post ID of the document. | |
| 773 | - */ | |
| 774 | - $additional_config = apply_filters( 'elementor/document/config', $additional_config, $this->get_main_id() ); | |
| 775 | - | |
| 776 | 546 | if ( ! empty( $additional_config ) ) { |
| 777 | 547 | $config = array_replace_recursive( $config, $additional_config ); |
| 778 | 548 | } |
| 779 | 549 | |
| @@ -785,16 +555,13 @@ | ||
| 785 | 555 | * @access protected |
| 786 | 556 | */ |
| 787 | 557 | protected function register_controls() { |
| 788 | 558 | $this->register_document_controls(); |
| 789 | - | |
| 790 | 559 | /** |
| 791 | 560 | * Register document controls. |
| 792 | 561 | * |
| 793 | 562 | * Fires after Elementor registers the document controls. |
| 794 | 563 | * |
| 795 | - * External developers can use this hook to add new controls to the document. | |
| 796 | - * | |
| 797 | 564 | * @since 2.0.0 |
| 798 | 565 | * |
| 799 | 566 | * @param Document $this The document instance. |
| 800 | 567 | */ |
| @@ -810,27 +577,14 @@ | ||
| 810 | 577 | * @return bool |
| 811 | 578 | */ |
| 812 | 579 | public function save( $data ) { |
| 813 | 580 | /** |
| 814 | - * Set locale to "C" to avoid issues with comma as decimal separator. | |
| 581 | + * Fires when document save starts on Elementor. | |
| 815 | 582 | * |
| 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 | - * Document save data. | |
| 583 | + * @param array $data. | |
| 584 | + * @param \Elementor\Core\Base\Document $this The current document. | |
| 823 | 585 | * |
| 824 | - * Filter the document data before saving process starts. | |
| 825 | - * | |
| 826 | - * External developers can use this hook to change the data before | |
| 827 | - * saving it to the database. | |
| 828 | - * | |
| 829 | 586 | * @since 3.3.0 |
| 830 | - * | |
| 831 | - * @param array $data The document data. | |
| 832 | - * @param \Elementor\Core\Base\Document $this The document instance. | |
| 833 | 587 | */ |
| 834 | 588 | $data = apply_filters( 'elementor/document/save/data', $data, $this ); |
| 835 | 589 | |
| 836 | 590 | $this->add_handle_revisions_changed_filter(); |
| @@ -853,9 +607,9 @@ | ||
| 853 | 607 | */ |
| 854 | 608 | do_action( 'elementor/document/before_save', $this, $data ); |
| 855 | 609 | |
| 856 | 610 | if ( ! current_user_can( 'unfiltered_html' ) ) { |
| 857 | - $data = Utils::kses_post_deep( $data ); | |
| 611 | + $data = wp_kses_post_deep( $data ); | |
| 858 | 612 | } |
| 859 | 613 | |
| 860 | 614 | if ( ! empty( $data['settings'] ) ) { |
| 861 | 615 | if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) { |
| @@ -882,11 +636,8 @@ | ||
| 882 | 636 | $post_css = Post_CSS::create( $this->post->ID ); |
| 883 | 637 | |
| 884 | 638 | $post_css->delete(); |
| 885 | 639 | |
| 886 | - // Remove Document Cache | |
| 887 | - $this->delete_cache(); | |
| 888 | - | |
| 889 | 640 | /** |
| 890 | 641 | * After document save. |
| 891 | 642 | * |
| 892 | 643 | * Fires when document save is complete. |
| @@ -901,10 +652,8 @@ | ||
| 901 | 652 | $this->set_is_saving( false ); |
| 902 | 653 | |
| 903 | 654 | $this->remove_handle_revisions_changed_filter(); |
| 904 | 655 | |
| 905 | - setlocale( LC_NUMERIC, $original_lc ); | |
| 906 | - | |
| 907 | 656 | return true; |
| 908 | 657 | } |
| 909 | 658 | |
| 910 | 659 | public function refresh_post() { |
| @@ -940,9 +689,9 @@ | ||
| 940 | 689 | * |
| 941 | 690 | * @return bool Whether the post was built with Elementor. |
| 942 | 691 | */ |
| 943 | 692 | public function is_built_with_elementor() { |
| 944 | - return (bool) $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 693 | + return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); | |
| 945 | 694 | } |
| 946 | 695 | |
| 947 | 696 | /** |
| 948 | 697 | * Mark the post as "built with elementor" or not. |
| @@ -1051,16 +800,8 @@ | ||
| 1051 | 800 | |
| 1052 | 801 | return $meta; |
| 1053 | 802 | } |
| 1054 | 803 | |
| 1055 | - public function update_json_meta( $key, $value ) { | |
| 1056 | - return $this->update_meta( | |
| 1057 | - $key, | |
| 1058 | - // `wp_slash` in order to avoid the unslashing during the `update_post_meta` | |
| 1059 | - wp_slash( wp_json_encode( $value ) ) | |
| 1060 | - ); | |
| 1061 | - } | |
| 1062 | - | |
| 1063 | 804 | /** |
| 1064 | 805 | * @since 2.0.0 |
| 1065 | 806 | * @access public |
| 1066 | 807 | * |
| @@ -1067,10 +808,8 @@ | ||
| 1067 | 808 | * @param null $data |
| 1068 | 809 | * @param bool $with_html_content |
| 1069 | 810 | * |
| 1070 | 811 | * @return array |
| 1071 | - * | |
| 1072 | - * @throws \Exception If elements retrieval fails or data processing errors occur. | |
| 1073 | 812 | */ |
| 1074 | 813 | public function get_elements_raw_data( $data = null, $with_html_content = false ) { |
| 1075 | 814 | if ( ! static::get_property( 'has_elements' ) ) { |
| 1076 | 815 | return []; |
| @@ -1079,23 +818,8 @@ | ||
| 1079 | 818 | if ( is_null( $data ) ) { |
| 1080 | 819 | $data = $this->get_elements_data(); |
| 1081 | 820 | } |
| 1082 | 821 | |
| 1083 | - /** | |
| 1084 | - * Filters document elements data after loading. | |
| 1085 | - * | |
| 1086 | - * Allows modification of elements data when loading (not saving). | |
| 1087 | - * Useful for migrations, transformations, or data enrichment. | |
| 1088 | - * | |
| 1089 | - * @since 3.35.0 | |
| 1090 | - * | |
| 1091 | - * @param array $data The elements data array. | |
| 1092 | - * @param \Elementor\Core\Base\Document $document The document instance. | |
| 1093 | - */ | |
| 1094 | - if ( ! $this->is_saving ) { | |
| 1095 | - $data = apply_filters( 'elementor/document/load/data', $data, $this ); | |
| 1096 | - } | |
| 1097 | - | |
| 1098 | 822 | // Change the current documents, so widgets can use `documents->get_current` and other post data |
| 1099 | 823 | Plugin::$instance->documents->switch_to_document( $this ); |
| 1100 | 824 | |
| 1101 | 825 | $editor_data = []; |
| @@ -1100,15 +824,8 @@ | ||
| 1100 | 824 | |
| 1101 | 825 | $editor_data = []; |
| 1102 | 826 | |
| 1103 | 827 | foreach ( $data as $element_data ) { |
| 1104 | - if ( ! is_array( $element_data ) ) { | |
| 1105 | - throw new \Exception( 'Invalid data: ' . wp_json_encode( [ | |
| 1106 | - 'data' => $data, | |
| 1107 | - 'element' => $element_data, | |
| 1108 | - ] ) ); | |
| 1109 | - } | |
| 1110 | - | |
| 1111 | 828 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1112 | 829 | |
| 1113 | 830 | if ( ! $element ) { |
| 1114 | 831 | continue; |
| @@ -1113,17 +830,11 @@ | ||
| 1113 | 830 | if ( ! $element ) { |
| 1114 | 831 | continue; |
| 1115 | 832 | } |
| 1116 | 833 | |
| 1117 | - if ( $this->is_saving ) { | |
| 1118 | - $element_data = $element->get_data_for_save(); | |
| 1119 | - } else { | |
| 1120 | - $element_data = $element->get_raw_data( $with_html_content ); | |
| 1121 | - } | |
| 834 | + $editor_data[] = $element->get_raw_data( $with_html_content ); | |
| 835 | + } // End foreach(). | |
| 1122 | 836 | |
| 1123 | - $editor_data[] = $element_data; | |
| 1124 | - } | |
| 1125 | - | |
| 1126 | 837 | Plugin::$instance->documents->restore_document(); |
| 1127 | 838 | |
| 1128 | 839 | return $editor_data; |
| 1129 | 840 | } |
| @@ -1136,9 +847,9 @@ | ||
| 1136 | 847 | * |
| 1137 | 848 | * @return array |
| 1138 | 849 | */ |
| 1139 | 850 | public function get_elements_data( $status = self::STATUS_PUBLISH ) { |
| 1140 | - $elements = $this->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 851 | + $elements = $this->get_json_meta( '_elementor_data' ); | |
| 1141 | 852 | |
| 1142 | 853 | if ( self::STATUS_DRAFT === $status ) { |
| 1143 | 854 | $autosave = $this->get_newer_autosave(); |
| 1144 | 855 | |
| @@ -1144,9 +855,9 @@ | ||
| 1144 | 855 | |
| 1145 | 856 | if ( is_object( $autosave ) ) { |
| 1146 | 857 | $autosave_elements = Plugin::$instance->documents |
| 1147 | 858 | ->get( $autosave->get_post()->ID ) |
| 1148 | - ->get_json_meta( self::ELEMENTOR_DATA_META_KEY ); | |
| 859 | + ->get_json_meta( '_elementor_data' ); | |
| 1149 | 860 | } |
| 1150 | 861 | } |
| 1151 | 862 | |
| 1152 | 863 | if ( Plugin::$instance->editor->is_edit_mode() ) { |
| @@ -1207,20 +918,28 @@ | ||
| 1207 | 918 | ]; |
| 1208 | 919 | } |
| 1209 | 920 | |
| 1210 | 921 | // TODO: Better coding to start template for editor |
| 1211 | - $converted_blocks = [ | |
| 922 | + return [ | |
| 1212 | 923 | [ |
| 1213 | 924 | 'id' => Utils::generate_random_string(), |
| 1214 | - 'elType' => $widget_type::get_type(), | |
| 1215 | - 'widgetType' => $widget_type->get_name(), | |
| 1216 | - '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 | + ], | |
| 1217 | 940 | ], |
| 1218 | 941 | ]; |
| 1219 | - | |
| 1220 | - return Plugin::$instance->experiments->is_feature_active( 'container' ) | |
| 1221 | - ? $this->get_container_elements_data( $converted_blocks ) | |
| 1222 | - : $this->get_sections_elements_data( $converted_blocks ); | |
| 1223 | 942 | } |
| 1224 | 943 | |
| 1225 | 944 | /** |
| 1226 | 945 | * @since 2.1.3 |
| @@ -1230,11 +949,20 @@ | ||
| 1230 | 949 | if ( ! $elements_data ) { |
| 1231 | 950 | $elements_data = $this->get_elements_data(); |
| 1232 | 951 | } |
| 1233 | 952 | |
| 953 | + $is_dom_optimization_active = Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ); | |
| 1234 | 954 | ?> |
| 1235 | 955 | <div <?php Utils::print_html_attributes( $this->get_container_attributes() ); ?>> |
| 1236 | - <?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 } ?> | |
| 1237 | 965 | </div> |
| 1238 | 966 | <?php |
| 1239 | 967 | } |
| 1240 | 968 | |
| @@ -1251,13 +979,10 @@ | ||
| 1251 | 979 | * @access public |
| 1252 | 980 | */ |
| 1253 | 981 | public function get_panel_page_settings() { |
| 1254 | 982 | return [ |
| 1255 | - 'title' => sprintf( | |
| 1256 | - /* translators: %s: Document title. */ | |
| 1257 | - esc_html__( '%s Settings', 'elementor' ), | |
| 1258 | - static::get_title() | |
| 1259 | - ), | |
| 983 | + /* translators: %s: Document title */ | |
| 984 | + 'title' => sprintf( esc_html__( '%s Settings', 'elementor' ), static::get_title() ), | |
| 1260 | 985 | ]; |
| 1261 | 986 | } |
| 1262 | 987 | |
| 1263 | 988 | /** |
| @@ -1297,78 +1022,9 @@ | ||
| 1297 | 1022 | |
| 1298 | 1023 | return $deleted && ! is_wp_error( $deleted ); |
| 1299 | 1024 | } |
| 1300 | 1025 | |
| 1301 | - public function force_delete() { | |
| 1302 | - $deleted = wp_delete_post( $this->post->ID, true ); | |
| 1303 | - | |
| 1304 | - return $deleted && ! is_wp_error( $deleted ); | |
| 1305 | - } | |
| 1306 | - | |
| 1307 | 1026 | /** |
| 1308 | - * On import update dynamic content (e.g. post and term IDs). | |
| 1309 | - * | |
| 1310 | - * @since 3.8.0 | |
| 1311 | - * | |
| 1312 | - * @param array $config The config of the passed element. | |
| 1313 | - * @param array $data The data that requires updating/replacement when imported. | |
| 1314 | - * @param array|null $controls The available controls. | |
| 1315 | - * | |
| 1316 | - * @return array Element data. | |
| 1317 | - */ | |
| 1318 | - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array { | |
| 1319 | - foreach ( $config as &$element_config ) { | |
| 1320 | - $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config ); | |
| 1321 | - | |
| 1322 | - if ( is_null( $element_instance ) ) { | |
| 1323 | - continue; | |
| 1324 | - } | |
| 1325 | - | |
| 1326 | - if ( $element_instance->has_own_method( 'on_import_replace_dynamic_content' ) ) { | |
| 1327 | - // TODO: Remove this check in the future. | |
| 1328 | - $element_config = $element_instance::on_import_replace_dynamic_content( $element_config, $data['post_ids'] ); | |
| 1329 | - } else { | |
| 1330 | - $element_config = $element_instance::on_import_update_dynamic_content( $element_config, $data, $element_instance->get_controls() ); | |
| 1331 | - } | |
| 1332 | - | |
| 1333 | - $element_config['elements'] = static::on_import_update_dynamic_content( $element_config['elements'], $data ); | |
| 1334 | - } | |
| 1335 | - | |
| 1336 | - return $config; | |
| 1337 | - } | |
| 1338 | - | |
| 1339 | - /** | |
| 1340 | - * Update dynamic settings in the document for import. | |
| 1341 | - * | |
| 1342 | - * @param array $settings The settings of the document. | |
| 1343 | - * @param array $config Import config to update the settings. | |
| 1344 | - * | |
| 1345 | - * @return array | |
| 1346 | - */ | |
| 1347 | - public function on_import_update_settings( array $settings, array $config ): array { | |
| 1348 | - $controls = $this->get_controls(); | |
| 1349 | - $controls_manager = Plugin::$instance->controls_manager; | |
| 1350 | - | |
| 1351 | - foreach ( $settings as $key => $value ) { | |
| 1352 | - | |
| 1353 | - if ( ! isset( $controls[ $key ] ) ) { | |
| 1354 | - continue; | |
| 1355 | - } | |
| 1356 | - | |
| 1357 | - $control = $controls[ $key ]; | |
| 1358 | - $control_instance = $controls_manager->get_control( $control['type'] ); | |
| 1359 | - | |
| 1360 | - if ( ! $control_instance ) { | |
| 1361 | - continue; | |
| 1362 | - } | |
| 1363 | - | |
| 1364 | - $settings[ $key ] = $control_instance->on_import_update_settings( $value, $control, $config ); | |
| 1365 | - } | |
| 1366 | - | |
| 1367 | - return $settings; | |
| 1368 | - } | |
| 1369 | - | |
| 1370 | - /** | |
| 1371 | 1027 | * Save editor elements. |
| 1372 | 1028 | * |
| 1373 | 1029 | * Save data from the editor to the database. |
| 1374 | 1030 | * |
| @@ -1383,9 +1039,9 @@ | ||
| 1383 | 1039 | // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 1384 | 1040 | $json_value = wp_slash( wp_json_encode( $editor_data ) ); |
| 1385 | 1041 | |
| 1386 | 1042 | // Don't use `update_post_meta` that can't handle `revision` post type |
| 1387 | - $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 ); | |
| 1388 | 1044 | |
| 1389 | 1045 | /** |
| 1390 | 1046 | * Before saving data. |
| 1391 | 1047 | * |
| @@ -1453,8 +1109,9 @@ | ||
| 1453 | 1109 | * |
| 1454 | 1110 | * @since 2.5.12 |
| 1455 | 1111 | * |
| 1456 | 1112 | * @param \Elementor\Core\Base\Document $this The current document. |
| 1113 | + * | |
| 1457 | 1114 | */ |
| 1458 | 1115 | do_action( 'elementor/document/save_version', $this ); |
| 1459 | 1116 | } |
| 1460 | 1117 | } |
| @@ -1491,9 +1148,9 @@ | ||
| 1491 | 1148 | * @since 2.0.4 |
| 1492 | 1149 | * @access public |
| 1493 | 1150 | * |
| 1494 | 1151 | * @param string $key Meta data key. |
| 1495 | - * @param mixed $value Meta data value. | |
| 1152 | + * @param string $value Meta data value. | |
| 1496 | 1153 | * |
| 1497 | 1154 | * @return bool|int |
| 1498 | 1155 | */ |
| 1499 | 1156 | public function update_main_meta( $key, $value ) { |
| @@ -1568,21 +1225,13 @@ | ||
| 1568 | 1225 | $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) ); |
| 1569 | 1226 | $display_name = get_the_author_meta( 'display_name', $post->post_author ); |
| 1570 | 1227 | |
| 1571 | 1228 | if ( $autosave_post || 'revision' === $post->post_type ) { |
| 1572 | - $last_edited = sprintf( | |
| 1573 | - /* translators: 1: Saving date, 2: Author display name. */ | |
| 1574 | - esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), | |
| 1575 | - '<time>' . $date . '</time>', | |
| 1576 | - $display_name | |
| 1577 | - ); | |
| 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 ); | |
| 1578 | 1231 | } else { |
| 1579 | - $last_edited = sprintf( | |
| 1580 | - /* translators: 1: Editing date, 2: Author display name. */ | |
| 1581 | - esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), | |
| 1582 | - '<time>' . $date . '</time>', | |
| 1583 | - $display_name | |
| 1584 | - ); | |
| 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 ); | |
| 1585 | 1234 | } |
| 1586 | 1235 | |
| 1587 | 1236 | return $last_edited; |
| 1588 | 1237 | } |
| @@ -1621,9 +1270,9 @@ | ||
| 1621 | 1270 | } else { |
| 1622 | 1271 | $this->post = get_post( $data['post_id'] ); |
| 1623 | 1272 | |
| 1624 | 1273 | if ( ! $this->post ) { |
| 1625 | - 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 ); | |
| 1626 | 1275 | } |
| 1627 | 1276 | } |
| 1628 | 1277 | |
| 1629 | 1278 | // Each Control_Stack is based on a unique ID. |
| @@ -1641,9 +1290,9 @@ | ||
| 1641 | 1290 | |
| 1642 | 1291 | parent::__construct( $data ); |
| 1643 | 1292 | } |
| 1644 | 1293 | |
| 1645 | - /** | |
| 1294 | + /* | |
| 1646 | 1295 | * Get Export Data |
| 1647 | 1296 | * |
| 1648 | 1297 | * Filters a document's data on export |
| 1649 | 1298 | * |
| @@ -1655,13 +1304,11 @@ | ||
| 1655 | 1304 | public function get_export_data() { |
| 1656 | 1305 | $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) { |
| 1657 | 1306 | $element_data['id'] = Utils::generate_random_string(); |
| 1658 | 1307 | |
| 1659 | - $element_data = apply_filters( 'elementor/document/element/replace_id', $element_data ); | |
| 1660 | - | |
| 1661 | 1308 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1662 | 1309 | |
| 1663 | - // 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 | |
| 1664 | 1311 | if ( ! $element ) { |
| 1665 | 1312 | return null; |
| 1666 | 1313 | } |
| 1667 | 1314 | |
| @@ -1682,9 +1329,9 @@ | ||
| 1682 | 1329 | 'thumbnail' => get_the_post_thumbnail_url( $this->post ), |
| 1683 | 1330 | ]; |
| 1684 | 1331 | } |
| 1685 | 1332 | |
| 1686 | - /** | |
| 1333 | + /* | |
| 1687 | 1334 | * Get Import Data |
| 1688 | 1335 | * |
| 1689 | 1336 | * Filters a document's data on import |
| 1690 | 1337 | * |
| @@ -1749,12 +1396,10 @@ | ||
| 1749 | 1396 | } |
| 1750 | 1397 | } |
| 1751 | 1398 | } |
| 1752 | 1399 | |
| 1753 | - public function process_element_import_export( Controls_Stack $element, $method, $element_data = null ) { | |
| 1754 | - if ( null === $element_data ) { | |
| 1755 | - $element_data = $element->get_data(); | |
| 1756 | - } | |
| 1400 | + private function process_element_import_export( Controls_Stack $element, $method ) { | |
| 1401 | + $element_data = $element->get_data(); | |
| 1757 | 1402 | |
| 1758 | 1403 | if ( method_exists( $element, $method ) ) { |
| 1759 | 1404 | // TODO: Use the internal element data without parameters. |
| 1760 | 1405 | $element_data = $element->{$method}( $element_data ); |
| @@ -1767,17 +1412,10 @@ | ||
| 1767 | 1412 | if ( ! $control_class ) { |
| 1768 | 1413 | return $element_data; |
| 1769 | 1414 | } |
| 1770 | 1415 | |
| 1771 | - // Do not add default value to the final settings, if there is no value at the | |
| 1772 | - // data before the methods `on_import` or `on_export` called. | |
| 1773 | - $has_value = isset( $element_data['settings'][ $control['name'] ] ); | |
| 1774 | - | |
| 1775 | - if ( $has_value && method_exists( $control_class, $method ) ) { | |
| 1776 | - $element_data['settings'][ $control['name'] ] = $control_class->{$method}( | |
| 1777 | - $element_data['settings'][ $control['name'] ], | |
| 1778 | - $control | |
| 1779 | - ); | |
| 1416 | + if ( method_exists( $control_class, $method ) ) { | |
| 1417 | + $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ), $control ); | |
| 1780 | 1418 | } |
| 1781 | 1419 | |
| 1782 | 1420 | // On Export, check if the control has an argument 'export' => false. |
| 1783 | 1421 | if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) { |
| @@ -1828,92 +1466,18 @@ | ||
| 1828 | 1466 | } |
| 1829 | 1467 | |
| 1830 | 1468 | /** |
| 1831 | 1469 | * @since 2.1.3 |
| 1832 | - * @access public | |
| 1470 | + * @access protected | |
| 1833 | 1471 | */ |
| 1834 | - public function print_elements( $elements_data ) { | |
| 1835 | - $is_element_cache_active = 'disable' !== get_option( 'elementor_element_cache_ttl', '' ); | |
| 1836 | - if ( ! $is_element_cache_active ) { | |
| 1837 | - 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(); | |
| 1838 | 1475 | |
| 1839 | - $this->do_print_elements( $elements_data ); | |
| 1840 | - | |
| 1841 | - $content = ob_get_clean(); | |
| 1842 | - | |
| 1843 | - if ( has_blocks( $content ) ) { | |
| 1844 | - $content = do_blocks( $content ); | |
| 1845 | - } | |
| 1846 | - | |
| 1847 | - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1848 | - | |
| 1849 | - return; | |
| 1476 | + if ( $runtime_elements_iteration_actions ) { | |
| 1477 | + $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); | |
| 1850 | 1478 | } |
| 1851 | 1479 | |
| 1852 | - $cached_data = $this->get_document_cache(); | |
| 1853 | - | |
| 1854 | - if ( false === $cached_data ) { | |
| 1855 | - add_filter( 'elementor/element/should_render_shortcode', '__return_true' ); | |
| 1856 | - | |
| 1857 | - $scripts_to_queue = []; | |
| 1858 | - $styles_to_queue = []; | |
| 1859 | - | |
| 1860 | - global $wp_scripts, $wp_styles; | |
| 1861 | - | |
| 1862 | - $should_store_scripts = $wp_scripts instanceof \WP_Scripts && $wp_styles instanceof \WP_Styles; | |
| 1863 | - if ( $should_store_scripts ) { | |
| 1864 | - $scripts_ignored = $wp_scripts->queue; | |
| 1865 | - $styles_ignored = $wp_styles->queue; | |
| 1866 | - } | |
| 1867 | - | |
| 1868 | - ob_start(); | |
| 1869 | - | |
| 1870 | - $this->do_print_elements( $elements_data ); | |
| 1871 | - | |
| 1872 | - if ( $should_store_scripts ) { | |
| 1873 | - $scripts_to_queue = array_values( array_diff( $wp_scripts->queue, $scripts_ignored ) ); | |
| 1874 | - $styles_to_queue = array_values( array_diff( $wp_styles->queue, $styles_ignored ) ); | |
| 1875 | - } | |
| 1876 | - | |
| 1877 | - $cached_data = [ | |
| 1878 | - 'content' => ob_get_clean(), | |
| 1879 | - 'scripts' => $scripts_to_queue, | |
| 1880 | - 'styles' => $styles_to_queue, | |
| 1881 | - ]; | |
| 1882 | - | |
| 1883 | - if ( $this->should_store_cache_elements() ) { | |
| 1884 | - $this->set_document_cache( $cached_data ); | |
| 1885 | - } | |
| 1886 | - | |
| 1887 | - remove_filter( 'elementor/element/should_render_shortcode', '__return_true' ); | |
| 1888 | - } else { | |
| 1889 | - if ( ! empty( $cached_data['scripts'] ) ) { | |
| 1890 | - foreach ( $cached_data['scripts'] as $script_handle ) { | |
| 1891 | - wp_enqueue_script( $script_handle ); | |
| 1892 | - } | |
| 1893 | - } | |
| 1894 | - | |
| 1895 | - if ( ! empty( $cached_data['styles'] ) ) { | |
| 1896 | - foreach ( $cached_data['styles'] as $style_handle ) { | |
| 1897 | - wp_enqueue_style( $style_handle ); | |
| 1898 | - } | |
| 1899 | - } | |
| 1900 | - } | |
| 1901 | - | |
| 1902 | - if ( ! empty( $cached_data['content'] ) ) { | |
| 1903 | - $content = do_shortcode( $cached_data['content'] ); | |
| 1904 | - | |
| 1905 | - if ( has_blocks( $content ) ) { | |
| 1906 | - $content = do_blocks( $content ); | |
| 1907 | - } | |
| 1908 | - | |
| 1909 | - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1910 | - } | |
| 1911 | - } | |
| 1912 | - | |
| 1913 | - protected function do_print_elements( $elements_data ) { | |
| 1914 | - $this->update_runtime_elements( $elements_data ); | |
| 1915 | - | |
| 1916 | 1480 | foreach ( $elements_data as $element_data ) { |
| 1917 | 1481 | $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 1918 | 1482 | |
| 1919 | 1483 | if ( ! $element ) { |
| @@ -1923,75 +1487,8 @@ | ||
| 1923 | 1487 | $element->print_element(); |
| 1924 | 1488 | } |
| 1925 | 1489 | } |
| 1926 | 1490 | |
| 1927 | - public function update_runtime_elements( $elements_data = null ) { | |
| 1928 | - if ( null === $elements_data ) { | |
| 1929 | - $elements_data = $this->get_elements_data(); | |
| 1930 | - } | |
| 1931 | - | |
| 1932 | - // Collect all data updaters that should be updated on runtime. | |
| 1933 | - $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions(); | |
| 1934 | - | |
| 1935 | - if ( $runtime_elements_iteration_actions ) { | |
| 1936 | - $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); | |
| 1937 | - } | |
| 1938 | - } | |
| 1939 | - | |
| 1940 | - public function set_document_cache( $value ) { | |
| 1941 | - $expiration_hours = get_option( 'elementor_element_cache_ttl', '' ); | |
| 1942 | - | |
| 1943 | - if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) { | |
| 1944 | - $expiration_hours = '24'; | |
| 1945 | - } | |
| 1946 | - | |
| 1947 | - $expiration_hours = absint( $expiration_hours ); | |
| 1948 | - | |
| 1949 | - $expiration = '+' . $expiration_hours . ' hours'; | |
| 1950 | - | |
| 1951 | - $data = [ | |
| 1952 | - 'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ), | |
| 1953 | - 'value' => $value, | |
| 1954 | - ]; | |
| 1955 | - | |
| 1956 | - $this->update_json_meta( static::CACHE_META_KEY, $data ); | |
| 1957 | - } | |
| 1958 | - | |
| 1959 | - private function get_document_cache() { | |
| 1960 | - $cache = $this->get_json_meta( static::CACHE_META_KEY ); | |
| 1961 | - | |
| 1962 | - if ( empty( $cache['timeout'] ) ) { | |
| 1963 | - return false; | |
| 1964 | - } | |
| 1965 | - | |
| 1966 | - if ( current_time( 'timestamp' ) > $cache['timeout'] ) { | |
| 1967 | - return false; | |
| 1968 | - } | |
| 1969 | - | |
| 1970 | - if ( ! is_array( $cache['value'] ) ) { | |
| 1971 | - return false; | |
| 1972 | - } | |
| 1973 | - | |
| 1974 | - return $cache['value']; | |
| 1975 | - } | |
| 1976 | - | |
| 1977 | - protected function delete_cache() { | |
| 1978 | - $this->delete_meta( static::CACHE_META_KEY ); | |
| 1979 | - } | |
| 1980 | - | |
| 1981 | - private function should_store_cache_elements() { | |
| 1982 | - static $should_store_cache_elements = null; | |
| 1983 | - | |
| 1984 | - if ( null === $should_store_cache_elements ) { | |
| 1985 | - $should_store_cache_elements = ( | |
| 1986 | - ! is_admin() | |
| 1987 | - && ! Plugin::$instance->preview->is_preview_mode() | |
| 1988 | - ); | |
| 1989 | - } | |
| 1990 | - | |
| 1991 | - return $should_store_cache_elements; | |
| 1992 | - } | |
| 1993 | - | |
| 1994 | 1491 | protected function register_document_controls() { |
| 1995 | 1492 | $this->start_controls_section( |
| 1996 | 1493 | 'document_settings', |
| 1997 | 1494 | [ |
| @@ -2006,8 +1503,9 @@ | ||
| 2006 | 1503 | 'label' => esc_html__( 'Title', 'elementor' ), |
| 2007 | 1504 | 'type' => Controls_Manager::TEXT, |
| 2008 | 1505 | 'default' => $this->post->post_title, |
| 2009 | 1506 | 'label_block' => true, |
| 1507 | + 'separator' => 'none', | |
| 2010 | 1508 | ] |
| 2011 | 1509 | ); |
| 2012 | 1510 | |
| 2013 | 1511 | $post_type_object = get_post_type_object( $this->post->post_type ); |
| @@ -2122,10 +1620,6 @@ | ||
| 2122 | 1620 | $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this ); |
| 2123 | 1621 | } |
| 2124 | 1622 | |
| 2125 | 1623 | return $this->elements_iteration_actions; |
| 2126 | - } | |
| 2127 | - | |
| 2128 | - public function get_elementor_version() { | |
| 2129 | - return $this->get_main_meta( '_elementor_version' ); | |
| 2130 | 1624 | } |
| 2131 | 1625 | } |