PluginProbe
Elementor Website Builder – more than just a page builder / 3.4.0-dev9
Elementor Website Builder – more than just a page builder v3.4.0-dev9
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | includes/base/widget-base.php +92 -177 4.3.0-beta33.4.0-dev9 View file →
@@ -1,10 +1,8 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Frontend\Widget_Content_Render_Mode;
5 -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
6 -use Elementor\Utils;
4 +use Elementor\Core\Page_Assets\Data_Managers\Widgets_Css as Widgets_Css_Data_Manager;
7 5
8 6 if ( ! defined( 'ABSPATH' ) ) {
9 7 exit; // Exit if accessed directly.
10 8 }
@@ -34,10 +32,8 @@
34 32 * @var bool
35 33 */
36 34 protected $_has_template_content = true;
37 35
38 - private $is_first_section = true;
39 -
40 36 /**
41 37 * Registered Runtime Widgets.
42 38 *
43 39 * Registering in runtime all widgets that are being used on the page.
@@ -49,8 +45,10 @@
49 45 * @var array
50 46 */
51 47 public static $registered_runtime_widgets = [];
52 48
49 + private static $widgets_css_data_manager;
50 +
53 51 /**
54 52 * Get element type.
55 53 *
56 54 * Retrieve the element type, in this case `widget`.
@@ -107,22 +105,8 @@
107 105 return [ 'general' ];
108 106 }
109 107
110 108 /**
111 - * Get widget upsale data.
112 - *
113 - * Retrieve the widget promotion data.
114 - *
115 - * @since 3.18.0
116 - * @access protected
117 - *
118 - * @return array|null Widget promotion data.
119 - */
120 - protected function get_upsale_data() {
121 - return null;
122 - }
123 -
124 - /**
125 109 * Widget base constructor.
126 110 *
127 111 * Initializing the widget base class.
128 112 *
@@ -140,9 +124,9 @@
140 124
141 125 $is_type_instance = $this->is_type_instance();
142 126
143 127 if ( ! $is_type_instance && null === $args ) {
144 - throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' );
128 + throw new \Exception( '`$args` argument is required when initializing a full widget instance.' );
145 129 }
146 130
147 131 if ( $is_type_instance ) {
148 132 if ( $this->has_own_method( '_register_skins', self::class ) ) {
@@ -184,11 +168,11 @@
184 168 */
185 169 public function get_stack( $with_common_controls = true ) {
186 170 $stack = parent::get_stack();
187 171
188 - if ( $with_common_controls && ! $this instanceof Widget_Common_Base ) {
189 - /** @var Widget_Common_Base $common_widget */
190 - $common_widget = Plugin::$instance->widgets_manager->get_widget_types( $this->get_common_widget_name() );
172 + if ( $with_common_controls && 'common' !== $this->get_unique_name() ) {
173 + /** @var Widget_Common $common_widget */
174 + $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' );
191 175
192 176 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
193 177
194 178 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
@@ -196,16 +180,8 @@
196 180
197 181 return $stack;
198 182 }
199 183
200 - private function get_common_widget_name() {
201 - if ( Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ) ) {
202 - return $this->has_widget_inner_wrapper() ? 'common' : 'common-optimized';
203 - }
204 -
205 - return 'common';
206 - }
207 -
208 184 /**
209 185 * Get widget controls pointer index.
210 186 *
211 187 * Retrieve widget pointer index where the next control should be added.
@@ -242,21 +218,8 @@
242 218 return true;
243 219 }
244 220
245 221 /**
246 - * Hide on search.
247 - *
248 - * Whether to hide the widget on search in the panel or not. By default returns false.
249 - *
250 - * @access public
251 - *
252 - * @return bool Whether to hide the widget when searching for widget or not.
253 - */
254 - public function hide_on_search() {
255 - return false;
256 - }
257 -
258 - /**
259 222 * Start widget controls section.
260 223 *
261 224 * Used to add a new section of controls to the widget. Regular controls and
262 225 * skin controls.
@@ -272,12 +235,14 @@
272 235 */
273 236 public function start_controls_section( $section_id, array $args = [] ) {
274 237 parent::start_controls_section( $section_id, $args );
275 238
276 - if ( $this->is_first_section ) {
239 + static $is_first_section = true;
240 +
241 + if ( $is_first_section ) {
277 242 $this->register_skin_control();
278 243
279 - $this->is_first_section = false;
244 + $is_first_section = false;
280 245 }
281 246 }
282 247
283 248 /**
@@ -301,9 +266,9 @@
301 266 foreach ( $skins as $skin_id => $skin ) {
302 267 $skin_options[ $skin_id ] = $skin->get_title();
303 268 }
304 269
305 - // Get the first item for default value.
270 + // Get the first item for default value
306 271 $default_value = array_keys( $skin_options );
307 272 $default_value = array_shift( $default_value );
308 273
309 274 if ( 1 >= count( $skin_options ) ) {
@@ -333,12 +298,12 @@
333 298 * Register widget skins - deprecated prefixed method
334 299 *
335 300 * @since 1.7.12
336 301 * @access protected
337 - * @deprecated 3.1.0 Use `register_skins()` method instead.
302 + * @deprecated 3.1.0
338 303 */
339 304 protected function _register_skins() {
340 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' );
305 + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_skins()' );
341 306
342 307 $this->register_skins();
343 308 }
344 309
@@ -379,23 +344,10 @@
379 344 'keywords' => $this->get_keywords(),
380 345 'categories' => $this->get_categories(),
381 346 'html_wrapper_class' => $this->get_html_wrapper_class(),
382 347 'show_in_panel' => $this->show_in_panel(),
383 - 'hide_on_search' => $this->hide_on_search(),
384 - 'upsale_data' => null,
385 - 'is_dynamic_content' => $this->is_dynamic_content(),
386 - 'has_widget_inner_wrapper' => $this->has_widget_inner_wrapper(),
387 348 ];
388 349
389 - if ( isset( $config['upsale_data'] ) && is_array( $config['upsale_data'] ) ) {
390 - $filter_name = 'elementor/widgets/' . $this->get_name() . '/custom_promotion';
391 - $config['upsale_data'] = Filtered_Promotions_Manager::get_filtered_promotion_data( $config['upsale_data'], $filter_name, 'upgrade_url' );
392 - }
393 -
394 - if ( isset( $config['upsale_data']['image'] ) ) {
395 - $config['upsale_data']['image'] = esc_url( $config['upsale_data']['image'] );
396 - }
397 -
398 350 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
399 351
400 352 if ( $stack ) {
401 353 $config['controls'] = $this->get_stack( false )['controls'];
@@ -401,9 +353,9 @@
401 353 $config['controls'] = $this->get_stack( false )['controls'];
402 354 $config['tabs_controls'] = $this->get_tabs_controls();
403 355 }
404 356
405 - return array_replace_recursive( parent::get_initial_config(), $config );
357 + return array_merge( parent::get_initial_config(), $config );
406 358 }
407 359
408 360 /**
409 361 * @since 2.3.1
@@ -424,15 +376,15 @@
424 376 *
425 377 * @param string $template_content Template content.
426 378 */
427 379 protected function print_template_content( $template_content ) {
428 - if ( $this->has_widget_inner_wrapper() ) : ?>
380 + ?>
429 381 <div class="elementor-widget-container">
430 - <?php endif;
431 - Utils::print_unescaped_internal_string( $template_content );
432 - if ( $this->has_widget_inner_wrapper() ) : ?>
382 + <?php
383 + echo $template_content; // XSS ok.
384 + ?>
433 385 </div>
434 - <?php endif;
386 + <?php
435 387 }
436 388
437 389 /**
438 390 * Parse text editor.
@@ -542,17 +494,18 @@
542 494 *
543 495 * Used to add Light-Box-related data attributes to links that open media files.
544 496 *
545 497 * @param array|string $element The link HTML element.
546 - * @param int $id The ID of the image.
547 - * @param string $lightbox_setting_key The setting key that dictates whether to open the image in a lightbox.
548 - * @param string $group_id Unique ID for a group of lightbox images.
549 - * @param bool $overwrite Optional. Whether to overwrite existing
550 - * attribute. Default is false, not to overwrite.
498 + * @param int $id The ID of the image
499 + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox
500 + * @param string $group_id Unique ID for a group of lightbox images
501 + * @param bool $overwrite Optional. Whether to overwrite existing
502 + * attribute. Default is false, not to overwrite.
551 503 *
552 504 * @return Widget_Base Current instance of the widget.
553 505 * @since 2.9.0
554 506 * @access public
507 + *
555 508 */
556 509 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
557 510 $kit = Plugin::$instance->kits_manager->get_active_kit();
558 511
@@ -571,19 +524,10 @@
571 524 }
572 525
573 526 $attributes['data-elementor-open-lightbox'] = 'yes';
574 527
575 - $action_hash_params = [];
576 -
577 - if ( $id ) {
578 - $action_hash_params['id'] = $id;
579 - $action_hash_params['url'] = wp_get_attachment_url( $id );
580 - }
581 -
582 528 if ( $group_id ) {
583 529 $attributes['data-elementor-lightbox-slideshow'] = $group_id;
584 -
585 - $action_hash_params['slideshow'] = $group_id;
586 530 }
587 531
588 532 if ( $id ) {
589 533 $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id );
@@ -596,10 +540,8 @@
596 540 $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
597 541 }
598 542 }
599 543
600 - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
601 -
602 544 $this->add_render_attribute( $element, $attributes, null, $overwrite );
603 545
604 546 return $this;
605 547 }
@@ -624,9 +566,9 @@
624 566 * @since 1.0.0
625 567 *
626 568 * @param Widget_Base $this The current widget.
627 569 */
628 - do_action( 'elementor/widget/before_render_content', $this, [ 'mode' => Widget_Content_Render_Mode::NORMAL ] );
570 + do_action( 'elementor/widget/before_render_content', $this );
629 571
630 572 ob_start();
631 573
632 574 $skin = $this->get_current_skin();
@@ -641,16 +583,20 @@
641 583
642 584 if ( empty( $widget_content ) ) {
643 585 return;
644 586 }
645 - if ( $this->has_widget_inner_wrapper() ) : ?>
587 + ?>
646 588 <div class="elementor-widget-container">
647 - <?php endif; ?>
648 589 <?php
649 - if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
590 + if ( $this->is_widget_first_render() ) {
591 +
650 592 $this->register_runtime_widget( $this->get_group_name() );
593 +
594 + $this->print_widget_css();
651 595 }
652 596
597 + // get_name
598 +
653 599 /**
654 600 * Render widget content.
655 601 *
656 602 * Filters the widget content before it's rendered.
@@ -659,18 +605,18 @@
659 605 *
660 606 * @param string $widget_content The content of the widget.
661 607 * @param Widget_Base $this The widget.
662 608 */
663 - $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this, [ 'mode' => Widget_Content_Render_Mode::NORMAL ] );
664 - Utils::print_unescaped_internal_string( $widget_content );
609 + $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
610 +
611 + echo $widget_content; // XSS ok.
665 612 ?>
666 - <?php if ( $this->has_widget_inner_wrapper() ) : ?>
667 613 </div>
668 - <?php endif;
614 + <?php
669 615 }
670 616
671 - protected function is_widget_first_render( $widget_name ) {
672 - return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
617 + protected function is_widget_first_render() {
618 + return ! in_array( $this->get_group_name(), self::$registered_runtime_widgets, true );
673 619 }
674 620
675 621 /**
676 622 * Render widget plain content.
@@ -697,43 +643,8 @@
697 643 public function render_plain_content() {
698 644 $this->render_content();
699 645 }
700 646
701 - public function render_markdown(): string {
702 - $content = $this->get_render_content_for_markdown();
703 -
704 - if ( '' === $content ) {
705 - return '';
706 - }
707 -
708 - return \Elementor\Modules\MarkdownRender\Html_To_Markdown::convert( $content );
709 - }
710 -
711 - protected function get_render_content_for_markdown(): string {
712 - $render_args = [ 'mode' => Widget_Content_Render_Mode::MARKDOWN ];
713 -
714 - do_action( 'elementor/widget/before_render_content', $this, $render_args );
715 -
716 - ob_start();
717 -
718 - $skin = $this->get_current_skin();
719 -
720 - if ( $skin ) {
721 - $skin->set_parent( $this );
722 - $skin->render_by_mode();
723 - } else {
724 - $this->render_by_mode();
725 - }
726 -
727 - $widget_content = ob_get_clean();
728 -
729 - if ( '' === $widget_content ) {
730 - return '';
731 - }
732 -
733 - return apply_filters( 'elementor/widget/render_content', $widget_content, $this, $render_args );
734 - }
735 -
736 647 /**
737 648 * Before widget rendering.
738 649 *
739 650 * Used to add stuff before the widget `_wrapper` element.
@@ -815,12 +726,12 @@
815 726 *
816 727 * Script tags are allowed on frontend according to the WP theme securing policy.
817 728 *
818 729 * @param string $setting
819 - * @param null $repeater_name
820 - * @param null $index
730 + * @param null $repeater_name
731 + * @param null $index
821 732 */
822 - final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
733 + final protected function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
823 734 if ( $repeater_name ) {
824 735 $repeater = $this->get_settings_for_display( $repeater_name );
825 736 $output = $repeater[ $index ][ $setting ];
826 737 } else {
@@ -883,9 +794,9 @@
883 794 * @access protected
884 795 *
885 796 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
886 797 * @param string $repeater_key The repeater key containing the array of all the items in the repeater (e.g. `tabs`).
887 - * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
798 + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
888 799 *
889 800 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
890 801 */
891 802 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
@@ -1042,16 +953,15 @@
1042 953 return $this->get_name();
1043 954 }
1044 955
1045 956 /**
1046 - * @param string $plugin_title Plugin's title.
1047 - * @param string $since Plugin version widget was deprecated.
1048 - * @param string $last Plugin version in which the widget will be removed.
1049 - * @param string $replacement Widget replacement.
957 + * @param string $plugin_title Plugin's title
958 + * @param string $since Plugin version widget was deprecated
959 + * @param string $last Plugin version in which the widget will be removed
960 + * @param string $replacement Widget replacement
1050 961 */
1051 962 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1052 - $this->start_controls_section(
1053 - 'Deprecated',
963 + $this->start_controls_section( 'Deprecated',
1054 964 [
1055 965 'label' => esc_html__( 'Deprecated', 'elementor' ),
1056 966 ]
1057 967 );
@@ -1068,22 +978,9 @@
1068 978 ]
1069 979 );
1070 980
1071 981 $this->end_controls_section();
1072 - }
1073 982
1074 - /**
1075 - * Init controls.
1076 - *
1077 - * Reset the `is_first_section` flag to true, so when the Stacks are cleared
1078 - * all the controls will be registered again with their skins and settings.
1079 - *
1080 - * @since 3.14.0
1081 - * @access protected
1082 - */
1083 - protected function init_controls() {
1084 - $this->is_first_section = true;
1085 - parent::init_controls();
1086 983 }
1087 984
1088 985 public function register_runtime_widget( $widget_name ) {
1089 986 self::$registered_runtime_widgets[] = $widget_name;
@@ -1088,32 +985,50 @@
1088 985 public function register_runtime_widget( $widget_name ) {
1089 986 self::$registered_runtime_widgets[] = $widget_name;
1090 987 }
1091 988
1092 - /**
1093 - * Mark widget as deprecated.
1094 - *
1095 - * Use `get_deprecation_message()` method to print the message control at specific location in register_controls().
1096 - *
1097 - * @param string $version The version of Elementor that deprecated the widget.
1098 - * @param string $message A message regarding the deprecation.
1099 - * @param string $replacement The widget that should be used instead.
1100 - */
1101 - protected function add_deprecation_message( $version, $message, $replacement ) {
1102 - // Expose the config for handling in JS.
1103 - $this->set_config( 'deprecation', [
1104 - 'version' => $version,
1105 - 'message' => $message,
1106 - 'replacement' => $replacement,
1107 - ] );
989 + public function get_css_config() {
990 + $widget_name = $this->get_group_name();
1108 991
1109 - $this->add_control(
1110 - 'deprecation_message',
1111 - [
1112 - 'type' => Controls_Manager::ALERT,
1113 - 'alert_type' => 'info',
1114 - 'content' => $message,
1115 - 'separator' => 'after',
1116 - ]
1117 - );
992 + $direction = is_rtl() ? '-rtl' : '';
993 +
994 + $css_file_path = 'css/widget-' . $widget_name . $direction . '.min.css';
995 +
996 + return [
997 + 'key' => $widget_name,
998 + 'version' => ELEMENTOR_VERSION,
999 + 'file_path' => ELEMENTOR_ASSETS_PATH . $css_file_path,
1000 + 'data' => [
1001 + 'file_url' => ELEMENTOR_ASSETS_URL . $css_file_path,
1002 + ],
1003 + ];
1004 + }
1005 +
1006 + private function get_widget_css() {
1007 + $widgets_css_data_manager = $this->get_widgets_css_data_manager();
1008 +
1009 + $widget_css = $widgets_css_data_manager->get_asset_data( $this->get_css_config() );
1010 +
1011 + return $widget_css;
1012 +
1013 + }
1014 +
1015 + private function print_widget_css() {
1016 + $is_edit_mode = Plugin::$instance->editor->is_edit_mode();
1017 + $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
1018 + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1019 +
1020 + if ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) {
1021 + return;
1022 + }
1023 +
1024 + echo wp_kses_post( $this->get_widget_css() );
1025 + }
1026 +
1027 + private function get_widgets_css_data_manager() {
1028 + if ( ! self::$widgets_css_data_manager ) {
1029 + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager();
1030 + }
1031 +
1032 + return self::$widgets_css_data_manager;
1118 1033 }
1119 1034 }