PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.3
Elementor Website Builder – more than just a page builder v3.5.3
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 +205 -133 4.2.0-dev23.5.3 View file →
@@ -1,9 +1,9 @@
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\Responsive_Widgets as Responsive_Widgets_Data_Manager;
5 +use Elementor\Core\Page_Assets\Data_Managers\Widgets_Css as Widgets_Css_Data_Manager;
6 6
7 7 if ( ! defined( 'ABSPATH' ) ) {
8 8 exit; // Exit if accessed directly.
9 9 }
@@ -33,10 +33,8 @@
33 33 * @var bool
34 34 */
35 35 protected $_has_template_content = true;
36 36
37 - private $is_first_section = true;
38 -
39 37 /**
40 38 * Registered Runtime Widgets.
41 39 *
42 40 * Registering in runtime all widgets that are being used on the page.
@@ -48,8 +46,14 @@
48 46 * @var array
49 47 */
50 48 public static $registered_runtime_widgets = [];
51 49
50 + public static $registered_inline_css_widgets = [];
51 +
52 + private static $widgets_css_data_manager;
53 +
54 + private static $responsive_widgets_data_manager;
55 +
52 56 /**
53 57 * Get element type.
54 58 *
55 59 * Retrieve the element type, in this case `widget`.
@@ -106,22 +110,8 @@
106 110 return [ 'general' ];
107 111 }
108 112
109 113 /**
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 114 * Widget base constructor.
125 115 *
126 116 * Initializing the widget base class.
127 117 *
@@ -139,9 +129,9 @@
139 129
140 130 $is_type_instance = $this->is_type_instance();
141 131
142 132 if ( ! $is_type_instance && null === $args ) {
143 - throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' );
133 + throw new \Exception( '`$args` argument is required when initializing a full widget instance.' );
144 134 }
145 135
146 136 if ( $is_type_instance ) {
147 137 if ( $this->has_own_method( '_register_skins', self::class ) ) {
@@ -183,11 +173,11 @@
183 173 */
184 174 public function get_stack( $with_common_controls = true ) {
185 175 $stack = parent::get_stack();
186 176
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() );
177 + if ( $with_common_controls && 'common' !== $this->get_unique_name() ) {
178 + /** @var Widget_Common $common_widget */
179 + $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' );
190 180
191 181 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
192 182
193 183 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
@@ -195,16 +185,8 @@
195 185
196 186 return $stack;
197 187 }
198 188
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 189 /**
208 190 * Get widget controls pointer index.
209 191 *
210 192 * Retrieve widget pointer index where the next control should be added.
@@ -241,21 +223,8 @@
241 223 return true;
242 224 }
243 225
244 226 /**
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 227 * Start widget controls section.
259 228 *
260 229 * Used to add a new section of controls to the widget. Regular controls and
261 230 * skin controls.
@@ -271,12 +240,14 @@
271 240 */
272 241 public function start_controls_section( $section_id, array $args = [] ) {
273 242 parent::start_controls_section( $section_id, $args );
274 243
275 - if ( $this->is_first_section ) {
244 + static $is_first_section = true;
245 +
246 + if ( $is_first_section ) {
276 247 $this->register_skin_control();
277 248
278 - $this->is_first_section = false;
249 + $is_first_section = false;
279 250 }
280 251 }
281 252
282 253 /**
@@ -300,9 +271,9 @@
300 271 foreach ( $skins as $skin_id => $skin ) {
301 272 $skin_options[ $skin_id ] = $skin->get_title();
302 273 }
303 274
304 - // Get the first item for default value.
275 + // Get the first item for default value
305 276 $default_value = array_keys( $skin_options );
306 277 $default_value = array_shift( $default_value );
307 278
308 279 if ( 1 >= count( $skin_options ) ) {
@@ -332,12 +303,12 @@
332 303 * Register widget skins - deprecated prefixed method
333 304 *
334 305 * @since 1.7.12
335 306 * @access protected
336 - * @deprecated 3.1.0 Use `register_skins()` method instead.
307 + * @deprecated 3.1.0
337 308 */
338 309 protected function _register_skins() {
339 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' );
310 + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_skins()' );
340 311
341 312 $this->register_skins();
342 313 }
343 314
@@ -378,23 +349,10 @@
378 349 'keywords' => $this->get_keywords(),
379 350 'categories' => $this->get_categories(),
380 351 'html_wrapper_class' => $this->get_html_wrapper_class(),
381 352 '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 353 ];
387 354
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 355 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
398 356
399 357 if ( $stack ) {
400 358 $config['controls'] = $this->get_stack( false )['controls'];
@@ -423,15 +381,15 @@
423 381 *
424 382 * @param string $template_content Template content.
425 383 */
426 384 protected function print_template_content( $template_content ) {
427 - if ( $this->has_widget_inner_wrapper() ) : ?>
385 + ?>
428 386 <div class="elementor-widget-container">
429 - <?php endif;
430 - Utils::print_unescaped_internal_string( $template_content );
431 - if ( $this->has_widget_inner_wrapper() ) : ?>
387 + <?php
388 + echo $template_content; // XSS ok.
389 + ?>
432 390 </div>
433 - <?php endif;
391 + <?php
434 392 }
435 393
436 394 /**
437 395 * Parse text editor.
@@ -541,17 +499,18 @@
541 499 *
542 500 * Used to add Light-Box-related data attributes to links that open media files.
543 501 *
544 502 * @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.
503 + * @param int $id The ID of the image
504 + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox
505 + * @param string $group_id Unique ID for a group of lightbox images
506 + * @param bool $overwrite Optional. Whether to overwrite existing
507 + * attribute. Default is false, not to overwrite.
550 508 *
551 509 * @return Widget_Base Current instance of the widget.
552 510 * @since 2.9.0
553 511 * @access public
512 + *
554 513 */
555 514 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
556 515 $kit = Plugin::$instance->kits_manager->get_active_kit();
557 516
@@ -570,19 +529,10 @@
570 529 }
571 530
572 531 $attributes['data-elementor-open-lightbox'] = 'yes';
573 532
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 533 if ( $group_id ) {
582 534 $attributes['data-elementor-lightbox-slideshow'] = $group_id;
583 -
584 - $action_hash_params['slideshow'] = $group_id;
585 535 }
586 536
587 537 if ( $id ) {
588 538 $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id );
@@ -595,10 +545,8 @@
595 545 $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
596 546 }
597 547 }
598 548
599 - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
600 -
601 549 $this->add_render_attribute( $element, $attributes, null, $overwrite );
602 550
603 551 return $this;
604 552 }
@@ -640,16 +588,19 @@
640 588
641 589 if ( empty( $widget_content ) ) {
642 590 return;
643 591 }
644 - if ( $this->has_widget_inner_wrapper() ) : ?>
592 + ?>
645 593 <div class="elementor-widget-container">
646 - <?php endif; ?>
647 594 <?php
648 595 if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
649 596 $this->register_runtime_widget( $this->get_group_name() );
650 597 }
651 598
599 + $this->print_widget_css();
600 +
601 + // get_name
602 +
652 603 /**
653 604 * Render widget content.
654 605 *
655 606 * Filters the widget content before it's rendered.
@@ -659,13 +610,13 @@
659 610 * @param string $widget_content The content of the widget.
660 611 * @param Widget_Base $this The widget.
661 612 */
662 613 $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
663 - Utils::print_unescaped_internal_string( $widget_content );
614 +
615 + echo $widget_content; // XSS ok.
664 616 ?>
665 - <?php if ( $this->has_widget_inner_wrapper() ) : ?>
666 617 </div>
667 - <?php endif;
618 + <?php
668 619 }
669 620
670 621 protected function is_widget_first_render( $widget_name ) {
671 622 return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
@@ -696,16 +647,8 @@
696 647 public function render_plain_content() {
697 648 $this->render_content();
698 649 }
699 650
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 651 /**
709 652 * Before widget rendering.
710 653 *
711 654 * Used to add stuff before the widget `_wrapper` element.
@@ -787,10 +730,10 @@
787 730 *
788 731 * Script tags are allowed on frontend according to the WP theme securing policy.
789 732 *
790 733 * @param string $setting
791 - * @param null $repeater_name
792 - * @param null $index
734 + * @param null $repeater_name
735 + * @param null $index
793 736 */
794 737 final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
795 738 if ( $repeater_name ) {
796 739 $repeater = $this->get_settings_for_display( $repeater_name );
@@ -855,9 +798,9 @@
855 798 * @access protected
856 799 *
857 800 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
858 801 * @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`).
802 + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
860 803 *
861 804 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
862 805 */
863 806 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
@@ -1014,13 +957,27 @@
1014 957 return $this->get_name();
1015 958 }
1016 959
1017 960 /**
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.
961 + * Get Inline CSS dependencies.
962 + *
963 + * Retrieve a list of inline CSS dependencies that the element requires.
964 + *
965 + * @since 3.3.0
966 + * @access public
967 + *
968 + * @return array.
1022 969 */
970 + public function get_inline_css_depends() {
971 + return [];
972 + }
973 +
974 + /**
975 + * @param string $plugin_title Plugin's title
976 + * @param string $since Plugin version widget was deprecated
977 + * @param string $last Plugin version in which the widget will be removed
978 + * @param string $replacement Widget replacement
979 + */
1023 980 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1024 981 $this->start_controls_section(
1025 982 'Deprecated',
1026 983 [
@@ -1040,52 +997,167 @@
1040 997 ]
1041 998 );
1042 999
1043 1000 $this->end_controls_section();
1001 +
1044 1002 }
1045 1003
1004 + public function register_runtime_widget( $widget_name ) {
1005 + self::$registered_runtime_widgets[] = $widget_name;
1006 + }
1007 +
1008 + public function get_widget_css_config( $widget_name ) {
1009 + $direction = is_rtl() ? '-rtl' : '';
1010 +
1011 + $has_custom_breakpoints = $this->is_custom_breakpoints_widget();
1012 +
1013 + $file_name = 'widget-' . $widget_name . $direction . '.min.css';
1014 +
1015 + // The URL of the widget's external CSS file that is loaded in case that the CSS content is too large to be printed inline.
1016 + $file_url = Plugin::$instance->frontend->get_frontend_file_url( $file_name, $has_custom_breakpoints );
1017 +
1018 + // The local path of the widget's CSS file that is being read and saved in the DB when the CSS content should be printed inline.
1019 + $file_path = Plugin::$instance->frontend->get_frontend_file_path( $file_name, $has_custom_breakpoints );
1020 +
1021 + return [
1022 + 'key' => $widget_name,
1023 + 'version' => ELEMENTOR_VERSION,
1024 + 'file_path' => $file_path,
1025 + 'data' => [
1026 + 'file_url' => $file_url,
1027 + ],
1028 + ];
1029 + }
1030 +
1031 + public function get_css_config() {
1032 + return $this->get_widget_css_config( $this->get_group_name() );
1033 + }
1034 +
1035 + public function get_responsive_widgets_config() {
1036 + $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager();
1037 +
1038 + return [
1039 + 'key' => $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_DATABASE_KEY,
1040 + 'version' => ELEMENTOR_VERSION,
1041 + 'file_path' => ELEMENTOR_ASSETS_PATH . $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_FILE_PATH,
1042 + ];
1043 + }
1044 +
1045 + public function get_responsive_widgets() {
1046 + $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager();
1047 +
1048 + $config = $this->get_responsive_widgets_config();
1049 +
1050 + return $responsive_widgets_data_manager->get_asset_data_from_config( $config );
1051 + }
1052 +
1046 1053 /**
1047 - * Init controls.
1054 + * Get Responsive Widgets Data Manager.
1048 1055 *
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.
1056 + * Retrieve the data manager that handles widgets that are using media queries for custom-breakpoints values.
1051 1057 *
1052 - * @since 3.14.0
1058 + * @since 3.5.0
1053 1059 * @access protected
1060 + *
1061 + * @return Responsive_Widgets_Data_Manager
1054 1062 */
1055 - protected function init_controls() {
1056 - $this->is_first_section = true;
1057 - parent::init_controls();
1058 - }
1063 + protected function get_responsive_widgets_data_manager() {
1064 + if ( ! self::$responsive_widgets_data_manager ) {
1065 + self::$responsive_widgets_data_manager = new Responsive_Widgets_Data_Manager();
1066 + }
1059 1067
1060 - public function register_runtime_widget( $widget_name ) {
1061 - self::$registered_runtime_widgets[] = $widget_name;
1068 + return self::$responsive_widgets_data_manager;
1062 1069 }
1063 1070
1064 1071 /**
1065 - * Mark widget as deprecated.
1072 + * Is Custom Breakpoints Widget.
1066 1073 *
1067 - * Use `get_deprecation_message()` method to print the message control at specific location in register_controls().
1074 + * Checking if there are active custom-breakpoints and if the widget use them.
1068 1075 *
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.
1076 + * @since 3.5.0
1077 + * @access protected
1078 + *
1079 + * @return boolean
1072 1080 */
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 - ] );
1081 + protected function is_custom_breakpoints_widget() {
1082 + $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints();
1080 1083
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 - );
1084 + if ( $has_custom_breakpoints ) {
1085 + $responsive_widgets = $this->get_responsive_widgets();
1086 +
1087 + // The $widget_name can also represents a widgets group name, therefore we need to use the current widget name to check if it's responsive widget.
1088 + $current_widget_name = $this->get_name();
1089 +
1090 + // If the widget is not implementing custom-breakpoints media queries then it has no custom- css file.
1091 + if ( ! isset( $responsive_widgets[ $current_widget_name ] ) ) {
1092 + $has_custom_breakpoints = false;
1093 + }
1094 + }
1095 +
1096 + return $has_custom_breakpoints;
1097 + }
1098 +
1099 + private function get_widget_css() {
1100 + $widgets_css_data_manager = $this->get_widgets_css_data_manager();
1101 +
1102 + $widgets_list = $this->get_inline_css_depends();
1103 +
1104 + $widgets_list[] = $this->get_group_name();
1105 +
1106 + $widget_css = '';
1107 +
1108 + foreach ( $widgets_list as $widget_data ) {
1109 + $widget_name = isset( $widget_data['name'] ) ? $widget_data['name'] : $widget_data;
1110 +
1111 + if ( ! in_array( $widget_name, self::$registered_inline_css_widgets, true ) ) {
1112 + if ( $this->get_group_name() === $widget_name ) {
1113 + $config = $this->get_css_config();
1114 + } else {
1115 + /**
1116 + * The core-dependency allowing to create a dependency specifically with the core widgets.
1117 + * Otherwise, the config will be taken from the class that inherits from Widget_Base.
1118 + */
1119 + $is_core_dependency = isset( $widget_data['is_core_dependency'] ) ? true : false;
1120 +
1121 + $config = $is_core_dependency ? self::get_widget_css_config( $widget_name ) : $this->get_widget_css_config( $widget_name );
1122 + }
1123 +
1124 + $widget_css .= $widgets_css_data_manager->get_asset_data_from_config( $config );
1125 +
1126 + self::$registered_inline_css_widgets[] = $widget_name;
1127 + }
1128 + }
1129 +
1130 + return $widget_css;
1131 +
1132 + }
1133 +
1134 + private function is_inline_css_mode() {
1135 + static $is_active;
1136 +
1137 + if ( null === $is_active ) {
1138 + $is_edit_mode = Plugin::$instance->editor->is_edit_mode();
1139 + $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
1140 + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1141 +
1142 + $is_active = ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) ? false : true;
1143 + }
1144 +
1145 + return $is_active;
1146 + }
1147 +
1148 + private function print_widget_css() {
1149 + if ( ! $this->is_inline_css_mode() ) {
1150 + return;
1151 + }
1152 +
1153 + Utils::print_unescaped_internal_string( $this->get_widget_css() );
1154 + }
1155 +
1156 + private function get_widgets_css_data_manager() {
1157 + if ( ! self::$widgets_css_data_manager ) {
1158 + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager();
1159 + }
1160 +
1161 + return self::$widgets_css_data_manager;
1090 1162 }
1091 1163 }