PluginProbe
Elementor Website Builder – more than just a page builder / 3.27.3
Elementor Website Builder – more than just a page builder v3.27.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
elementor / includes / base / widget-base.php

widget-base.php in Elementor Website Builder – more than just a page builder 3.27.3, at includes/base/widget-base.php

1,085 lines 28.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor widget base.
12 *
13 * An abstract class to register new Elementor widgets. It extended the
14 * `Element_Base` class to inherit its properties.
15 *
16 * This abstract class must be extended in order to register new widgets.
17 *
18 * @since 1.0.0
19 * @abstract
20 */
21 abstract class Widget_Base extends Element_Base {
22 /**
23 * Whether the widget has content.
24 *
25 * Used in cases where the widget has no content. When widgets uses only
26 * skins to display dynamic content generated on the server. For example the
27 * posts widget in Elementor Pro. Default is true, the widget has content
28 * template.
29 *
30 * @access protected
31 *
32 * @var bool
33 */
34 protected $_has_template_content = true;
35
36 private $is_first_section = true;
37
38 /**
39 * Registered Runtime Widgets.
40 *
41 * Registering in runtime all widgets that are being used on the page.
42 *
43 * @since 3.3.0
44 * @access public
45 * @static
46 *
47 * @var array
48 */
49 public static $registered_runtime_widgets = [];
50
51 /**
52 * Get element type.
53 *
54 * Retrieve the element type, in this case `widget`.
55 *
56 * @since 1.0.0
57 * @access public
58 * @static
59 *
60 * @return string The type.
61 */
62 public static function get_type() {
63 return 'widget';
64 }
65
66 /**
67 * Get widget icon.
68 *
69 * Retrieve the widget icon.
70 *
71 * @since 1.0.0
72 * @access public
73 *
74 * @return string Widget icon.
75 */
76 public function get_icon() {
77 return 'eicon-apps';
78 }
79
80 /**
81 * Get widget keywords.
82 *
83 * Retrieve the widget keywords.
84 *
85 * @since 1.0.10
86 * @access public
87 *
88 * @return array Widget keywords.
89 */
90 public function get_keywords() {
91 return [];
92 }
93
94 /**
95 * Get widget categories.
96 *
97 * Retrieve the widget categories.
98 *
99 * @since 1.0.10
100 * @access public
101 *
102 * @return array Widget categories.
103 */
104 public function get_categories() {
105 return [ 'general' ];
106 }
107
108 /**
109 * Get widget upsale data.
110 *
111 * Retrieve the widget promotion data.
112 *
113 * @since 3.18.0
114 * @access protected
115 *
116 * @return array|null Widget promotion data.
117 */
118 protected function get_upsale_data() {
119 return null;
120 }
121
122 /**
123 * Widget base constructor.
124 *
125 * Initializing the widget base class.
126 *
127 * @since 1.0.0
128 * @access public
129 *
130 * @throws \Exception If arguments are missing when initializing a full widget
131 * instance.
132 *
133 * @param array $data Widget data. Default is an empty array.
134 * @param array|null $args Optional. Widget default arguments. Default is null.
135 */
136 public function __construct( $data = [], $args = null ) {
137 parent::__construct( $data, $args );
138
139 $is_type_instance = $this->is_type_instance();
140
141 if ( ! $is_type_instance && null === $args ) {
142 throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' );
143 }
144
145 if ( $is_type_instance ) {
146 if ( $this->has_own_method( '_register_skins', self::class ) ) {
147 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_register_skins', '3.1.0', __CLASS__ . '::register_skins()' );
148
149 $this->_register_skins();
150 } else {
151 $this->register_skins();
152 }
153
154 $widget_name = $this->get_name();
155
156 /**
157 * Widget skin init.
158 *
159 * Fires when Elementor widget is being initialized.
160 *
161 * The dynamic portion of the hook name, `$widget_name`, refers to the widget name.
162 *
163 * @since 1.0.0
164 *
165 * @param Widget_Base $this The current widget.
166 */
167 do_action( "elementor/widget/{$widget_name}/skins_init", $this );
168 }
169 }
170
171 /**
172 * Get stack.
173 *
174 * Retrieve the widget stack of controls.
175 *
176 * @since 1.9.2
177 * @access public
178 *
179 * @param bool $with_common_controls Optional. Whether to include the common controls. Default is true.
180 *
181 * @return array Widget stack of controls.
182 */
183 public function get_stack( $with_common_controls = true ) {
184 $stack = parent::get_stack();
185
186 if ( $with_common_controls && ! $this instanceof Widget_Common_Base ) {
187 /** @var Widget_Common_Base $common_widget */
188 $common_widget = Plugin::$instance->widgets_manager->get_widget_types( $this->get_common_widget_name() );
189
190 $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
191
192 $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
193 }
194
195 return $stack;
196 }
197
198 private function get_common_widget_name() {
199 if ( Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ) ) {
200 return $this->has_widget_inner_wrapper() ? 'common' : 'common-optimized';
201 }
202
203 return 'common';
204 }
205
206 /**
207 * Get widget controls pointer index.
208 *
209 * Retrieve widget pointer index where the next control should be added.
210 *
211 * While using injection point, it will return the injection point index. Otherwise index of the last control of the
212 * current widget itself without the common controls, plus one.
213 *
214 * @since 1.9.2
215 * @access public
216 *
217 * @return int Widget controls pointer index.
218 */
219 public function get_pointer_index() {
220 $injection_point = $this->get_injection_point();
221
222 if ( null !== $injection_point ) {
223 return $injection_point['index'];
224 }
225
226 return count( $this->get_stack( false )['controls'] );
227 }
228
229 /**
230 * Show in panel.
231 *
232 * Whether to show the widget in the panel or not. By default returns true.
233 *
234 * @since 1.0.0
235 * @access public
236 *
237 * @return bool Whether to show the widget in the panel or not.
238 */
239 public function show_in_panel() {
240 return true;
241 }
242
243 /**
244 * Hide on search.
245 *
246 * Whether to hide the widget on search in the panel or not. By default returns false.
247 *
248 * @access public
249 *
250 * @return bool Whether to hide the widget when searching for widget or not.
251 */
252 public function hide_on_search() {
253 return false;
254 }
255
256 /**
257 * Start widget controls section.
258 *
259 * Used to add a new section of controls to the widget. Regular controls and
260 * skin controls.
261 *
262 * Note that when you add new controls to widgets they must be wrapped by
263 * `start_controls_section()` and `end_controls_section()`.
264 *
265 * @since 1.0.0
266 * @access public
267 *
268 * @param string $section_id Section ID.
269 * @param array $args Section arguments Optional.
270 */
271 public function start_controls_section( $section_id, array $args = [] ) {
272 parent::start_controls_section( $section_id, $args );
273
274 if ( $this->is_first_section ) {
275 $this->register_skin_control();
276
277 $this->is_first_section = false;
278 }
279 }
280
281 /**
282 * Register the Skin Control if the widget has skins.
283 *
284 * An internal method that is used to add a skin control to the widget.
285 * Added at the top of the controls section.
286 *
287 * @since 2.0.0
288 * @access private
289 */
290 private function register_skin_control() {
291 $skins = $this->get_skins();
292 if ( ! empty( $skins ) ) {
293 $skin_options = [];
294
295 if ( $this->_has_template_content ) {
296 $skin_options[''] = esc_html__( 'Default', 'elementor' );
297 }
298
299 foreach ( $skins as $skin_id => $skin ) {
300 $skin_options[ $skin_id ] = $skin->get_title();
301 }
302
303 // Get the first item for default value
304 $default_value = array_keys( $skin_options );
305 $default_value = array_shift( $default_value );
306
307 if ( 1 >= count( $skin_options ) ) {
308 $this->add_control(
309 '_skin',
310 [
311 'label' => esc_html__( 'Skin', 'elementor' ),
312 'type' => Controls_Manager::HIDDEN,
313 'default' => $default_value,
314 ]
315 );
316 } else {
317 $this->add_control(
318 '_skin',
319 [
320 'label' => esc_html__( 'Skin', 'elementor' ),
321 'type' => Controls_Manager::SELECT,
322 'default' => $default_value,
323 'options' => $skin_options,
324 ]
325 );
326 }
327 }
328 }
329
330 /**
331 * Register widget skins - deprecated prefixed method
332 *
333 * @since 1.7.12
334 * @access protected
335 * @deprecated 3.1.0 Use `register_skins()` method instead.
336 */
337 protected function _register_skins() {
338 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' );
339
340 $this->register_skins();
341 }
342
343 /**
344 * Register widget skins.
345 *
346 * This method is activated while initializing the widget base class. It is
347 * used to assign skins to widgets with `add_skin()` method.
348 *
349 * Usage:
350 *
351 * protected function register_skins() {
352 * $this->add_skin( new Skin_Classic( $this ) );
353 * }
354 *
355 * @since 3.1.0
356 * @access protected
357 */
358 protected function register_skins() {}
359
360 /**
361 * Get initial config.
362 *
363 * Retrieve the current widget initial configuration.
364 *
365 * Adds more configuration on top of the controls list, the tabs assigned to
366 * the control, element name, type, icon and more. This method also adds
367 * widget type, keywords and categories.
368 *
369 * @since 2.9.0
370 * @access protected
371 *
372 * @return array The initial widget config.
373 */
374 protected function get_initial_config() {
375 $config = [
376 'widget_type' => $this->get_name(),
377 'keywords' => $this->get_keywords(),
378 'categories' => $this->get_categories(),
379 'html_wrapper_class' => $this->get_html_wrapper_class(),
380 'show_in_panel' => $this->show_in_panel(),
381 'hide_on_search' => $this->hide_on_search(),
382 'upsale_data' => $this->get_upsale_data(),
383 'is_dynamic_content' => $this->is_dynamic_content(),
384 'has_widget_inner_wrapper' => $this->has_widget_inner_wrapper(),
385 ];
386
387 if ( isset( $config['upsale_data'] ) && is_array( $config['upsale_data'] ) ) {
388 $filter_name = 'elementor/widgets/' . $this->get_name() . '/custom_promotion';
389 $config['upsale_data'] = Filtered_Promotions_Manager::get_filtered_promotion_data( $config['upsale_data'], $filter_name, 'upgrade_url' );
390 }
391
392 if ( isset( $config['upsale_data']['image'] ) ) {
393 $config['upsale_data']['image'] = esc_url( $config['upsale_data']['image'] );
394 }
395
396 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
397
398 if ( $stack ) {
399 $config['controls'] = $this->get_stack( false )['controls'];
400 $config['tabs_controls'] = $this->get_tabs_controls();
401 }
402
403 return array_replace_recursive( parent::get_initial_config(), $config );
404 }
405
406 /**
407 * @since 2.3.1
408 * @access protected
409 */
410 protected function should_print_empty() {
411 return false;
412 }
413
414 /**
415 * Print widget content template.
416 *
417 * Used to generate the widget content template on the editor, using a
418 * Backbone JavaScript template.
419 *
420 * @since 2.0.0
421 * @access protected
422 *
423 * @param string $template_content Template content.
424 */
425 protected function print_template_content( $template_content ) {
426 if ( $this->has_widget_inner_wrapper() ) : ?>
427 <div class="elementor-widget-container">
428 <?php endif;
429 echo $template_content; // XSS ok.
430 if ( $this->has_widget_inner_wrapper() ) : ?>
431 </div>
432 <?php endif;
433 }
434
435 /**
436 * Parse text editor.
437 *
438 * Parses the content from rich text editor with shortcodes, oEmbed and
439 * filtered data.
440 *
441 * @since 1.0.0
442 * @access protected
443 *
444 * @param string $content Text editor content.
445 *
446 * @return string Parsed content.
447 */
448 protected function parse_text_editor( $content ) {
449 /** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
450 $content = apply_filters( 'widget_text', $content, $this->get_settings() );
451
452 $content = shortcode_unautop( $content );
453 $content = do_shortcode( $content );
454 $content = wptexturize( $content );
455
456 if ( $GLOBALS['wp_embed'] instanceof \WP_Embed ) {
457 $content = $GLOBALS['wp_embed']->autoembed( $content );
458 }
459
460 return $content;
461 }
462
463 /**
464 * Safe print parsed text editor.
465 *
466 * @uses static::parse_text_editor.
467 *
468 * @access protected
469 *
470 * @param string $content Text editor content.
471 */
472 final protected function print_text_editor( $content ) {
473 // PHPCS - the method `parse_text_editor` is safe.
474 echo static::parse_text_editor( $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
475 }
476
477 /**
478 * Get HTML wrapper class.
479 *
480 * Retrieve the widget container class. Can be used to override the
481 * container class for specific widgets.
482 *
483 * @since 2.0.9
484 * @access protected
485 */
486 protected function get_html_wrapper_class() {
487 return 'elementor-widget-' . $this->get_name();
488 }
489
490 /**
491 * Add widget render attributes.
492 *
493 * Used to add attributes to the current widget wrapper HTML tag.
494 *
495 * @since 1.0.0
496 * @access protected
497 */
498 protected function add_render_attributes() {
499 parent::add_render_attributes();
500
501 $this->add_render_attribute(
502 '_wrapper', 'class', [
503 'elementor-widget',
504 $this->get_html_wrapper_class(),
505 ]
506 );
507
508 $settings = $this->get_settings();
509
510 $this->add_render_attribute( '_wrapper', 'data-widget_type', $this->get_name() . '.' . ( ! empty( $settings['_skin'] ) ? $settings['_skin'] : 'default' ) );
511 }
512
513 /**
514 * Add lightbox data to image link.
515 *
516 * Used to add lightbox data attributes to image link HTML.
517 *
518 * @since 2.9.1
519 * @access public
520 *
521 * @param string $link_html Image link HTML.
522 * @param string $id Attachment id.
523 *
524 * @return string Image link HTML with lightbox data attributes.
525 */
526 public function add_lightbox_data_to_image_link( $link_html, $id ) {
527 $settings = $this->get_settings_for_display();
528 $open_lightbox = isset( $settings['open_lightbox'] ) ? $settings['open_lightbox'] : null;
529
530 if ( Plugin::$instance->editor->is_edit_mode() ) {
531 $this->add_render_attribute( 'link', 'class', 'elementor-clickable', true );
532 }
533
534 $this->add_lightbox_data_attributes( 'link', $id, $open_lightbox, $this->get_id(), true );
535 return preg_replace( '/^<a/', '<a ' . $this->get_render_attribute_string( 'link' ), $link_html );
536 }
537
538 /**
539 * Add Light-Box attributes.
540 *
541 * Used to add Light-Box-related data attributes to links that open media files.
542 *
543 * @param array|string $element The link HTML element.
544 * @param int $id The ID of the image
545 * @param string $lightbox_setting_key The setting key that dictates whether to open the image in a lightbox
546 * @param string $group_id Unique ID for a group of lightbox images
547 * @param bool $overwrite Optional. Whether to overwrite existing
548 * attribute. Default is false, not to overwrite.
549 *
550 * @return Widget_Base Current instance of the widget.
551 * @since 2.9.0
552 * @access public
553 *
554 */
555 public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
556 $kit = Plugin::$instance->kits_manager->get_active_kit();
557
558 $is_global_image_lightbox_enabled = 'yes' === $kit->get_settings( 'global_image_lightbox' );
559
560 if ( 'no' === $lightbox_setting_key ) {
561 if ( $is_global_image_lightbox_enabled ) {
562 $this->add_render_attribute( $element, 'data-elementor-open-lightbox', 'no', $overwrite );
563 }
564
565 return $this;
566 }
567
568 if ( 'yes' !== $lightbox_setting_key && ! $is_global_image_lightbox_enabled ) {
569 return $this;
570 }
571
572 $attributes['data-elementor-open-lightbox'] = 'yes';
573
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 if ( $group_id ) {
582 $attributes['data-elementor-lightbox-slideshow'] = $group_id;
583
584 $action_hash_params['slideshow'] = $group_id;
585 }
586
587 if ( $id ) {
588 $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id );
589
590 if ( isset( $lightbox_image_attributes['title'] ) ) {
591 $attributes['data-elementor-lightbox-title'] = $lightbox_image_attributes['title'];
592 }
593
594 if ( isset( $lightbox_image_attributes['description'] ) ) {
595 $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
596 }
597 }
598
599 $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params );
600
601 $this->add_render_attribute( $element, $attributes, null, $overwrite );
602
603 return $this;
604 }
605
606 /**
607 * Render widget output on the frontend.
608 *
609 * Used to generate the final HTML displayed on the frontend.
610 *
611 * Note that if skin is selected, it will be rendered by the skin itself,
612 * not the widget.
613 *
614 * @since 1.0.0
615 * @access public
616 */
617 public function render_content() {
618 /**
619 * Before widget render content.
620 *
621 * Fires before Elementor widget is being rendered.
622 *
623 * @since 1.0.0
624 *
625 * @param Widget_Base $this The current widget.
626 */
627 do_action( 'elementor/widget/before_render_content', $this );
628
629 ob_start();
630
631 $skin = $this->get_current_skin();
632 if ( $skin ) {
633 $skin->set_parent( $this );
634 $skin->render_by_mode();
635 } else {
636 $this->render_by_mode();
637 }
638
639 $widget_content = ob_get_clean();
640
641 if ( empty( $widget_content ) ) {
642 return;
643 }
644 if ( $this->has_widget_inner_wrapper() ) : ?>
645 <div class="elementor-widget-container">
646 <?php endif; ?>
647 <?php
648 if ( $this->is_widget_first_render( $this->get_group_name() ) ) {
649 $this->register_runtime_widget( $this->get_group_name() );
650 }
651
652 /**
653 * Render widget content.
654 *
655 * Filters the widget content before it's rendered.
656 *
657 * @since 1.0.0
658 *
659 * @param string $widget_content The content of the widget.
660 * @param Widget_Base $this The widget.
661 */
662 $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
663
664 echo $widget_content; // XSS ok.
665 ?>
666 <?php if ( $this->has_widget_inner_wrapper() ) : ?>
667 </div>
668 <?php endif;
669 }
670
671 protected function is_widget_first_render( $widget_name ) {
672 return ! in_array( $widget_name, self::$registered_runtime_widgets, true );
673 }
674
675 /**
676 * Render widget plain content.
677 *
678 * Elementor saves the page content in a unique way, but it's not the way
679 * WordPress saves data. This method is used to save generated HTML to the
680 * database as plain content the WordPress way.
681 *
682 * When rendering plain content, it allows other WordPress plugins to
683 * interact with the content - to search, check SEO and other purposes. It
684 * also allows the site to keep working even if Elementor is deactivated.
685 *
686 * Note that if the widget uses shortcodes to display the data, the best
687 * practice is to return the shortcode itself.
688 *
689 * Also note that if the widget don't display any content it should return
690 * an empty string. For example Elementor Pro Form Widget uses this method
691 * to return an empty string because there is no content to return. This way
692 * if Elementor Pro will be deactivated there won't be any form to display.
693 *
694 * @since 1.0.0
695 * @access public
696 */
697 public function render_plain_content() {
698 $this->render_content();
699 }
700
701 /**
702 * Before widget rendering.
703 *
704 * Used to add stuff before the widget `_wrapper` element.
705 *
706 * @since 1.0.0
707 * @access public
708 */
709 public function before_render() {
710 ?>
711 <div <?php $this->print_render_attribute_string( '_wrapper' ); ?>>
712 <?php
713 }
714
715 /**
716 * After widget rendering.
717 *
718 * Used to add stuff after the widget `_wrapper` element.
719 *
720 * @since 1.0.0
721 * @access public
722 */
723 public function after_render() {
724 ?>
725 </div>
726 <?php
727 }
728
729 /**
730 * Get the element raw data.
731 *
732 * Retrieve the raw element data, including the id, type, settings, child
733 * elements and whether it is an inner element.
734 *
735 * The data with the HTML used always to display the data, but the Elementor
736 * editor uses the raw data without the HTML in order not to render the data
737 * again.
738 *
739 * @since 1.0.0
740 * @access public
741 *
742 * @param bool $with_html_content Optional. Whether to return the data with
743 * HTML content or without. Used for caching.
744 * Default is false, without HTML.
745 *
746 * @return array Element raw data.
747 */
748 public function get_raw_data( $with_html_content = false ) {
749 $data = parent::get_raw_data( $with_html_content );
750
751 unset( $data['isInner'] );
752
753 $data['widgetType'] = $this->get_data( 'widgetType' );
754
755 if ( $with_html_content ) {
756 ob_start();
757
758 $this->render_content();
759
760 $data['htmlCache'] = ob_get_clean();
761 }
762
763 return $data;
764 }
765
766 /**
767 * Print widget content.
768 *
769 * Output the widget final HTML on the frontend.
770 *
771 * @since 1.0.0
772 * @access protected
773 */
774 protected function print_content() {
775 $this->render_content();
776 }
777
778 /**
779 * Print a setting content without escaping.
780 *
781 * Script tags are allowed on frontend according to the WP theme securing policy.
782 *
783 * @param string $setting
784 * @param null $repeater_name
785 * @param null $index
786 */
787 final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) {
788 if ( $repeater_name ) {
789 $repeater = $this->get_settings_for_display( $repeater_name );
790 $output = $repeater[ $index ][ $setting ];
791 } else {
792 $output = $this->get_settings_for_display( $setting );
793 }
794
795 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
796 }
797
798 /**
799 * Get default data.
800 *
801 * Retrieve the default widget data. Used to reset the data on initialization.
802 *
803 * @since 1.0.0
804 * @access protected
805 *
806 * @return array Default data.
807 */
808 protected function get_default_data() {
809 $data = parent::get_default_data();
810
811 $data['widgetType'] = '';
812
813 return $data;
814 }
815
816 /**
817 * Get default child type.
818 *
819 * Retrieve the widget child type based on element data.
820 *
821 * @since 1.0.0
822 * @access protected
823 *
824 * @param array $element_data Widget ID.
825 *
826 * @return array|false Child type or false if it's not a valid widget.
827 */
828 protected function _get_default_child_type( array $element_data ) {
829 return Plugin::$instance->elements_manager->get_element_types( 'section' );
830 }
831
832 /**
833 * Get repeater setting key.
834 *
835 * Retrieve the unique setting key for the current repeater item. Used to connect the current element in the
836 * repeater to it's settings model and it's control in the panel.
837 *
838 * PHP usage (inside `Widget_Base::render()` method):
839 *
840 * $tabs = $this->get_settings( 'tabs' );
841 * foreach ( $tabs as $index => $item ) {
842 * $tab_title_setting_key = $this->get_repeater_setting_key( 'tab_title', 'tabs', $index );
843 * $this->add_inline_editing_attributes( $tab_title_setting_key, 'none' );
844 * echo '<div ' . $this->get_render_attribute_string( $tab_title_setting_key ) . '>' . $item['tab_title'] . '</div>';
845 * }
846 *
847 * @since 1.8.0
848 * @access protected
849 *
850 * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
851 * @param string $repeater_key The repeater key containing the array of all the items in the repeater (e.g. `tabs`).
852 * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
853 *
854 * @return string The repeater setting key (e.g. `tabs.3.tab_title`).
855 */
856 protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
857 return implode( '.', [ $repeater_key, $repeater_item_index, $setting_key ] );
858 }
859
860 /**
861 * Add inline editing attributes.
862 *
863 * Define specific area in the element to be editable inline. The element can have several areas, with this method
864 * you can set the area inside the element that can be edited inline. You can also define the type of toolbar the
865 * user will see, whether it will be a basic toolbar or an advanced one.
866 *
867 * Note: When you use wysiwyg control use the advanced toolbar, with textarea control use the basic toolbar. Text
868 * control should not have toolbar.
869 *
870 * PHP usage (inside `Widget_Base::render()` method):
871 *
872 * $this->add_inline_editing_attributes( 'text', 'advanced' );
873 * echo '<div ' . $this->get_render_attribute_string( 'text' ) . '>' . $this->get_settings( 'text' ) . '</div>';
874 *
875 * @since 1.8.0
876 * @access protected
877 *
878 * @param string $key Element key.
879 * @param string $toolbar Optional. Toolbar type. Accepted values are `advanced`, `basic` or `none`. Default is
880 * `basic`.
881 */
882 protected function add_inline_editing_attributes( $key, $toolbar = 'basic' ) {
883 if ( ! Plugin::$instance->editor->is_edit_mode() ) {
884 return;
885 }
886
887 $this->add_render_attribute( $key, [
888 'class' => 'elementor-inline-editing',
889 'data-elementor-setting-key' => $key,
890 ] );
891
892 if ( 'basic' !== $toolbar ) {
893 $this->add_render_attribute( $key, [
894 'data-elementor-inline-editing-toolbar' => $toolbar,
895 ] );
896 }
897 }
898
899 /**
900 * Add new skin.
901 *
902 * Register new widget skin to allow the user to set custom designs. Must be
903 * called inside the `register_skins()` method.
904 *
905 * @since 1.0.0
906 * @access public
907 *
908 * @param Skin_Base $skin Skin instance.
909 */
910 public function add_skin( Skin_Base $skin ) {
911 Plugin::$instance->skins_manager->add_skin( $this, $skin );
912 }
913
914 /**
915 * Get single skin.
916 *
917 * Retrieve a single skin based on skin ID, from all the skin assigned to
918 * the widget. If the skin does not exist or not assigned to the widget,
919 * return false.
920 *
921 * @since 1.0.0
922 * @access public
923 *
924 * @param string $skin_id Skin ID.
925 *
926 * @return string|false Single skin, or false.
927 */
928 public function get_skin( $skin_id ) {
929 $skins = $this->get_skins();
930 if ( isset( $skins[ $skin_id ] ) ) {
931 return $skins[ $skin_id ];
932 }
933
934 return false;
935 }
936
937 /**
938 * Get current skin ID.
939 *
940 * Retrieve the ID of the current skin.
941 *
942 * @since 1.0.0
943 * @access public
944 *
945 * @return string Current skin.
946 */
947 public function get_current_skin_id() {
948 return $this->get_settings( '_skin' );
949 }
950
951 /**
952 * Get current skin.
953 *
954 * Retrieve the current skin, or if non exist return false.
955 *
956 * @since 1.0.0
957 * @access public
958 *
959 * @return Skin_Base|false Current skin or false.
960 */
961 public function get_current_skin() {
962 return $this->get_skin( $this->get_current_skin_id() );
963 }
964
965 /**
966 * Remove widget skin.
967 *
968 * Unregister an existing skin and remove it from the widget.
969 *
970 * @since 1.0.0
971 * @access public
972 *
973 * @param string $skin_id Skin ID.
974 *
975 * @return \WP_Error|true Whether the skin was removed successfully from the widget.
976 */
977 public function remove_skin( $skin_id ) {
978 return Plugin::$instance->skins_manager->remove_skin( $this, $skin_id );
979 }
980
981 /**
982 * Get widget skins.
983 *
984 * Retrieve all the skin assigned to the widget.
985 *
986 * @since 1.0.0
987 * @access public
988 *
989 * @return Skin_Base[]
990 */
991 public function get_skins() {
992 return Plugin::$instance->skins_manager->get_skins( $this );
993 }
994
995 /**
996 * Get group name.
997 *
998 * Some widgets need to use group names, this method allows you to create them.
999 * By default it retrieves the regular name.
1000 *
1001 * @since 3.3.0
1002 * @access public
1003 *
1004 * @return string Unique name.
1005 */
1006 public function get_group_name() {
1007 return $this->get_name();
1008 }
1009
1010 /**
1011 * @param string $plugin_title Plugin's title
1012 * @param string $since Plugin version widget was deprecated
1013 * @param string $last Plugin version in which the widget will be removed
1014 * @param string $replacement Widget replacement
1015 */
1016 protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
1017 $this->start_controls_section(
1018 'Deprecated',
1019 [
1020 'label' => esc_html__( 'Deprecated', 'elementor' ),
1021 ]
1022 );
1023
1024 $this->add_control(
1025 'deprecated_notice',
1026 [
1027 'type' => Controls_Manager::DEPRECATED_NOTICE,
1028 'widget' => $this->get_title(),
1029 'since' => $since,
1030 'last' => $last,
1031 'plugin' => $plugin_title,
1032 'replacement' => $replacement,
1033 ]
1034 );
1035
1036 $this->end_controls_section();
1037 }
1038
1039 /**
1040 * Init controls.
1041 *
1042 * Reset the `is_first_section` flag to true, so when the Stacks are cleared
1043 * all the controls will be registered again with their skins and settings.
1044 *
1045 * @since 3.14.0
1046 * @access protected
1047 */
1048 protected function init_controls() {
1049 $this->is_first_section = true;
1050 parent::init_controls();
1051 }
1052
1053 public function register_runtime_widget( $widget_name ) {
1054 self::$registered_runtime_widgets[] = $widget_name;
1055 }
1056
1057 /**
1058 * Mark widget as deprecated.
1059 *
1060 * Use `get_deprecation_message()` method to print the message control at specific location in register_controls().
1061 *
1062 * @param $version string The version of Elementor that deprecated the widget.
1063 * @param $message string A message regarding the deprecation.
1064 * @param $replacement string The widget that should be used instead.
1065 */
1066 protected function add_deprecation_message( $version, $message, $replacement ) {
1067 // Expose the config for handling in JS.
1068 $this->set_config( 'deprecation', [
1069 'version' => $version,
1070 'message' => $message,
1071 'replacement' => $replacement,
1072 ] );
1073
1074 $this->add_control(
1075 'deprecation_message',
1076 [
1077 'type' => Controls_Manager::ALERT,
1078 'alert_type' => 'info',
1079 'content' => $message,
1080 'separator' => 'after',
1081 ]
1082 );
1083 }
1084 }
1085