| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; | |
| 5 | -use Elementor\Utils; | |
| 4 | +use Elementor\Core\Page_Assets\Data_Managers\Widgets_Css as Widgets_Css_Data_Manager; | |
| 6 | 5 | |
| 7 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 7 | exit; // Exit if accessed directly. |
| 9 | 8 | } |
| @@ -33,10 +32,8 @@ | ||
| 33 | 32 | * @var bool |
| 34 | 33 | */ |
| 35 | 34 | protected $_has_template_content = true; |
| 36 | 35 | |
| 37 | - private $is_first_section = true; | |
| 38 | - | |
| 39 | 36 | /** |
| 40 | 37 | * Registered Runtime Widgets. |
| 41 | 38 | * |
| 42 | 39 | * Registering in runtime all widgets that are being used on the page. |
| @@ -48,8 +45,12 @@ | ||
| 48 | 45 | * @var array |
| 49 | 46 | */ |
| 50 | 47 | public static $registered_runtime_widgets = []; |
| 51 | 48 | |
| 49 | + public static $registered_inline_css_widgets = []; | |
| 50 | + | |
| 51 | + private static $widgets_css_data_manager; | |
| 52 | + | |
| 52 | 53 | /** |
| 53 | 54 | * Get element type. |
| 54 | 55 | * |
| 55 | 56 | * Retrieve the element type, in this case `widget`. |
| @@ -106,22 +107,8 @@ | ||
| 106 | 107 | return [ 'general' ]; |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | 110 | /** |
| 110 | - * Get widget upsale data. | |
| 111 | - * | |
| 112 | - * Retrieve the widget promotion data. | |
| 113 | - * | |
| 114 | - * @since 3.18.0 | |
| 115 | - * @access protected | |
| 116 | - * | |
| 117 | - * @return array|null Widget promotion data. | |
| 118 | - */ | |
| 119 | - protected function get_upsale_data() { | |
| 120 | - return null; | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | 111 | * Widget base constructor. |
| 125 | 112 | * |
| 126 | 113 | * Initializing the widget base class. |
| 127 | 114 | * |
| @@ -139,9 +126,9 @@ | ||
| 139 | 126 | |
| 140 | 127 | $is_type_instance = $this->is_type_instance(); |
| 141 | 128 | |
| 142 | 129 | if ( ! $is_type_instance && null === $args ) { |
| 143 | - throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' ); | |
| 130 | + throw new \Exception( '`$args` argument is required when initializing a full widget instance.' ); | |
| 144 | 131 | } |
| 145 | 132 | |
| 146 | 133 | if ( $is_type_instance ) { |
| 147 | 134 | if ( $this->has_own_method( '_register_skins', self::class ) ) { |
| @@ -183,11 +170,11 @@ | ||
| 183 | 170 | */ |
| 184 | 171 | public function get_stack( $with_common_controls = true ) { |
| 185 | 172 | $stack = parent::get_stack(); |
| 186 | 173 | |
| 187 | - if ( $with_common_controls && ! $this instanceof Widget_Common_Base ) { | |
| 188 | - /** @var Widget_Common_Base $common_widget */ | |
| 189 | - $common_widget = Plugin::$instance->widgets_manager->get_widget_types( $this->get_common_widget_name() ); | |
| 174 | + if ( $with_common_controls && 'common' !== $this->get_unique_name() ) { | |
| 175 | + /** @var Widget_Common $common_widget */ | |
| 176 | + $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' ); | |
| 190 | 177 | |
| 191 | 178 | $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() ); |
| 192 | 179 | |
| 193 | 180 | $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() ); |
| @@ -195,16 +182,8 @@ | ||
| 195 | 182 | |
| 196 | 183 | return $stack; |
| 197 | 184 | } |
| 198 | 185 | |
| 199 | - private function get_common_widget_name() { | |
| 200 | - if ( Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ) ) { | |
| 201 | - return $this->has_widget_inner_wrapper() ? 'common' : 'common-optimized'; | |
| 202 | - } | |
| 203 | - | |
| 204 | - return 'common'; | |
| 205 | - } | |
| 206 | - | |
| 207 | 186 | /** |
| 208 | 187 | * Get widget controls pointer index. |
| 209 | 188 | * |
| 210 | 189 | * Retrieve widget pointer index where the next control should be added. |
| @@ -241,21 +220,8 @@ | ||
| 241 | 220 | return true; |
| 242 | 221 | } |
| 243 | 222 | |
| 244 | 223 | /** |
| 245 | - * Hide on search. | |
| 246 | - * | |
| 247 | - * Whether to hide the widget on search in the panel or not. By default returns false. | |
| 248 | - * | |
| 249 | - * @access public | |
| 250 | - * | |
| 251 | - * @return bool Whether to hide the widget when searching for widget or not. | |
| 252 | - */ | |
| 253 | - public function hide_on_search() { | |
| 254 | - return false; | |
| 255 | - } | |
| 256 | - | |
| 257 | - /** | |
| 258 | 224 | * Start widget controls section. |
| 259 | 225 | * |
| 260 | 226 | * Used to add a new section of controls to the widget. Regular controls and |
| 261 | 227 | * skin controls. |
| @@ -271,12 +237,14 @@ | ||
| 271 | 237 | */ |
| 272 | 238 | public function start_controls_section( $section_id, array $args = [] ) { |
| 273 | 239 | parent::start_controls_section( $section_id, $args ); |
| 274 | 240 | |
| 275 | - if ( $this->is_first_section ) { | |
| 241 | + static $is_first_section = true; | |
| 242 | + | |
| 243 | + if ( $is_first_section ) { | |
| 276 | 244 | $this->register_skin_control(); |
| 277 | 245 | |
| 278 | - $this->is_first_section = false; | |
| 246 | + $is_first_section = false; | |
| 279 | 247 | } |
| 280 | 248 | } |
| 281 | 249 | |
| 282 | 250 | /** |
| @@ -293,9 +261,9 @@ | ||
| 293 | 261 | if ( ! empty( $skins ) ) { |
| 294 | 262 | $skin_options = []; |
| 295 | 263 | |
| 296 | 264 | if ( $this->_has_template_content ) { |
| 297 | - $skin_options[''] = esc_html__( 'Default', 'elementor' ); | |
| 265 | + $skin_options[''] = __( 'Default', 'elementor' ); | |
| 298 | 266 | } |
| 299 | 267 | |
| 300 | 268 | foreach ( $skins as $skin_id => $skin ) { |
| 301 | 269 | $skin_options[ $skin_id ] = $skin->get_title(); |
| @@ -300,9 +268,9 @@ | ||
| 300 | 268 | foreach ( $skins as $skin_id => $skin ) { |
| 301 | 269 | $skin_options[ $skin_id ] = $skin->get_title(); |
| 302 | 270 | } |
| 303 | 271 | |
| 304 | - // Get the first item for default value. | |
| 272 | + // Get the first item for default value | |
| 305 | 273 | $default_value = array_keys( $skin_options ); |
| 306 | 274 | $default_value = array_shift( $default_value ); |
| 307 | 275 | |
| 308 | 276 | if ( 1 >= count( $skin_options ) ) { |
| @@ -308,9 +276,9 @@ | ||
| 308 | 276 | if ( 1 >= count( $skin_options ) ) { |
| 309 | 277 | $this->add_control( |
| 310 | 278 | '_skin', |
| 311 | 279 | [ |
| 312 | - 'label' => esc_html__( 'Skin', 'elementor' ), | |
| 280 | + 'label' => __( 'Skin', 'elementor' ), | |
| 313 | 281 | 'type' => Controls_Manager::HIDDEN, |
| 314 | 282 | 'default' => $default_value, |
| 315 | 283 | ] |
| 316 | 284 | ); |
| @@ -317,9 +285,9 @@ | ||
| 317 | 285 | } else { |
| 318 | 286 | $this->add_control( |
| 319 | 287 | '_skin', |
| 320 | 288 | [ |
| 321 | - 'label' => esc_html__( 'Skin', 'elementor' ), | |
| 289 | + 'label' => __( 'Skin', 'elementor' ), | |
| 322 | 290 | 'type' => Controls_Manager::SELECT, |
| 323 | 291 | 'default' => $default_value, |
| 324 | 292 | 'options' => $skin_options, |
| 325 | 293 | ] |
| @@ -332,12 +300,12 @@ | ||
| 332 | 300 | * Register widget skins - deprecated prefixed method |
| 333 | 301 | * |
| 334 | 302 | * @since 1.7.12 |
| 335 | 303 | * @access protected |
| 336 | - * @deprecated 3.1.0 Use `register_skins()` method instead. | |
| 304 | + * @deprecated 3.1.0 | |
| 337 | 305 | */ |
| 338 | 306 | protected function _register_skins() { |
| 339 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' ); | |
| 307 | + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_skins()' ); | |
| 340 | 308 | |
| 341 | 309 | $this->register_skins(); |
| 342 | 310 | } |
| 343 | 311 | |
| @@ -378,23 +346,10 @@ | ||
| 378 | 346 | 'keywords' => $this->get_keywords(), |
| 379 | 347 | 'categories' => $this->get_categories(), |
| 380 | 348 | 'html_wrapper_class' => $this->get_html_wrapper_class(), |
| 381 | 349 | 'show_in_panel' => $this->show_in_panel(), |
| 382 | - 'hide_on_search' => $this->hide_on_search(), | |
| 383 | - 'upsale_data' => $this->get_upsale_data(), | |
| 384 | - 'is_dynamic_content' => $this->is_dynamic_content(), | |
| 385 | - 'has_widget_inner_wrapper' => $this->has_widget_inner_wrapper(), | |
| 386 | 350 | ]; |
| 387 | 351 | |
| 388 | - if ( isset( $config['upsale_data'] ) && is_array( $config['upsale_data'] ) ) { | |
| 389 | - $filter_name = 'elementor/widgets/' . $this->get_name() . '/custom_promotion'; | |
| 390 | - $config['upsale_data'] = Filtered_Promotions_Manager::get_filtered_promotion_data( $config['upsale_data'], $filter_name, 'upgrade_url' ); | |
| 391 | - } | |
| 392 | - | |
| 393 | - if ( isset( $config['upsale_data']['image'] ) ) { | |
| 394 | - $config['upsale_data']['image'] = esc_url( $config['upsale_data']['image'] ); | |
| 395 | - } | |
| 396 | - | |
| 397 | 352 | $stack = Plugin::$instance->controls_manager->get_element_stack( $this ); |
| 398 | 353 | |
| 399 | 354 | if ( $stack ) { |
| 400 | 355 | $config['controls'] = $this->get_stack( false )['controls']; |
| @@ -400,9 +355,9 @@ | ||
| 400 | 355 | $config['controls'] = $this->get_stack( false )['controls']; |
| 401 | 356 | $config['tabs_controls'] = $this->get_tabs_controls(); |
| 402 | 357 | } |
| 403 | 358 | |
| 404 | - return array_replace_recursive( parent::get_initial_config(), $config ); | |
| 359 | + return array_merge( parent::get_initial_config(), $config ); | |
| 405 | 360 | } |
| 406 | 361 | |
| 407 | 362 | /** |
| 408 | 363 | * @since 2.3.1 |
| @@ -423,15 +378,15 @@ | ||
| 423 | 378 | * |
| 424 | 379 | * @param string $template_content Template content. |
| 425 | 380 | */ |
| 426 | 381 | protected function print_template_content( $template_content ) { |
| 427 | - if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 382 | + ?> | |
| 428 | 383 | <div class="elementor-widget-container"> |
| 429 | - <?php endif; | |
| 430 | - Utils::print_unescaped_internal_string( $template_content ); | |
| 431 | - if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 384 | + <?php | |
| 385 | + echo $template_content; // XSS ok. | |
| 386 | + ?> | |
| 432 | 387 | </div> |
| 433 | - <?php endif; | |
| 388 | + <?php | |
| 434 | 389 | } |
| 435 | 390 | |
| 436 | 391 | /** |
| 437 | 392 | * Parse text editor. |
| @@ -461,22 +416,8 @@ | ||
| 461 | 416 | return $content; |
| 462 | 417 | } |
| 463 | 418 | |
| 464 | 419 | /** |
| 465 | - * Safe print parsed text editor. | |
| 466 | - * | |
| 467 | - * @uses static::parse_text_editor. | |
| 468 | - * | |
| 469 | - * @access protected | |
| 470 | - * | |
| 471 | - * @param string $content Text editor content. | |
| 472 | - */ | |
| 473 | - final protected function print_text_editor( $content ) { | |
| 474 | - // PHPCS - the method `parse_text_editor` is safe. | |
| 475 | - echo static::parse_text_editor( $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 476 | - } | |
| 477 | - | |
| 478 | - /** | |
| 479 | 420 | * Get HTML wrapper class. |
| 480 | 421 | * |
| 481 | 422 | * Retrieve the widget container class. Can be used to override the |
| 482 | 423 | * container class for specific widgets. |
| @@ -541,17 +482,18 @@ | ||
| 541 | 482 | * |
| 542 | 483 | * Used to add Light-Box-related data attributes to links that open media files. |
| 543 | 484 | * |
| 544 | 485 | * @param array|string $element The link HTML element. |
| 545 | - * @param int $id The ID of the image. | |
| 546 | - * @param string $lightbox_setting_key The setting key that dictates whether to open the image in a lightbox. | |
| 547 | - * @param string $group_id Unique ID for a group of lightbox images. | |
| 548 | - * @param bool $overwrite Optional. Whether to overwrite existing | |
| 549 | - * attribute. Default is false, not to overwrite. | |
| 486 | + * @param int $id The ID of the image | |
| 487 | + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox | |
| 488 | + * @param string $group_id Unique ID for a group of lightbox images | |
| 489 | + * @param bool $overwrite Optional. Whether to overwrite existing | |
| 490 | + * attribute. Default is false, not to overwrite. | |
| 550 | 491 | * |
| 551 | 492 | * @return Widget_Base Current instance of the widget. |
| 552 | 493 | * @since 2.9.0 |
| 553 | 494 | * @access public |
| 495 | + * | |
| 554 | 496 | */ |
| 555 | 497 | public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) { |
| 556 | 498 | $kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 557 | 499 | |
| @@ -570,19 +512,10 @@ | ||
| 570 | 512 | } |
| 571 | 513 | |
| 572 | 514 | $attributes['data-elementor-open-lightbox'] = 'yes'; |
| 573 | 515 | |
| 574 | - $action_hash_params = []; | |
| 575 | - | |
| 576 | - if ( $id ) { | |
| 577 | - $action_hash_params['id'] = $id; | |
| 578 | - $action_hash_params['url'] = wp_get_attachment_url( $id ); | |
| 579 | - } | |
| 580 | - | |
| 581 | 516 | if ( $group_id ) { |
| 582 | 517 | $attributes['data-elementor-lightbox-slideshow'] = $group_id; |
| 583 | - | |
| 584 | - $action_hash_params['slideshow'] = $group_id; | |
| 585 | 518 | } |
| 586 | 519 | |
| 587 | 520 | if ( $id ) { |
| 588 | 521 | $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id ); |
| @@ -595,10 +528,8 @@ | ||
| 595 | 528 | $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description']; |
| 596 | 529 | } |
| 597 | 530 | } |
| 598 | 531 | |
| 599 | - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params ); | |
| 600 | - | |
| 601 | 532 | $this->add_render_attribute( $element, $attributes, null, $overwrite ); |
| 602 | 533 | |
| 603 | 534 | return $this; |
| 604 | 535 | } |
| @@ -640,16 +571,19 @@ | ||
| 640 | 571 | |
| 641 | 572 | if ( empty( $widget_content ) ) { |
| 642 | 573 | return; |
| 643 | 574 | } |
| 644 | - if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 575 | + ?> | |
| 645 | 576 | <div class="elementor-widget-container"> |
| 646 | - <?php endif; ?> | |
| 647 | 577 | <?php |
| 648 | 578 | if ( $this->is_widget_first_render( $this->get_group_name() ) ) { |
| 649 | 579 | $this->register_runtime_widget( $this->get_group_name() ); |
| 650 | 580 | } |
| 651 | 581 | |
| 582 | + $this->print_widget_css(); | |
| 583 | + | |
| 584 | + // get_name | |
| 585 | + | |
| 652 | 586 | /** |
| 653 | 587 | * Render widget content. |
| 654 | 588 | * |
| 655 | 589 | * Filters the widget content before it's rendered. |
| @@ -659,13 +593,13 @@ | ||
| 659 | 593 | * @param string $widget_content The content of the widget. |
| 660 | 594 | * @param Widget_Base $this The widget. |
| 661 | 595 | */ |
| 662 | 596 | $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this ); |
| 663 | - Utils::print_unescaped_internal_string( $widget_content ); | |
| 597 | + | |
| 598 | + echo $widget_content; // XSS ok. | |
| 664 | 599 | ?> |
| 665 | - <?php if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 666 | 600 | </div> |
| 667 | - <?php endif; | |
| 601 | + <?php | |
| 668 | 602 | } |
| 669 | 603 | |
| 670 | 604 | protected function is_widget_first_render( $widget_name ) { |
| 671 | 605 | return ! in_array( $widget_name, self::$registered_runtime_widgets, true ); |
| @@ -696,16 +630,8 @@ | ||
| 696 | 630 | public function render_plain_content() { |
| 697 | 631 | $this->render_content(); |
| 698 | 632 | } |
| 699 | 633 | |
| 700 | - public function render_markdown(): string { | |
| 701 | - ob_start(); | |
| 702 | - $this->render_content(); | |
| 703 | - $html = ob_get_clean(); | |
| 704 | - | |
| 705 | - return wp_strip_all_tags( $html ); | |
| 706 | - } | |
| 707 | - | |
| 708 | 634 | /** |
| 709 | 635 | * Before widget rendering. |
| 710 | 636 | * |
| 711 | 637 | * Used to add stuff before the widget `_wrapper` element. |
| @@ -787,12 +713,12 @@ | ||
| 787 | 713 | * |
| 788 | 714 | * Script tags are allowed on frontend according to the WP theme securing policy. |
| 789 | 715 | * |
| 790 | 716 | * @param string $setting |
| 791 | - * @param null $repeater_name | |
| 792 | - * @param null $index | |
| 717 | + * @param null $repeater_name | |
| 718 | + * @param null $index | |
| 793 | 719 | */ |
| 794 | - final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) { | |
| 720 | + final protected function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) { | |
| 795 | 721 | if ( $repeater_name ) { |
| 796 | 722 | $repeater = $this->get_settings_for_display( $repeater_name ); |
| 797 | 723 | $output = $repeater[ $index ][ $setting ]; |
| 798 | 724 | } else { |
| @@ -855,9 +781,9 @@ | ||
| 855 | 781 | * @access protected |
| 856 | 782 | * |
| 857 | 783 | * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`). |
| 858 | 784 | * @param string $repeater_key The repeater key containing the array of all the items in the repeater (e.g. `tabs`). |
| 859 | - * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`). | |
| 785 | + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`). | |
| 860 | 786 | * |
| 861 | 787 | * @return string The repeater setting key (e.g. `tabs.3.tab_title`). |
| 862 | 788 | */ |
| 863 | 789 | protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) { |
| @@ -1014,18 +940,31 @@ | ||
| 1014 | 940 | return $this->get_name(); |
| 1015 | 941 | } |
| 1016 | 942 | |
| 1017 | 943 | /** |
| 1018 | - * @param string $plugin_title Plugin's title. | |
| 1019 | - * @param string $since Plugin version widget was deprecated. | |
| 1020 | - * @param string $last Plugin version in which the widget will be removed. | |
| 1021 | - * @param string $replacement Widget replacement. | |
| 944 | + * Get Inline CSS dependencies. | |
| 945 | + * | |
| 946 | + * Retrieve a list of inline CSS dependencies that the element requires. | |
| 947 | + * | |
| 948 | + * @since 3.3.0 | |
| 949 | + * @access public | |
| 950 | + * | |
| 951 | + * @return array. | |
| 1022 | 952 | */ |
| 953 | + public function get_inline_css_depends() { | |
| 954 | + return []; | |
| 955 | + } | |
| 956 | + | |
| 957 | + /** | |
| 958 | + * @param string $plugin_title Plugin's title | |
| 959 | + * @param string $since Plugin version widget was deprecated | |
| 960 | + * @param string $last Plugin version in which the widget will be removed | |
| 961 | + * @param string $replacement Widget replacement | |
| 962 | + */ | |
| 1023 | 963 | protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) { |
| 1024 | - $this->start_controls_section( | |
| 1025 | - 'Deprecated', | |
| 964 | + $this->start_controls_section( 'Deprecated', | |
| 1026 | 965 | [ |
| 1027 | - 'label' => esc_html__( 'Deprecated', 'elementor' ), | |
| 966 | + 'label' => __( 'Deprecated', 'elementor' ), | |
| 1028 | 967 | ] |
| 1029 | 968 | ); |
| 1030 | 969 | |
| 1031 | 970 | $this->add_control( |
| @@ -1040,22 +979,9 @@ | ||
| 1040 | 979 | ] |
| 1041 | 980 | ); |
| 1042 | 981 | |
| 1043 | 982 | $this->end_controls_section(); |
| 1044 | - } | |
| 1045 | 983 | |
| 1046 | - /** | |
| 1047 | - * Init controls. | |
| 1048 | - * | |
| 1049 | - * Reset the `is_first_section` flag to true, so when the Stacks are cleared | |
| 1050 | - * all the controls will be registered again with their skins and settings. | |
| 1051 | - * | |
| 1052 | - * @since 3.14.0 | |
| 1053 | - * @access protected | |
| 1054 | - */ | |
| 1055 | - protected function init_controls() { | |
| 1056 | - $this->is_first_section = true; | |
| 1057 | - parent::init_controls(); | |
| 1058 | 984 | } |
| 1059 | 985 | |
| 1060 | 986 | public function register_runtime_widget( $widget_name ) { |
| 1061 | 987 | self::$registered_runtime_widgets[] = $widget_name; |
| @@ -1060,32 +986,88 @@ | ||
| 1060 | 986 | public function register_runtime_widget( $widget_name ) { |
| 1061 | 987 | self::$registered_runtime_widgets[] = $widget_name; |
| 1062 | 988 | } |
| 1063 | 989 | |
| 1064 | - /** | |
| 1065 | - * Mark widget as deprecated. | |
| 1066 | - * | |
| 1067 | - * Use `get_deprecation_message()` method to print the message control at specific location in register_controls(). | |
| 1068 | - * | |
| 1069 | - * @param string $version The version of Elementor that deprecated the widget. | |
| 1070 | - * @param string $message A message regarding the deprecation. | |
| 1071 | - * @param string $replacement The widget that should be used instead. | |
| 1072 | - */ | |
| 1073 | - protected function add_deprecation_message( $version, $message, $replacement ) { | |
| 1074 | - // Expose the config for handling in JS. | |
| 1075 | - $this->set_config( 'deprecation', [ | |
| 1076 | - 'version' => $version, | |
| 1077 | - 'message' => $message, | |
| 1078 | - 'replacement' => $replacement, | |
| 1079 | - ] ); | |
| 990 | + public function get_widget_css_config( $widget_name ) { | |
| 991 | + $direction = is_rtl() ? '-rtl' : ''; | |
| 1080 | 992 | |
| 1081 | - $this->add_control( | |
| 1082 | - 'deprecation_message', | |
| 1083 | - [ | |
| 1084 | - 'type' => Controls_Manager::ALERT, | |
| 1085 | - 'alert_type' => 'info', | |
| 1086 | - 'content' => $message, | |
| 1087 | - 'separator' => 'after', | |
| 1088 | - ] | |
| 1089 | - ); | |
| 993 | + $css_file_path = 'css/widget-' . $widget_name . $direction . '.min.css'; | |
| 994 | + | |
| 995 | + return [ | |
| 996 | + 'key' => $widget_name, | |
| 997 | + 'version' => ELEMENTOR_VERSION, | |
| 998 | + 'file_path' => ELEMENTOR_ASSETS_PATH . $css_file_path, | |
| 999 | + 'data' => [ | |
| 1000 | + 'file_url' => ELEMENTOR_ASSETS_URL . $css_file_path, | |
| 1001 | + ], | |
| 1002 | + ]; | |
| 1003 | + } | |
| 1004 | + | |
| 1005 | + public function get_css_config() { | |
| 1006 | + return $this->get_widget_css_config( $this->get_group_name() ); | |
| 1007 | + } | |
| 1008 | + | |
| 1009 | + private function get_widget_css() { | |
| 1010 | + $widgets_css_data_manager = $this->get_widgets_css_data_manager(); | |
| 1011 | + | |
| 1012 | + $widgets_list = $this->get_inline_css_depends(); | |
| 1013 | + | |
| 1014 | + $widgets_list[] = $this->get_group_name(); | |
| 1015 | + | |
| 1016 | + $widget_css = ''; | |
| 1017 | + | |
| 1018 | + foreach ( $widgets_list as $widget_data ) { | |
| 1019 | + $widget_name = isset( $widget_data['name'] ) ? $widget_data['name'] : $widget_data; | |
| 1020 | + | |
| 1021 | + if ( ! in_array( $widget_name, self::$registered_inline_css_widgets, true ) ) { | |
| 1022 | + if ( $this->get_group_name() === $widget_name ) { | |
| 1023 | + $config = $this->get_css_config(); | |
| 1024 | + } else { | |
| 1025 | + /** | |
| 1026 | + * The core-dependency allowing to create a dependency specifically with the core widgets. | |
| 1027 | + * Otherwise, the config will be taken from the class that inherits from Widget_Base. | |
| 1028 | + */ | |
| 1029 | + $is_core_dependency = isset( $widget_data['is_core_dependency'] ) ? true : false; | |
| 1030 | + | |
| 1031 | + $config = $is_core_dependency ? self::get_widget_css_config( $widget_name ) : $this->get_widget_css_config( $widget_name ); | |
| 1032 | + } | |
| 1033 | + | |
| 1034 | + $widget_css .= $widgets_css_data_manager->get_asset_data( $config ); | |
| 1035 | + | |
| 1036 | + self::$registered_inline_css_widgets[] = $widget_name; | |
| 1037 | + } | |
| 1038 | + } | |
| 1039 | + | |
| 1040 | + return $widget_css; | |
| 1041 | + | |
| 1042 | + } | |
| 1043 | + | |
| 1044 | + private function is_inline_css_mode() { | |
| 1045 | + static $is_active; | |
| 1046 | + | |
| 1047 | + if ( null === $is_active ) { | |
| 1048 | + $is_edit_mode = Plugin::$instance->editor->is_edit_mode(); | |
| 1049 | + $is_preview_mode = Plugin::$instance->preview->is_preview_mode(); | |
| 1050 | + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' ); | |
| 1051 | + | |
| 1052 | + $is_active = ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) ? false : true; | |
| 1053 | + } | |
| 1054 | + | |
| 1055 | + return $is_active; | |
| 1056 | + } | |
| 1057 | + | |
| 1058 | + private function print_widget_css() { | |
| 1059 | + if ( ! $this->is_inline_css_mode() ) { | |
| 1060 | + return; | |
| 1061 | + } | |
| 1062 | + | |
| 1063 | + echo $this->get_widget_css(); | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + private function get_widgets_css_data_manager() { | |
| 1067 | + if ( ! self::$widgets_css_data_manager ) { | |
| 1068 | + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager(); | |
| 1069 | + } | |
| 1070 | + | |
| 1071 | + return self::$widgets_css_data_manager; | |
| 1090 | 1072 | } |
| 1091 | 1073 | } |