PluginProbe
Elementor Website Builder – more than just a page builder / 3.9.0
Elementor Website Builder – more than just a page builder v3.9.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 +204 -135 4.3.0-beta23.9.0 View file →
@@ -1,10 +1,9 @@
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\Responsive_Widgets as Responsive_Widgets_Data_Manager;
5 +use Elementor\Core\Page_Assets\Data_Managers\Widgets_Css as Widgets_Css_Data_Manager;
7 6
8 7 if ( ! defined( 'ABSPATH' ) ) {
9 8 exit; // Exit if accessed directly.
10 9 }
@@ -49,8 +48,14 @@
49 48 * @var array
50 49 */
51 50 public static $registered_runtime_widgets = [];
52 51
52 + public static $registered_inline_css_widgets = [];
53 +
54 + private static $widgets_css_data_manager;
55 +
56 + private static $responsive_widgets_data_manager;
57 +
53 58 /**
54 59 * Get element type.
55 60 *
56 61 * Retrieve the element type, in this case `widget`.
@@ -107,22 +112,8 @@
107 112 return [ 'general' ];
108 113 }
109 114
110 115 /**
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 116 * Widget base constructor.
126 117 *
127 118 * Initializing the widget base class.
128 119 *
@@ -140,9 +131,9 @@
140 131
141 132 $is_type_instance = $this->is_type_instance();
142 133
143 134 if ( ! $is_type_instance && null === $args ) {
144 - throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' );
135 + throw new \Exception( '`$args` argument is required when initializing a full widget instance.' );
145 136 }
146 137
147 138 if ( $is_type_instance ) {
148 139 if ( $this->has_own_method( '_register_skins', self::class ) ) {
@@ -184,11 +175,11 @@
184 175 */
185 176 public function get_stack( $with_common_controls = true ) {
186 177 $stack = parent::get_stack();
187 178
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() );
179 + if ( $with_common_controls && 'common' !== $this->get_unique_name() ) {
180 + /** @var Widget_Common $common_widget */
181 + $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' );
191 182
192 183 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
193 184
194 185 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
@@ -196,16 +187,8 @@
196 187
197 188 return $stack;
198 189 }
199 190
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 191 /**
209 192 * Get widget controls pointer index.
210 193 *
211 194 * Retrieve widget pointer index where the next control should be added.
@@ -301,9 +284,9 @@
301 284 foreach ( $skins as $skin_id => $skin ) {
302 285 $skin_options[ $skin_id ] = $skin->get_title();
303 286 }
304 287
305 - // Get the first item for default value.
288 + // Get the first item for default value
306 289 $default_value = array_keys( $skin_options );
307 290 $default_value = array_shift( $default_value );
308 291
309 292 if ( 1 >= count( $skin_options ) ) {
@@ -333,12 +316,12 @@
333 316 * Register widget skins - deprecated prefixed method
334 317 *
335 318 * @since 1.7.12
336 319 * @access protected
337 - * @deprecated 3.1.0 Use `register_skins()` method instead.
320 + * @deprecated 3.1.0
338 321 */
339 322 protected function _register_skins() {
340 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' );
323 + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_skins()' );
341 324
342 325 $this->register_skins();
343 326 }
344 327
@@ -380,22 +363,10 @@
380 363 'categories' => $this->get_categories(),
381 364 'html_wrapper_class' => $this->get_html_wrapper_class(),
382 365 'show_in_panel' => $this->show_in_panel(),
383 366 '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 367 ];
388 368
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 369 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
399 370
400 371 if ( $stack ) {
401 372 $config['controls'] = $this->get_stack( false )['controls'];
@@ -424,15 +395,15 @@
424 395 *
425 396 * @param string $template_content Template content.
426 397 */
427 398 protected function print_template_content( $template_content ) {
428 - if ( $this->has_widget_inner_wrapper() ) : ?>
399 + ?>
429 400 <div class="elementor-widget-container">
430 - <?php endif;
431 - Utils::print_unescaped_internal_string( $template_content );
432 - if ( $this->has_widget_inner_wrapper() ) : ?>
401 + <?php
402 + echo $template_content; // XSS ok.
403 + ?>
433 404 </div>
434 - <?php endif;
405 + <?php
435 406 }
436 407
437 408 /**
438 409 * Parse text editor.
@@ -542,17 +513,18 @@
542 513 *
543 514 * Used to add Light-Box-related data attributes to links that open media files.
544 515 *
545 516 * @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.
517 + * @param int $id The ID of the image
518 + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox
519 + * @param string $group_id Unique ID for a group of lightbox images
520 + * @param bool $overwrite Optional. Whether to overwrite existing
521 + * attribute. Default is false, not to overwrite.
551 522 *
552 523 * @return Widget_Base Current instance of the widget.
553 524 * @since 2.9.0
554 525 * @access public
526 + *
555 527 */
556 528 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
557 529 $kit = Plugin::$instance->kits_manager->get_active_kit();
558 530
@@ -596,9 +568,9 @@
596 568 $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
597 569 }
598 570 }
599 571
600 - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
572 + $attributes['e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
601 573
602 574 $this->add_render_attribute( $element, $attributes, null, $overwrite );
603 575
604 576 return $this;
@@ -624,9 +596,9 @@
624 596 * @since 1.0.0
625 597 *
626 598 * @param Widget_Base $this The current widget.
627 599 */
628 - do_action( 'elementor/widget/before_render_content', $this, [ 'mode' => Widget_Content_Render_Mode::NORMAL ] );
600 + do_action( 'elementor/widget/before_render_content', $this );
629 601
630 602 ob_start();
631 603
632 604 $skin = $this->get_current_skin();
@@ -641,16 +613,19 @@
641 613
642 614 if ( empty( $widget_content ) ) {
643 615 return;
644 616 }
645 - if ( $this->has_widget_inner_wrapper() ) : ?>
617 + ?>
646 618 <div class="elementor-widget-container">
647 - <?php endif; ?>
648 619 <?php
649 620 if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
650 621 $this->register_runtime_widget( $this->get_group_name() );
651 622 }
652 623
624 + $this->print_widget_css();
625 +
626 + // get_name
627 +
653 628 /**
654 629 * Render widget content.
655 630 *
656 631 * Filters the widget content before it's rendered.
@@ -659,14 +634,14 @@
659 634 *
660 635 * @param string $widget_content The content of the widget.
661 636 * @param Widget_Base $this The widget.
662 637 */
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 );
638 + $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
639 +
640 + echo $widget_content; // XSS ok.
665 641 ?>
666 - <?php if ( $this->has_widget_inner_wrapper() ) : ?>
667 642 </div>
668 - <?php endif;
643 + <?php
669 644 }
670 645
671 646 protected function is_widget_first_render( $widget_name ) {
672 647 return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
@@ -697,43 +672,8 @@
697 672 public function render_plain_content() {
698 673 $this->render_content();
699 674 }
700 675
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 676 /**
737 677 * Before widget rendering.
738 678 *
739 679 * Used to add stuff before the widget `_wrapper` element.
@@ -815,10 +755,10 @@
815 755 *
816 756 * Script tags are allowed on frontend according to the WP theme securing policy.
817 757 *
818 758 * @param string $setting
819 - * @param null $repeater_name
820 - * @param null $index
759 + * @param null $repeater_name
760 + * @param null $index
821 761 */
822 762 final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
823 763 if ( $repeater_name ) {
824 764 $repeater = $this->get_settings_for_display( $repeater_name );
@@ -883,9 +823,9 @@
883 823 * @access protected
884 824 *
885 825 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
886 826 * @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`).
827 + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
888 828 *
889 829 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
890 830 */
891 831 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
@@ -1042,13 +982,27 @@
1042 982 return $this->get_name();
1043 983 }
1044 984
1045 985 /**
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.
986 + * Get Inline CSS dependencies.
987 + *
988 + * Retrieve a list of inline CSS dependencies that the element requires.
989 + *
990 + * @since 3.3.0
991 + * @access public
992 + *
993 + * @return array.
1050 994 */
995 + public function get_inline_css_depends() {
996 + return [];
997 + }
998 +
999 + /**
1000 + * @param string $plugin_title Plugin's title
1001 + * @param string $since Plugin version widget was deprecated
1002 + * @param string $last Plugin version in which the widget will be removed
1003 + * @param string $replacement Widget replacement
1004 + */
1051 1005 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1052 1006 $this->start_controls_section(
1053 1007 'Deprecated',
1054 1008 [
@@ -1068,52 +1022,167 @@
1068 1022 ]
1069 1023 );
1070 1024
1071 1025 $this->end_controls_section();
1026 +
1072 1027 }
1073 1028
1029 + public function register_runtime_widget( $widget_name ) {
1030 + self::$registered_runtime_widgets[] = $widget_name;
1031 + }
1032 +
1033 + public function get_widget_css_config( $widget_name ) {
1034 + $direction = is_rtl() ? '-rtl' : '';
1035 +
1036 + $has_custom_breakpoints = $this->is_custom_breakpoints_widget();
1037 +
1038 + $file_name = 'widget-' . $widget_name . $direction . '.min.css';
1039 +
1040 + // 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.
1041 + $file_url = Plugin::$instance->frontend->get_frontend_file_url( $file_name, $has_custom_breakpoints );
1042 +
1043 + // 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.
1044 + $file_path = Plugin::$instance->frontend->get_frontend_file_path( $file_name, $has_custom_breakpoints );
1045 +
1046 + return [
1047 + 'key' => $widget_name,
1048 + 'version' => ELEMENTOR_VERSION,
1049 + 'file_path' => $file_path,
1050 + 'data' => [
1051 + 'file_url' => $file_url,
1052 + ],
1053 + ];
1054 + }
1055 +
1056 + public function get_css_config() {
1057 + return $this->get_widget_css_config( $this->get_group_name() );
1058 + }
1059 +
1060 + public function get_responsive_widgets_config() {
1061 + $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager();
1062 +
1063 + return [
1064 + 'key' => $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_DATABASE_KEY,
1065 + 'version' => ELEMENTOR_VERSION,
1066 + 'file_path' => ELEMENTOR_ASSETS_PATH . $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_FILE_PATH,
1067 + ];
1068 + }
1069 +
1070 + public function get_responsive_widgets() {
1071 + $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager();
1072 +
1073 + $config = $this->get_responsive_widgets_config();
1074 +
1075 + return $responsive_widgets_data_manager->get_asset_data_from_config( $config );
1076 + }
1077 +
1074 1078 /**
1075 - * Init controls.
1079 + * Get Responsive Widgets Data Manager.
1076 1080 *
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.
1081 + * Retrieve the data manager that handles widgets that are using media queries for custom-breakpoints values.
1079 1082 *
1080 - * @since 3.14.0
1083 + * @since 3.5.0
1081 1084 * @access protected
1085 + *
1086 + * @return Responsive_Widgets_Data_Manager
1082 1087 */
1083 - protected function init_controls() {
1084 - $this->is_first_section = true;
1085 - parent::init_controls();
1086 - }
1088 + protected function get_responsive_widgets_data_manager() {
1089 + if ( ! self::$responsive_widgets_data_manager ) {
1090 + self::$responsive_widgets_data_manager = new Responsive_Widgets_Data_Manager();
1091 + }
1087 1092
1088 - public function register_runtime_widget( $widget_name ) {
1089 - self::$registered_runtime_widgets[] = $widget_name;
1093 + return self::$responsive_widgets_data_manager;
1090 1094 }
1091 1095
1092 1096 /**
1093 - * Mark widget as deprecated.
1097 + * Is Custom Breakpoints Widget.
1094 1098 *
1095 - * Use `get_deprecation_message()` method to print the message control at specific location in register_controls().
1099 + * Checking if there are active custom-breakpoints and if the widget use them.
1096 1100 *
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.
1101 + * @since 3.5.0
1102 + * @access protected
1103 + *
1104 + * @return boolean
1100 1105 */
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 - ] );
1106 + protected function is_custom_breakpoints_widget() {
1107 + $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints();
1108 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 - );
1109 + if ( $has_custom_breakpoints ) {
1110 + $responsive_widgets = $this->get_responsive_widgets();
1111 +
1112 + // 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.
1113 + $current_widget_name = $this->get_name();
1114 +
1115 + // If the widget is not implementing custom-breakpoints media queries then it has no custom- css file.
1116 + if ( ! isset( $responsive_widgets[ $current_widget_name ] ) ) {
1117 + $has_custom_breakpoints = false;
1118 + }
1119 + }
1120 +
1121 + return $has_custom_breakpoints;
1122 + }
1123 +
1124 + private function get_widget_css() {
1125 + $widgets_css_data_manager = $this->get_widgets_css_data_manager();
1126 +
1127 + $widgets_list = $this->get_inline_css_depends();
1128 +
1129 + $widgets_list[] = $this->get_group_name();
1130 +
1131 + $widget_css = '';
1132 +
1133 + foreach ( $widgets_list as $widget_data ) {
1134 + $widget_name = isset( $widget_data['name'] ) ? $widget_data['name'] : $widget_data;
1135 +
1136 + if ( ! in_array( $widget_name, self::$registered_inline_css_widgets, true ) ) {
1137 + if ( $this->get_group_name() === $widget_name ) {
1138 + $config = $this->get_css_config();
1139 + } else {
1140 + /**
1141 + * The core-dependency allowing to create a dependency specifically with the core widgets.
1142 + * Otherwise, the config will be taken from the class that inherits from Widget_Base.
1143 + */
1144 + $is_core_dependency = isset( $widget_data['is_core_dependency'] ) ? true : false;
1145 +
1146 + $config = $is_core_dependency ? self::get_widget_css_config( $widget_name ) : $this->get_widget_css_config( $widget_name );
1147 + }
1148 +
1149 + $widget_css .= $widgets_css_data_manager->get_asset_data_from_config( $config );
1150 +
1151 + self::$registered_inline_css_widgets[] = $widget_name;
1152 + }
1153 + }
1154 +
1155 + return $widget_css;
1156 +
1157 + }
1158 +
1159 + private function is_inline_css_mode() {
1160 + static $is_active;
1161 +
1162 + if ( null === $is_active ) {
1163 + $is_edit_mode = Plugin::$instance->editor->is_edit_mode();
1164 + $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
1165 + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1166 +
1167 + $is_active = ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) ? false : true;
1168 + }
1169 +
1170 + return $is_active;
1171 + }
1172 +
1173 + private function print_widget_css() {
1174 + if ( ! $this->is_inline_css_mode() ) {
1175 + return;
1176 + }
1177 +
1178 + Utils::print_unescaped_internal_string( $this->get_widget_css() );
1179 + }
1180 +
1181 + private function get_widgets_css_data_manager() {
1182 + if ( ! self::$widgets_css_data_manager ) {
1183 + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager();
1184 + }
1185 +
1186 + return self::$widgets_css_data_manager;
1118 1187 }
1119 1188 }