PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.4
Elementor Website Builder – more than just a page builder v3.25.4
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 +216 -78 4.3.0-beta23.25.4 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Frontend\Widget_Content_Render_Mode;
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;
5 6 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
6 -use Elementor\Utils;
7 7
8 8 if ( ! defined( 'ABSPATH' ) ) {
9 9 exit; // Exit if accessed directly.
10 10 }
@@ -49,8 +49,14 @@
49 49 * @var array
50 50 */
51 51 public static $registered_runtime_widgets = [];
52 52
53 + public static $registered_inline_css_widgets = [];
54 +
55 + private static $widgets_css_data_manager;
56 +
57 + private static $responsive_widgets_data_manager;
58 +
53 59 /**
54 60 * Get element type.
55 61 *
56 62 * Retrieve the element type, in this case `widget`.
@@ -184,11 +190,11 @@
184 190 */
185 191 public function get_stack( $with_common_controls = true ) {
186 192 $stack = parent::get_stack();
187 193
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() );
194 + if ( $with_common_controls && 'common' !== $this->get_unique_name() ) {
195 + /** @var Widget_Common $common_widget */
196 + $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' );
191 197
192 198 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
193 199
194 200 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
@@ -196,16 +202,8 @@
196 202
197 203 return $stack;
198 204 }
199 205
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 206 /**
209 207 * Get widget controls pointer index.
210 208 *
211 209 * Retrieve widget pointer index where the next control should be added.
@@ -301,9 +299,9 @@
301 299 foreach ( $skins as $skin_id => $skin ) {
302 300 $skin_options[ $skin_id ] = $skin->get_title();
303 301 }
304 302
305 - // Get the first item for default value.
303 + // Get the first item for default value
306 304 $default_value = array_keys( $skin_options );
307 305 $default_value = array_shift( $default_value );
308 306
309 307 if ( 1 >= count( $skin_options ) ) {
@@ -380,11 +378,10 @@
380 378 'categories' => $this->get_categories(),
381 379 'html_wrapper_class' => $this->get_html_wrapper_class(),
382 380 'show_in_panel' => $this->show_in_panel(),
383 381 'hide_on_search' => $this->hide_on_search(),
384 - 'upsale_data' => null,
382 + 'upsale_data' => $this->get_upsale_data(),
385 383 'is_dynamic_content' => $this->is_dynamic_content(),
386 - 'has_widget_inner_wrapper' => $this->has_widget_inner_wrapper(),
387 384 ];
388 385
389 386 if ( isset( $config['upsale_data'] ) && is_array( $config['upsale_data'] ) ) {
390 387 $filter_name = 'elementor/widgets/' . $this->get_name() . '/custom_promotion';
@@ -424,15 +421,15 @@
424 421 *
425 422 * @param string $template_content Template content.
426 423 */
427 424 protected function print_template_content( $template_content ) {
428 - if ( $this->has_widget_inner_wrapper() ) : ?>
425 + ?>
429 426 <div class="elementor-widget-container">
430 - <?php endif;
431 - Utils::print_unescaped_internal_string( $template_content );
432 - if ( $this->has_widget_inner_wrapper() ) : ?>
427 + <?php
428 + echo $template_content; // XSS ok.
429 + ?>
433 430 </div>
434 - <?php endif;
431 + <?php
435 432 }
436 433
437 434 /**
438 435 * Parse text editor.
@@ -542,17 +539,18 @@
542 539 *
543 540 * Used to add Light-Box-related data attributes to links that open media files.
544 541 *
545 542 * @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.
543 + * @param int $id The ID of the image
544 + * @param string $lightbox_setting_key The setting key that dictates whether to open the image in a lightbox
545 + * @param string $group_id Unique ID for a group of lightbox images
546 + * @param bool $overwrite Optional. Whether to overwrite existing
547 + * attribute. Default is false, not to overwrite.
551 548 *
552 549 * @return Widget_Base Current instance of the widget.
553 550 * @since 2.9.0
554 551 * @access public
552 + *
555 553 */
556 554 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
557 555 $kit = Plugin::$instance->kits_manager->get_active_kit();
558 556
@@ -624,9 +622,9 @@
624 622 * @since 1.0.0
625 623 *
626 624 * @param Widget_Base $this The current widget.
627 625 */
628 - do_action( 'elementor/widget/before_render_content', $this, [ 'mode' => Widget_Content_Render_Mode::NORMAL ] );
626 + do_action( 'elementor/widget/before_render_content', $this );
629 627
630 628 ob_start();
631 629
632 630 $skin = $this->get_current_skin();
@@ -641,16 +639,19 @@
641 639
642 640 if ( empty( $widget_content ) ) {
643 641 return;
644 642 }
645 - if ( $this->has_widget_inner_wrapper() ) : ?>
643 + ?>
646 644 <div class="elementor-widget-container">
647 - <?php endif; ?>
648 645 <?php
649 646 if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
650 647 $this->register_runtime_widget( $this->get_group_name() );
651 648 }
652 649
650 + // $this->print_widget_css();
651 +
652 + // get_name
653 +
653 654 /**
654 655 * Render widget content.
655 656 *
656 657 * Filters the widget content before it's rendered.
@@ -659,14 +660,14 @@
659 660 *
660 661 * @param string $widget_content The content of the widget.
661 662 * @param Widget_Base $this The widget.
662 663 */
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 );
664 + $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
665 +
666 + echo $widget_content; // XSS ok.
665 667 ?>
666 - <?php if ( $this->has_widget_inner_wrapper() ) : ?>
667 668 </div>
668 - <?php endif;
669 + <?php
669 670 }
670 671
671 672 protected function is_widget_first_render( $widget_name ) {
672 673 return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
@@ -697,43 +698,8 @@
697 698 public function render_plain_content() {
698 699 $this->render_content();
699 700 }
700 701
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 702 /**
737 703 * Before widget rendering.
738 704 *
739 705 * Used to add stuff before the widget `_wrapper` element.
@@ -815,10 +781,10 @@
815 781 *
816 782 * Script tags are allowed on frontend according to the WP theme securing policy.
817 783 *
818 784 * @param string $setting
819 - * @param null $repeater_name
820 - * @param null $index
785 + * @param null $repeater_name
786 + * @param null $index
821 787 */
822 788 final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
823 789 if ( $repeater_name ) {
824 790 $repeater = $this->get_settings_for_display( $repeater_name );
@@ -883,9 +849,9 @@
883 849 * @access protected
884 850 *
885 851 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
886 852 * @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`).
853 + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
888 854 *
889 855 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
890 856 */
891 857 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
@@ -1042,13 +1008,27 @@
1042 1008 return $this->get_name();
1043 1009 }
1044 1010
1045 1011 /**
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.
1012 + * Get Inline CSS dependencies.
1013 + *
1014 + * Retrieve a list of inline CSS dependencies that the element requires.
1015 + *
1016 + * @since 3.3.0
1017 + * @access public
1018 + *
1019 + * @return array.
1050 1020 */
1021 + public function get_inline_css_depends() {
1022 + return [];
1023 + }
1024 +
1025 + /**
1026 + * @param string $plugin_title Plugin's title
1027 + * @param string $since Plugin version widget was deprecated
1028 + * @param string $last Plugin version in which the widget will be removed
1029 + * @param string $replacement Widget replacement
1030 + */
1051 1031 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1052 1032 $this->start_controls_section(
1053 1033 'Deprecated',
1054 1034 [
@@ -1088,16 +1068,63 @@
1088 1068 public function register_runtime_widget( $widget_name ) {
1089 1069 self::$registered_runtime_widgets[] = $widget_name;
1090 1070 }
1091 1071
1072 + public function get_widget_css_config( $widget_name ) {
1073 + $direction = is_rtl() ? '-rtl' : '';
1074 +
1075 + $has_custom_breakpoints = $this->is_custom_breakpoints_widget();
1076 +
1077 + $file_name = 'widget-' . $widget_name . $direction . '.min.css';
1078 +
1079 + // 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.
1080 + $file_url = Plugin::$instance->frontend->get_frontend_file_url( $file_name, $has_custom_breakpoints );
1081 +
1082 + // 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.
1083 + $file_path = Plugin::$instance->frontend->get_frontend_file_path( $file_name, $has_custom_breakpoints );
1084 +
1085 + $file_timestamp = file_exists( $file_path ) ? filemtime( $file_path ) : ELEMENTOR_VERSION;
1086 +
1087 + return [
1088 + 'key' => $widget_name,
1089 + 'version' => ELEMENTOR_VERSION,
1090 + 'file_path' => $file_path,
1091 + 'data' => [
1092 + 'file_url' => $file_url . '?ver=' . $file_timestamp,
1093 + ],
1094 + ];
1095 + }
1096 +
1097 + public function get_css_config() {
1098 + return $this->get_widget_css_config( $this->get_group_name() );
1099 + }
1100 +
1101 + public function get_responsive_widgets_config() {
1102 + $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager();
1103 +
1104 + return [
1105 + 'key' => $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_DATABASE_KEY,
1106 + 'version' => ELEMENTOR_VERSION,
1107 + 'file_path' => ELEMENTOR_ASSETS_PATH . $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_FILE_PATH,
1108 + ];
1109 + }
1110 +
1111 + public function get_responsive_widgets() {
1112 + $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager();
1113 +
1114 + $config = $this->get_responsive_widgets_config();
1115 +
1116 + return $responsive_widgets_data_manager->get_asset_data_from_config( $config );
1117 + }
1118 +
1092 1119 /**
1093 1120 * Mark widget as deprecated.
1094 1121 *
1095 1122 * Use `get_deprecation_message()` method to print the message control at specific location in register_controls().
1096 1123 *
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.
1124 + * @param $version string The version of Elementor that deprecated the widget.
1125 + * @param $message string A message regarding the deprecation.
1126 + * @param $replacement string The widget that should be used instead.
1100 1127 */
1101 1128 protected function add_deprecation_message( $version, $message, $replacement ) {
1102 1129 // Expose the config for handling in JS.
1103 1130 $this->set_config( 'deprecation', [
@@ -1114,6 +1141,117 @@
1114 1141 'content' => $message,
1115 1142 'separator' => 'after',
1116 1143 ]
1117 1144 );
1145 + }
1146 +
1147 + /**
1148 + * Get Responsive Widgets Data Manager.
1149 + *
1150 + * Retrieve the data manager that handles widgets that are using media queries for custom-breakpoints values.
1151 + *
1152 + * @since 3.5.0
1153 + * @access protected
1154 + *
1155 + * @return Responsive_Widgets_Data_Manager
1156 + */
1157 + protected function get_responsive_widgets_data_manager() {
1158 + if ( ! self::$responsive_widgets_data_manager ) {
1159 + self::$responsive_widgets_data_manager = new Responsive_Widgets_Data_Manager();
1160 + }
1161 +
1162 + return self::$responsive_widgets_data_manager;
1163 + }
1164 +
1165 + /**
1166 + * Is Custom Breakpoints Widget.
1167 + *
1168 + * Checking if there are active custom-breakpoints and if the widget use them.
1169 + *
1170 + * @since 3.5.0
1171 + * @access protected
1172 + *
1173 + * @return boolean
1174 + */
1175 + protected function is_custom_breakpoints_widget() {
1176 + $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints();
1177 +
1178 + if ( $has_custom_breakpoints ) {
1179 + $responsive_widgets = $this->get_responsive_widgets();
1180 +
1181 + // 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.
1182 + $current_widget_name = $this->get_name();
1183 +
1184 + // If the widget is not implementing custom-breakpoints media queries then it has no custom- css file.
1185 + if ( ! isset( $responsive_widgets[ $current_widget_name ] ) ) {
1186 + $has_custom_breakpoints = false;
1187 + }
1188 + }
1189 +
1190 + return $has_custom_breakpoints;
1191 + }
1192 +
1193 + private function get_widget_css() {
1194 + $widgets_css_data_manager = $this->get_widgets_css_data_manager();
1195 +
1196 + $widgets_list = $this->get_inline_css_depends();
1197 +
1198 + $widgets_list[] = $this->get_group_name();
1199 +
1200 + $widget_css = '';
1201 +
1202 + foreach ( $widgets_list as $widget_data ) {
1203 + $widget_name = isset( $widget_data['name'] ) ? $widget_data['name'] : $widget_data;
1204 +
1205 + if ( ! in_array( $widget_name, self::$registered_inline_css_widgets, true ) ) {
1206 + if ( $this->get_group_name() === $widget_name ) {
1207 + $config = $this->get_css_config();
1208 + } else {
1209 + /**
1210 + * The core-dependency allowing to create a dependency specifically with the core widgets.
1211 + * Otherwise, the config will be taken from the class that inherits from Widget_Base.
1212 + */
1213 + $is_core_dependency = isset( $widget_data['is_core_dependency'] ) ? true : false;
1214 +
1215 + $config = $is_core_dependency ? self::get_widget_css_config( $widget_name ) : $this->get_widget_css_config( $widget_name );
1216 + }
1217 +
1218 + $widget_css .= $widgets_css_data_manager->get_asset_data_from_config( $config );
1219 +
1220 + self::$registered_inline_css_widgets[] = $widget_name;
1221 + }
1222 + }
1223 +
1224 + return $widget_css;
1225 +
1226 + }
1227 +
1228 + private function is_inline_css_mode() {
1229 + static $is_active;
1230 +
1231 + if ( null === $is_active ) {
1232 + $is_edit_mode = Plugin::$instance->editor->is_edit_mode();
1233 + $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
1234 + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1235 +
1236 + $is_active = ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) ? false : true;
1237 + }
1238 +
1239 + return $is_active;
1240 + }
1241 +
1242 + private function print_widget_css() {
1243 + if ( ! $this->is_inline_css_mode() ) {
1244 + return;
1245 + }
1246 +
1247 + Utils::print_unescaped_internal_string( $this->get_widget_css() );
1248 + }
1249 +
1250 + private function get_widgets_css_data_manager() {
1251 + if ( ! self::$widgets_css_data_manager ) {
1252 + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager();
1253 + }
1254 +
1255 + return self::$widgets_css_data_manager;
1118 1256 }
1119 1257 }