PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.0-dev9
Elementor Website Builder – more than just a page builder v3.5.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 +149 -173 4.3.0-beta23.5.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,12 @@
49 45 * @var array
50 46 */
51 47 public static $registered_runtime_widgets = [];
52 48
49 + public static $registered_inline_css_widgets = [];
50 +
51 + private static $widgets_css_data_manager;
52 +
53 53 /**
54 54 * Get element type.
55 55 *
56 56 * Retrieve the element type, in this case `widget`.
@@ -107,22 +107,8 @@
107 107 return [ 'general' ];
108 108 }
109 109
110 110 /**
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 111 * Widget base constructor.
126 112 *
127 113 * Initializing the widget base class.
128 114 *
@@ -140,9 +126,9 @@
140 126
141 127 $is_type_instance = $this->is_type_instance();
142 128
143 129 if ( ! $is_type_instance && null === $args ) {
144 - 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.' );
145 131 }
146 132
147 133 if ( $is_type_instance ) {
148 134 if ( $this->has_own_method( '_register_skins', self::class ) ) {
@@ -184,11 +170,11 @@
184 170 */
185 171 public function get_stack( $with_common_controls = true ) {
186 172 $stack = parent::get_stack();
187 173
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() );
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' );
191 177
192 178 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
193 179
194 180 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
@@ -196,16 +182,8 @@
196 182
197 183 return $stack;
198 184 }
199 185
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 186 /**
209 187 * Get widget controls pointer index.
210 188 *
211 189 * Retrieve widget pointer index where the next control should be added.
@@ -242,21 +220,8 @@
242 220 return true;
243 221 }
244 222
245 223 /**
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 224 * Start widget controls section.
260 225 *
261 226 * Used to add a new section of controls to the widget. Regular controls and
262 227 * skin controls.
@@ -272,12 +237,14 @@
272 237 */
273 238 public function start_controls_section( $section_id, array $args = [] ) {
274 239 parent::start_controls_section( $section_id, $args );
275 240
276 - if ( $this->is_first_section ) {
241 + static $is_first_section = true;
242 +
243 + if ( $is_first_section ) {
277 244 $this->register_skin_control();
278 245
279 - $this->is_first_section = false;
246 + $is_first_section = false;
280 247 }
281 248 }
282 249
283 250 /**
@@ -301,9 +268,9 @@
301 268 foreach ( $skins as $skin_id => $skin ) {
302 269 $skin_options[ $skin_id ] = $skin->get_title();
303 270 }
304 271
305 - // Get the first item for default value.
272 + // Get the first item for default value
306 273 $default_value = array_keys( $skin_options );
307 274 $default_value = array_shift( $default_value );
308 275
309 276 if ( 1 >= count( $skin_options ) ) {
@@ -333,12 +300,12 @@
333 300 * Register widget skins - deprecated prefixed method
334 301 *
335 302 * @since 1.7.12
336 303 * @access protected
337 - * @deprecated 3.1.0 Use `register_skins()` method instead.
304 + * @deprecated 3.1.0
338 305 */
339 306 protected function _register_skins() {
340 - 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()' );
341 308
342 309 $this->register_skins();
343 310 }
344 311
@@ -379,23 +346,10 @@
379 346 'keywords' => $this->get_keywords(),
380 347 'categories' => $this->get_categories(),
381 348 'html_wrapper_class' => $this->get_html_wrapper_class(),
382 349 '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 350 ];
388 351
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 352 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
399 353
400 354 if ( $stack ) {
401 355 $config['controls'] = $this->get_stack( false )['controls'];
@@ -401,9 +355,9 @@
401 355 $config['controls'] = $this->get_stack( false )['controls'];
402 356 $config['tabs_controls'] = $this->get_tabs_controls();
403 357 }
404 358
405 - return array_replace_recursive( parent::get_initial_config(), $config );
359 + return array_merge( parent::get_initial_config(), $config );
406 360 }
407 361
408 362 /**
409 363 * @since 2.3.1
@@ -424,15 +378,15 @@
424 378 *
425 379 * @param string $template_content Template content.
426 380 */
427 381 protected function print_template_content( $template_content ) {
428 - if ( $this->has_widget_inner_wrapper() ) : ?>
382 + ?>
429 383 <div class="elementor-widget-container">
430 - <?php endif;
431 - Utils::print_unescaped_internal_string( $template_content );
432 - if ( $this->has_widget_inner_wrapper() ) : ?>
384 + <?php
385 + echo $template_content; // XSS ok.
386 + ?>
433 387 </div>
434 - <?php endif;
388 + <?php
435 389 }
436 390
437 391 /**
438 392 * Parse text editor.
@@ -542,17 +496,18 @@
542 496 *
543 497 * Used to add Light-Box-related data attributes to links that open media files.
544 498 *
545 499 * @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.
500 + * @param int $id The ID of the image
501 + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox
502 + * @param string $group_id Unique ID for a group of lightbox images
503 + * @param bool $overwrite Optional. Whether to overwrite existing
504 + * attribute. Default is false, not to overwrite.
551 505 *
552 506 * @return Widget_Base Current instance of the widget.
553 507 * @since 2.9.0
554 508 * @access public
509 + *
555 510 */
556 511 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
557 512 $kit = Plugin::$instance->kits_manager->get_active_kit();
558 513
@@ -571,19 +526,10 @@
571 526 }
572 527
573 528 $attributes['data-elementor-open-lightbox'] = 'yes';
574 529
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 530 if ( $group_id ) {
583 531 $attributes['data-elementor-lightbox-slideshow'] = $group_id;
584 -
585 - $action_hash_params['slideshow'] = $group_id;
586 532 }
587 533
588 534 if ( $id ) {
589 535 $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id );
@@ -596,10 +542,8 @@
596 542 $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
597 543 }
598 544 }
599 545
600 - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
601 -
602 546 $this->add_render_attribute( $element, $attributes, null, $overwrite );
603 547
604 548 return $this;
605 549 }
@@ -624,9 +568,9 @@
624 568 * @since 1.0.0
625 569 *
626 570 * @param Widget_Base $this The current widget.
627 571 */
628 - do_action( 'elementor/widget/before_render_content', $this, [ 'mode' => Widget_Content_Render_Mode::NORMAL ] );
572 + do_action( 'elementor/widget/before_render_content', $this );
629 573
630 574 ob_start();
631 575
632 576 $skin = $this->get_current_skin();
@@ -641,16 +585,19 @@
641 585
642 586 if ( empty( $widget_content ) ) {
643 587 return;
644 588 }
645 - if ( $this->has_widget_inner_wrapper() ) : ?>
589 + ?>
646 590 <div class="elementor-widget-container">
647 - <?php endif; ?>
648 591 <?php
649 592 if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
650 593 $this->register_runtime_widget( $this->get_group_name() );
651 594 }
652 595
596 + $this->print_widget_css();
597 +
598 + // get_name
599 +
653 600 /**
654 601 * Render widget content.
655 602 *
656 603 * Filters the widget content before it's rendered.
@@ -659,14 +606,14 @@
659 606 *
660 607 * @param string $widget_content The content of the widget.
661 608 * @param Widget_Base $this The widget.
662 609 */
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 );
610 + $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
611 +
612 + echo $widget_content; // XSS ok.
665 613 ?>
666 - <?php if ( $this->has_widget_inner_wrapper() ) : ?>
667 614 </div>
668 - <?php endif;
615 + <?php
669 616 }
670 617
671 618 protected function is_widget_first_render( $widget_name ) {
672 619 return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
@@ -697,43 +644,8 @@
697 644 public function render_plain_content() {
698 645 $this->render_content();
699 646 }
700 647
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 648 /**
737 649 * Before widget rendering.
738 650 *
739 651 * Used to add stuff before the widget `_wrapper` element.
@@ -815,12 +727,12 @@
815 727 *
816 728 * Script tags are allowed on frontend according to the WP theme securing policy.
817 729 *
818 730 * @param string $setting
819 - * @param null $repeater_name
820 - * @param null $index
731 + * @param null $repeater_name
732 + * @param null $index
821 733 */
822 - final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
734 + final protected function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
823 735 if ( $repeater_name ) {
824 736 $repeater = $this->get_settings_for_display( $repeater_name );
825 737 $output = $repeater[ $index ][ $setting ];
826 738 } else {
@@ -883,9 +795,9 @@
883 795 * @access protected
884 796 *
885 797 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
886 798 * @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`).
799 + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
888 800 *
889 801 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
890 802 */
891 803 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
@@ -1042,16 +954,29 @@
1042 954 return $this->get_name();
1043 955 }
1044 956
1045 957 /**
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.
958 + * Get Inline CSS dependencies.
959 + *
960 + * Retrieve a list of inline CSS dependencies that the element requires.
961 + *
962 + * @since 3.3.0
963 + * @access public
964 + *
965 + * @return array.
1050 966 */
967 + public function get_inline_css_depends() {
968 + return [];
969 + }
970 +
971 + /**
972 + * @param string $plugin_title Plugin's title
973 + * @param string $since Plugin version widget was deprecated
974 + * @param string $last Plugin version in which the widget will be removed
975 + * @param string $replacement Widget replacement
976 + */
1051 977 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1052 - $this->start_controls_section(
1053 - 'Deprecated',
978 + $this->start_controls_section( 'Deprecated',
1054 979 [
1055 980 'label' => esc_html__( 'Deprecated', 'elementor' ),
1056 981 ]
1057 982 );
@@ -1068,22 +993,9 @@
1068 993 ]
1069 994 );
1070 995
1071 996 $this->end_controls_section();
1072 - }
1073 997
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 998 }
1087 999
1088 1000 public function register_runtime_widget( $widget_name ) {
1089 1001 self::$registered_runtime_widgets[] = $widget_name;
@@ -1088,32 +1000,96 @@
1088 1000 public function register_runtime_widget( $widget_name ) {
1089 1001 self::$registered_runtime_widgets[] = $widget_name;
1090 1002 }
1091 1003
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,
1004 + public function get_widget_css_config( $widget_name ) {
1005 + $direction = is_rtl() ? '-rtl' : '';
1006 +
1007 + $css_file_path = 'css/widget-' . $widget_name . $direction . '.min.css';
1008 +
1009 + return [
1010 + 'key' => $widget_name,
1011 + 'version' => ELEMENTOR_VERSION,
1012 + 'file_path' => ELEMENTOR_ASSETS_PATH . $css_file_path,
1013 + 'data' => [
1014 + 'file_url' => ELEMENTOR_ASSETS_URL . $css_file_path,
1015 + ],
1016 + ];
1017 + }
1018 +
1019 + public function get_css_config() {
1020 + return $this->get_widget_css_config( $this->get_group_name() );
1021 + }
1022 +
1023 + private function get_widget_css() {
1024 + $widgets_css_data_manager = $this->get_widgets_css_data_manager();
1025 +
1026 + $widgets_list = $this->get_inline_css_depends();
1027 +
1028 + $widgets_list[] = $this->get_group_name();
1029 +
1030 + $widget_css = '';
1031 +
1032 + foreach ( $widgets_list as $widget_data ) {
1033 + $widget_name = isset( $widget_data['name'] ) ? $widget_data['name'] : $widget_data;
1034 +
1035 + if ( ! in_array( $widget_name, self::$registered_inline_css_widgets, true ) ) {
1036 + if ( $this->get_group_name() === $widget_name ) {
1037 + $config = $this->get_css_config();
1038 + } else {
1039 + /**
1040 + * The core-dependency allowing to create a dependency specifically with the core widgets.
1041 + * Otherwise, the config will be taken from the class that inherits from Widget_Base.
1042 + */
1043 + $is_core_dependency = isset( $widget_data['is_core_dependency'] ) ? true : false;
1044 +
1045 + $config = $is_core_dependency ? self::get_widget_css_config( $widget_name ) : $this->get_widget_css_config( $widget_name );
1046 + }
1047 +
1048 + $widget_css .= $widgets_css_data_manager->get_asset_data( $config );
1049 +
1050 + self::$registered_inline_css_widgets[] = $widget_name;
1051 + }
1052 + }
1053 +
1054 + return $widget_css;
1055 +
1056 + }
1057 +
1058 + private function is_inline_css_mode() {
1059 + static $is_active;
1060 +
1061 + if ( null === $is_active ) {
1062 + $is_edit_mode = Plugin::$instance->editor->is_edit_mode();
1063 + $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
1064 + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1065 +
1066 + $is_active = ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) ? false : true;
1067 + }
1068 +
1069 + return $is_active;
1070 + }
1071 +
1072 + private function print_widget_css() {
1073 + if ( ! $this->is_inline_css_mode() ) {
1074 + return;
1075 + }
1076 +
1077 + $widget_css = $this->get_widget_css();
1078 +
1079 + echo wp_kses( $widget_css, [
1080 + 'style' => [],
1081 + 'link' => [
1082 + 'rel' => true,
1083 + 'href' => true,
1084 + ],
1107 1085 ] );
1086 + }
1108 1087
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 - );
1088 + private function get_widgets_css_data_manager() {
1089 + if ( ! self::$widgets_css_data_manager ) {
1090 + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager();
1091 + }
1092 +
1093 + return self::$widgets_css_data_manager;
1118 1094 }
1119 1095 }