PluginProbe
Elementor Website Builder – more than just a page builder / 3.3.0
Elementor Website Builder – more than just a page builder v3.3.0
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 4.0.7 All 451 releases
← All changes | includes/base/widget-base.php +94 -165 4.2.23.3.0 View file →
@@ -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,10 @@
48 45 * @var array
49 46 */
50 47 public static $registered_runtime_widgets = [];
51 48
49 + private static $widgets_css_data_manager;
50 +
52 51 /**
53 52 * Get element type.
54 53 *
55 54 * Retrieve the element type, in this case `widget`.
@@ -106,22 +105,8 @@
106 105 return [ 'general' ];
107 106 }
108 107
109 108 /**
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 109 * Widget base constructor.
125 110 *
126 111 * Initializing the widget base class.
127 112 *
@@ -139,9 +124,9 @@
139 124
140 125 $is_type_instance = $this->is_type_instance();
141 126
142 127 if ( ! $is_type_instance && null === $args ) {
143 - 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.' );
144 129 }
145 130
146 131 if ( $is_type_instance ) {
147 132 if ( $this->has_own_method( '_register_skins', self::class ) ) {
@@ -183,11 +168,11 @@
183 168 */
184 169 public function get_stack( $with_common_controls = true ) {
185 170 $stack = parent::get_stack();
186 171
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() );
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' );
190 175
191 176 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
192 177
193 178 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
@@ -195,16 +180,8 @@
195 180
196 181 return $stack;
197 182 }
198 183
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 184 /**
208 185 * Get widget controls pointer index.
209 186 *
210 187 * Retrieve widget pointer index where the next control should be added.
@@ -241,21 +218,8 @@
241 218 return true;
242 219 }
243 220
244 221 /**
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 222 * Start widget controls section.
259 223 *
260 224 * Used to add a new section of controls to the widget. Regular controls and
261 225 * skin controls.
@@ -271,12 +235,14 @@
271 235 */
272 236 public function start_controls_section( $section_id, array $args = [] ) {
273 237 parent::start_controls_section( $section_id, $args );
274 238
275 - if ( $this->is_first_section ) {
239 + static $is_first_section = true;
240 +
241 + if ( $is_first_section ) {
276 242 $this->register_skin_control();
277 243
278 - $this->is_first_section = false;
244 + $is_first_section = false;
279 245 }
280 246 }
281 247
282 248 /**
@@ -293,9 +259,9 @@
293 259 if ( ! empty( $skins ) ) {
294 260 $skin_options = [];
295 261
296 262 if ( $this->_has_template_content ) {
297 - $skin_options[''] = esc_html__( 'Default', 'elementor' );
263 + $skin_options[''] = __( 'Default', 'elementor' );
298 264 }
299 265
300 266 foreach ( $skins as $skin_id => $skin ) {
301 267 $skin_options[ $skin_id ] = $skin->get_title();
@@ -300,9 +266,9 @@
300 266 foreach ( $skins as $skin_id => $skin ) {
301 267 $skin_options[ $skin_id ] = $skin->get_title();
302 268 }
303 269
304 - // Get the first item for default value.
270 + // Get the first item for default value
305 271 $default_value = array_keys( $skin_options );
306 272 $default_value = array_shift( $default_value );
307 273
308 274 if ( 1 >= count( $skin_options ) ) {
@@ -308,9 +274,9 @@
308 274 if ( 1 >= count( $skin_options ) ) {
309 275 $this->add_control(
310 276 '_skin',
311 277 [
312 - 'label' => esc_html__( 'Skin', 'elementor' ),
278 + 'label' => __( 'Skin', 'elementor' ),
313 279 'type' => Controls_Manager::HIDDEN,
314 280 'default' => $default_value,
315 281 ]
316 282 );
@@ -317,9 +283,9 @@
317 283 } else {
318 284 $this->add_control(
319 285 '_skin',
320 286 [
321 - 'label' => esc_html__( 'Skin', 'elementor' ),
287 + 'label' => __( 'Skin', 'elementor' ),
322 288 'type' => Controls_Manager::SELECT,
323 289 'default' => $default_value,
324 290 'options' => $skin_options,
325 291 ]
@@ -332,12 +298,12 @@
332 298 * Register widget skins - deprecated prefixed method
333 299 *
334 300 * @since 1.7.12
335 301 * @access protected
336 - * @deprecated 3.1.0 Use `register_skins()` method instead.
302 + * @deprecated 3.1.0
337 303 */
338 304 protected function _register_skins() {
339 - 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()' );
340 306
341 307 $this->register_skins();
342 308 }
343 309
@@ -378,23 +344,10 @@
378 344 'keywords' => $this->get_keywords(),
379 345 'categories' => $this->get_categories(),
380 346 'html_wrapper_class' => $this->get_html_wrapper_class(),
381 347 'show_in_panel' => $this->show_in_panel(),
382 - 'hide_on_search' => $this->hide_on_search(),
383 - 'upsale_data' => Plugin::$instance->experiments->is_feature_active( 'e_panel_promotions' ) ? null : $this->get_upsale_data(),
384 - 'is_dynamic_content' => $this->is_dynamic_content(),
385 - 'has_widget_inner_wrapper' => $this->has_widget_inner_wrapper(),
386 348 ];
387 349
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 350 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
398 351
399 352 if ( $stack ) {
400 353 $config['controls'] = $this->get_stack( false )['controls'];
@@ -400,9 +353,9 @@
400 353 $config['controls'] = $this->get_stack( false )['controls'];
401 354 $config['tabs_controls'] = $this->get_tabs_controls();
402 355 }
403 356
404 - return array_replace_recursive( parent::get_initial_config(), $config );
357 + return array_merge( parent::get_initial_config(), $config );
405 358 }
406 359
407 360 /**
408 361 * @since 2.3.1
@@ -423,15 +376,15 @@
423 376 *
424 377 * @param string $template_content Template content.
425 378 */
426 379 protected function print_template_content( $template_content ) {
427 - if ( $this->has_widget_inner_wrapper() ) : ?>
380 + ?>
428 381 <div class="elementor-widget-container">
429 - <?php endif;
430 - Utils::print_unescaped_internal_string( $template_content );
431 - if ( $this->has_widget_inner_wrapper() ) : ?>
382 + <?php
383 + echo $template_content; // XSS ok.
384 + ?>
432 385 </div>
433 - <?php endif;
386 + <?php
434 387 }
435 388
436 389 /**
437 390 * Parse text editor.
@@ -461,22 +414,8 @@
461 414 return $content;
462 415 }
463 416
464 417 /**
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 418 * Get HTML wrapper class.
480 419 *
481 420 * Retrieve the widget container class. Can be used to override the
482 421 * container class for specific widgets.
@@ -541,17 +480,18 @@
541 480 *
542 481 * Used to add Light-Box-related data attributes to links that open media files.
543 482 *
544 483 * @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.
484 + * @param int $id The ID of the image
485 + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox
486 + * @param string $group_id Unique ID for a group of lightbox images
487 + * @param bool $overwrite Optional. Whether to overwrite existing
488 + * attribute. Default is false, not to overwrite.
550 489 *
551 490 * @return Widget_Base Current instance of the widget.
552 491 * @since 2.9.0
553 492 * @access public
493 + *
554 494 */
555 495 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
556 496 $kit = Plugin::$instance->kits_manager->get_active_kit();
557 497
@@ -570,19 +510,10 @@
570 510 }
571 511
572 512 $attributes['data-elementor-open-lightbox'] = 'yes';
573 513
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 514 if ( $group_id ) {
582 515 $attributes['data-elementor-lightbox-slideshow'] = $group_id;
583 -
584 - $action_hash_params['slideshow'] = $group_id;
585 516 }
586 517
587 518 if ( $id ) {
588 519 $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id );
@@ -595,10 +526,8 @@
595 526 $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
596 527 }
597 528 }
598 529
599 - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
600 -
601 530 $this->add_render_attribute( $element, $attributes, null, $overwrite );
602 531
603 532 return $this;
604 533 }
@@ -640,16 +569,20 @@
640 569
641 570 if ( empty( $widget_content ) ) {
642 571 return;
643 572 }
644 - if ( $this->has_widget_inner_wrapper() ) : ?>
573 + ?>
645 574 <div class="elementor-widget-container">
646 - <?php endif; ?>
647 575 <?php
648 - if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
576 + if ( $this->is_widget_first_render() ) {
577 +
649 578 $this->register_runtime_widget( $this->get_group_name() );
579 +
580 + $this->print_widget_css();
650 581 }
651 582
583 + // get_name
584 +
652 585 /**
653 586 * Render widget content.
654 587 *
655 588 * Filters the widget content before it's rendered.
@@ -659,17 +592,17 @@
659 592 * @param string $widget_content The content of the widget.
660 593 * @param Widget_Base $this The widget.
661 594 */
662 595 $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
663 - Utils::print_unescaped_internal_string( $widget_content );
596 +
597 + echo $widget_content; // XSS ok.
664 598 ?>
665 - <?php if ( $this->has_widget_inner_wrapper() ) : ?>
666 599 </div>
667 - <?php endif;
600 + <?php
668 601 }
669 602
670 - protected function is_widget_first_render( $widget_name ) {
671 - return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
603 + protected function is_widget_first_render() {
604 + return ! in_array( $this->get_group_name(), self::$registered_runtime_widgets, true );
672 605 }
673 606
674 607 /**
675 608 * Render widget plain content.
@@ -696,16 +629,8 @@
696 629 public function render_plain_content() {
697 630 $this->render_content();
698 631 }
699 632
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 633 /**
709 634 * Before widget rendering.
710 635 *
711 636 * Used to add stuff before the widget `_wrapper` element.
@@ -787,12 +712,12 @@
787 712 *
788 713 * Script tags are allowed on frontend according to the WP theme securing policy.
789 714 *
790 715 * @param string $setting
791 - * @param null $repeater_name
792 - * @param null $index
716 + * @param null $repeater_name
717 + * @param null $index
793 718 */
794 - final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
719 + final protected function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
795 720 if ( $repeater_name ) {
796 721 $repeater = $this->get_settings_for_display( $repeater_name );
797 722 $output = $repeater[ $index ][ $setting ];
798 723 } else {
@@ -855,9 +780,9 @@
855 780 * @access protected
856 781 *
857 782 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
858 783 * @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`).
784 + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
860 785 *
861 786 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
862 787 */
863 788 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
@@ -1014,18 +939,17 @@
1014 939 return $this->get_name();
1015 940 }
1016 941
1017 942 /**
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.
943 + * @param string $plugin_title Plugin's title
944 + * @param string $since Plugin version widget was deprecated
945 + * @param string $last Plugin version in which the widget will be removed
946 + * @param string $replacement Widget replacement
1022 947 */
1023 948 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1024 - $this->start_controls_section(
1025 - 'Deprecated',
949 + $this->start_controls_section( 'Deprecated',
1026 950 [
1027 - 'label' => esc_html__( 'Deprecated', 'elementor' ),
951 + 'label' => __( 'Deprecated', 'elementor' ),
1028 952 ]
1029 953 );
1030 954
1031 955 $this->add_control(
@@ -1040,22 +964,9 @@
1040 964 ]
1041 965 );
1042 966
1043 967 $this->end_controls_section();
1044 - }
1045 968
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 969 }
1059 970
1060 971 public function register_runtime_widget( $widget_name ) {
1061 972 self::$registered_runtime_widgets[] = $widget_name;
@@ -1060,32 +971,50 @@
1060 971 public function register_runtime_widget( $widget_name ) {
1061 972 self::$registered_runtime_widgets[] = $widget_name;
1062 973 }
1063 974
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 - ] );
975 + public function get_css_config() {
976 + $widget_name = $this->get_group_name();
1080 977
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 - );
978 + $direction = is_rtl() ? '-rtl' : '';
979 +
980 + $css_file_path = 'css/widget-' . $widget_name . $direction . '.min.css';
981 +
982 + return [
983 + 'key' => $widget_name,
984 + 'version' => ELEMENTOR_VERSION,
985 + 'file_path' => ELEMENTOR_ASSETS_PATH . $css_file_path,
986 + 'data' => [
987 + 'file_url' => ELEMENTOR_ASSETS_URL . $css_file_path,
988 + ],
989 + ];
990 + }
991 +
992 + private function get_widget_css() {
993 + $widgets_css_data_manager = $this->get_widgets_css_data_manager();
994 +
995 + $widget_css = $widgets_css_data_manager->get_asset_data( $this->get_css_config() );
996 +
997 + return $widget_css;
998 +
999 + }
1000 +
1001 + private function print_widget_css() {
1002 + $is_edit_mode = Plugin::$instance->editor->is_edit_mode();
1003 + $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
1004 + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1005 +
1006 + if ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) {
1007 + return;
1008 + }
1009 +
1010 + echo $this->get_widget_css();
1011 + }
1012 +
1013 + private function get_widgets_css_data_manager() {
1014 + if ( ! self::$widgets_css_data_manager ) {
1015 + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager();
1016 + }
1017 +
1018 + return self::$widgets_css_data_manager;
1090 1019 }
1091 1020 }