PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.0
Elementor Website Builder – more than just a page builder v3.2.0
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 +41 -253 4.3.0-beta33.2.0 View file →
@@ -1,11 +1,7 @@
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;
7 -
8 4 if ( ! defined( 'ABSPATH' ) ) {
9 5 exit; // Exit if accessed directly.
10 6 }
11 7
@@ -20,8 +16,9 @@
20 16 * @since 1.0.0
21 17 * @abstract
22 18 */
23 19 abstract class Widget_Base extends Element_Base {
20 +
24 21 /**
25 22 * Whether the widget has content.
26 23 *
27 24 * Used in cases where the widget has no content. When widgets uses only
@@ -34,24 +31,9 @@
34 31 * @var bool
35 32 */
36 33 protected $_has_template_content = true;
37 34
38 - private $is_first_section = true;
39 -
40 35 /**
41 - * Registered Runtime Widgets.
42 - *
43 - * Registering in runtime all widgets that are being used on the page.
44 - *
45 - * @since 3.3.0
46 - * @access public
47 - * @static
48 - *
49 - * @var array
50 - */
51 - public static $registered_runtime_widgets = [];
52 -
53 - /**
54 36 * Get element type.
55 37 *
56 38 * Retrieve the element type, in this case `widget`.
57 39 *
@@ -107,22 +89,8 @@
107 89 return [ 'general' ];
108 90 }
109 91
110 92 /**
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 93 * Widget base constructor.
126 94 *
127 95 * Initializing the widget base class.
128 96 *
@@ -140,9 +108,9 @@
140 108
141 109 $is_type_instance = $this->is_type_instance();
142 110
143 111 if ( ! $is_type_instance && null === $args ) {
144 - throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' );
112 + throw new \Exception( '`$args` argument is required when initializing a full widget instance.' );
145 113 }
146 114
147 115 if ( $is_type_instance ) {
148 116 if ( $this->has_own_method( '_register_skins', self::class ) ) {
@@ -184,11 +152,11 @@
184 152 */
185 153 public function get_stack( $with_common_controls = true ) {
186 154 $stack = parent::get_stack();
187 155
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() );
156 + if ( $with_common_controls && 'common' !== $this->get_unique_name() ) {
157 + /** @var Widget_Common $common_widget */
158 + $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' );
191 159
192 160 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
193 161
194 162 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
@@ -196,16 +164,8 @@
196 164
197 165 return $stack;
198 166 }
199 167
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 168 /**
209 169 * Get widget controls pointer index.
210 170 *
211 171 * Retrieve widget pointer index where the next control should be added.
@@ -242,21 +202,8 @@
242 202 return true;
243 203 }
244 204
245 205 /**
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 206 * Start widget controls section.
260 207 *
261 208 * Used to add a new section of controls to the widget. Regular controls and
262 209 * skin controls.
@@ -272,12 +219,14 @@
272 219 */
273 220 public function start_controls_section( $section_id, array $args = [] ) {
274 221 parent::start_controls_section( $section_id, $args );
275 222
276 - if ( $this->is_first_section ) {
223 + static $is_first_section = true;
224 +
225 + if ( $is_first_section ) {
277 226 $this->register_skin_control();
278 227
279 - $this->is_first_section = false;
228 + $is_first_section = false;
280 229 }
281 230 }
282 231
283 232 /**
@@ -294,9 +243,9 @@
294 243 if ( ! empty( $skins ) ) {
295 244 $skin_options = [];
296 245
297 246 if ( $this->_has_template_content ) {
298 - $skin_options[''] = esc_html__( 'Default', 'elementor' );
247 + $skin_options[''] = __( 'Default', 'elementor' );
299 248 }
300 249
301 250 foreach ( $skins as $skin_id => $skin ) {
302 251 $skin_options[ $skin_id ] = $skin->get_title();
@@ -301,9 +250,9 @@
301 250 foreach ( $skins as $skin_id => $skin ) {
302 251 $skin_options[ $skin_id ] = $skin->get_title();
303 252 }
304 253
305 - // Get the first item for default value.
254 + // Get the first item for default value
306 255 $default_value = array_keys( $skin_options );
307 256 $default_value = array_shift( $default_value );
308 257
309 258 if ( 1 >= count( $skin_options ) ) {
@@ -309,9 +258,9 @@
309 258 if ( 1 >= count( $skin_options ) ) {
310 259 $this->add_control(
311 260 '_skin',
312 261 [
313 - 'label' => esc_html__( 'Skin', 'elementor' ),
262 + 'label' => __( 'Skin', 'elementor' ),
314 263 'type' => Controls_Manager::HIDDEN,
315 264 'default' => $default_value,
316 265 ]
317 266 );
@@ -318,9 +267,9 @@
318 267 } else {
319 268 $this->add_control(
320 269 '_skin',
321 270 [
322 - 'label' => esc_html__( 'Skin', 'elementor' ),
271 + 'label' => __( 'Skin', 'elementor' ),
323 272 'type' => Controls_Manager::SELECT,
324 273 'default' => $default_value,
325 274 'options' => $skin_options,
326 275 ]
@@ -333,12 +282,12 @@
333 282 * Register widget skins - deprecated prefixed method
334 283 *
335 284 * @since 1.7.12
336 285 * @access protected
337 - * @deprecated 3.1.0 Use `register_skins()` method instead.
286 + * @deprecated 3.1.0
338 287 */
339 288 protected function _register_skins() {
340 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' );
289 + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_skins()' );
341 290
342 291 $this->register_skins();
343 292 }
344 293
@@ -379,23 +328,10 @@
379 328 'keywords' => $this->get_keywords(),
380 329 'categories' => $this->get_categories(),
381 330 'html_wrapper_class' => $this->get_html_wrapper_class(),
382 331 '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 332 ];
388 333
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 334 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
399 335
400 336 if ( $stack ) {
401 337 $config['controls'] = $this->get_stack( false )['controls'];
@@ -401,9 +337,9 @@
401 337 $config['controls'] = $this->get_stack( false )['controls'];
402 338 $config['tabs_controls'] = $this->get_tabs_controls();
403 339 }
404 340
405 - return array_replace_recursive( parent::get_initial_config(), $config );
341 + return array_merge( parent::get_initial_config(), $config );
406 342 }
407 343
408 344 /**
409 345 * @since 2.3.1
@@ -424,15 +360,15 @@
424 360 *
425 361 * @param string $template_content Template content.
426 362 */
427 363 protected function print_template_content( $template_content ) {
428 - if ( $this->has_widget_inner_wrapper() ) : ?>
364 + ?>
429 365 <div class="elementor-widget-container">
430 - <?php endif;
431 - Utils::print_unescaped_internal_string( $template_content );
432 - if ( $this->has_widget_inner_wrapper() ) : ?>
366 + <?php
367 + echo $template_content; // XSS ok.
368 + ?>
433 369 </div>
434 - <?php endif;
370 + <?php
435 371 }
436 372
437 373 /**
438 374 * Parse text editor.
@@ -462,22 +398,8 @@
462 398 return $content;
463 399 }
464 400
465 401 /**
466 - * Safe print parsed text editor.
467 - *
468 - * @uses static::parse_text_editor.
469 - *
470 - * @access protected
471 - *
472 - * @param string $content Text editor content.
473 - */
474 - final protected function print_text_editor( $content ) {
475 - // PHPCS - the method `parse_text_editor` is safe.
476 - echo static::parse_text_editor( $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
477 - }
478 -
479 - /**
480 402 * Get HTML wrapper class.
481 403 *
482 404 * Retrieve the widget container class. Can be used to override the
483 405 * container class for specific widgets.
@@ -542,17 +464,18 @@
542 464 *
543 465 * Used to add Light-Box-related data attributes to links that open media files.
544 466 *
545 467 * @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.
468 + * @param int $id The ID of the image
469 + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox
470 + * @param string $group_id Unique ID for a group of lightbox images
471 + * @param bool $overwrite Optional. Whether to overwrite existing
472 + * attribute. Default is false, not to overwrite.
551 473 *
552 474 * @return Widget_Base Current instance of the widget.
553 475 * @since 2.9.0
554 476 * @access public
477 + *
555 478 */
556 479 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
557 480 $kit = Plugin::$instance->kits_manager->get_active_kit();
558 481
@@ -559,9 +482,9 @@
559 482 $is_global_image_lightbox_enabled = 'yes' === $kit->get_settings( 'global_image_lightbox' );
560 483
561 484 if ( 'no' === $lightbox_setting_key ) {
562 485 if ( $is_global_image_lightbox_enabled ) {
563 - $this->add_render_attribute( $element, 'data-elementor-open-lightbox', 'no', $overwrite );
486 + $this->add_render_attribute( $element, 'data-elementor-open-lightbox', 'no' );
564 487 }
565 488
566 489 return $this;
567 490 }
@@ -571,19 +494,10 @@
571 494 }
572 495
573 496 $attributes['data-elementor-open-lightbox'] = 'yes';
574 497
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 498 if ( $group_id ) {
583 499 $attributes['data-elementor-lightbox-slideshow'] = $group_id;
584 -
585 - $action_hash_params['slideshow'] = $group_id;
586 500 }
587 501
588 502 if ( $id ) {
589 503 $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id );
@@ -596,10 +510,8 @@
596 510 $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
597 511 }
598 512 }
599 513
600 - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
601 -
602 514 $this->add_render_attribute( $element, $attributes, null, $overwrite );
603 515
604 516 return $this;
605 517 }
@@ -624,9 +536,9 @@
624 536 * @since 1.0.0
625 537 *
626 538 * @param Widget_Base $this The current widget.
627 539 */
628 - do_action( 'elementor/widget/before_render_content', $this, [ 'mode' => Widget_Content_Render_Mode::NORMAL ] );
540 + do_action( 'elementor/widget/before_render_content', $this );
629 541
630 542 ob_start();
631 543
632 544 $skin = $this->get_current_skin();
@@ -641,15 +553,11 @@
641 553
642 554 if ( empty( $widget_content ) ) {
643 555 return;
644 556 }
645 - if ( $this->has_widget_inner_wrapper() ) : ?>
557 + ?>
646 558 <div class="elementor-widget-container">
647 - <?php endif; ?>
648 559 <?php
649 - if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
650 - $this->register_runtime_widget( $this->get_group_name() );
651 - }
652 560
653 561 /**
654 562 * Render widget content.
655 563 *
@@ -659,20 +567,16 @@
659 567 *
660 568 * @param string $widget_content The content of the widget.
661 569 * @param Widget_Base $this The widget.
662 570 */
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 );
571 + $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
572 +
573 + echo $widget_content; // XSS ok.
665 574 ?>
666 - <?php if ( $this->has_widget_inner_wrapper() ) : ?>
667 575 </div>
668 - <?php endif;
576 + <?php
669 577 }
670 578
671 - protected function is_widget_first_render( $widget_name ) {
672 - return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
673 - }
674 -
675 579 /**
676 580 * Render widget plain content.
677 581 *
678 582 * Elementor saves the page content in a unique way, but it's not the way
@@ -697,43 +601,8 @@
697 601 public function render_plain_content() {
698 602 $this->render_content();
699 603 }
700 604
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 605 /**
737 606 * Before widget rendering.
738 607 *
739 608 * Used to add stuff before the widget `_wrapper` element.
@@ -810,28 +679,8 @@
810 679 $this->render_content();
811 680 }
812 681
813 682 /**
814 - * Print a setting content without escaping.
815 - *
816 - * Script tags are allowed on frontend according to the WP theme securing policy.
817 - *
818 - * @param string $setting
819 - * @param null $repeater_name
820 - * @param null $index
821 - */
822 - final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
823 - if ( $repeater_name ) {
824 - $repeater = $this->get_settings_for_display( $repeater_name );
825 - $output = $repeater[ $index ][ $setting ];
826 - } else {
827 - $output = $this->get_settings_for_display( $setting );
828 - }
829 -
830 - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
831 - }
832 -
833 - /**
834 683 * Get default data.
835 684 *
836 685 * Retrieve the default widget data. Used to reset the data on initialization.
837 686 *
@@ -883,9 +732,9 @@
883 732 * @access protected
884 733 *
885 734 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
886 735 * @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`).
736 + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
888 737 *
889 738 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
890 739 */
891 740 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
@@ -1027,33 +876,17 @@
1027 876 return Plugin::$instance->skins_manager->get_skins( $this );
1028 877 }
1029 878
1030 879 /**
1031 - * Get group name.
1032 - *
1033 - * Some widgets need to use group names, this method allows you to create them.
1034 - * By default it retrieves the regular name.
1035 - *
1036 - * @since 3.3.0
1037 - * @access public
1038 - *
1039 - * @return string Unique name.
880 + * @param string $plugin_title Plugin's title
881 + * @param string $since Plugin version widget was deprecated
882 + * @param string $last Plugin version in which the widget will be removed
883 + * @param string $replacement Widget replacement
1040 884 */
1041 - public function get_group_name() {
1042 - return $this->get_name();
1043 - }
1044 -
1045 - /**
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.
1050 - */
1051 885 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1052 - $this->start_controls_section(
1053 - 'Deprecated',
886 + $this->start_controls_section( 'Deprecated',
1054 887 [
1055 - 'label' => esc_html__( 'Deprecated', 'elementor' ),
888 + 'label' => __( 'Deprecated', 'elementor' ),
1056 889 ]
1057 890 );
1058 891
1059 892 $this->add_control(
@@ -1068,52 +901,7 @@
1068 901 ]
1069 902 );
1070 903
1071 904 $this->end_controls_section();
1072 - }
1073 905
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 - }
1087 -
1088 - public function register_runtime_widget( $widget_name ) {
1089 - self::$registered_runtime_widgets[] = $widget_name;
1090 - }
1091 -
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 - ] );
1108 -
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 - );
1118 906 }
1119 907 }