PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.2
Elementor Website Builder – more than just a page builder v3.19.2
4.3.1 4.3.0 4.3.0-beta3 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 All 454 releases
← All changes | includes/widgets/traits/button-trait.php +77 -185 4.2.0-beta2 → 3.19.2 View file →
@@ -10,12 +10,11 @@
10 10 use Elementor\Group_Control_Text_Shadow;
11 11 use Elementor\Group_Control_Typography;
12 12 use Elementor\Icons_Manager;
13 13 use Elementor\Widget_Base;
14 -use Elementor\Plugin;
15 14
16 15 if ( ! defined( 'ABSPATH' ) ) {
17 - exit; // Exit if accessed directly.
16 + exit; // Exit if accessed directly
18 17 }
19 18
20 19 trait Button_Trait {
21 20 /**
@@ -47,8 +46,10 @@
47 46 *
48 47 * @type array $section_condition Set of conditions to hide the controls.
49 48 * @type string $button_text Text contained in button.
50 49 * @type string $text_control_label Name for the label of the text control.
50 + * @type string $alignment_control_prefix_class Prefix class name for the button alignment control.
51 + * @type string $alignment_default Default alignment for the button.
51 52 * @type array $icon_exclude_inline_options Set of icon types to exclude from icon controls.
52 53 * }
53 54 */
54 55 protected function register_button_content_controls( $args = [] ) {
@@ -55,8 +56,10 @@
55 56 $default_args = [
56 57 'section_condition' => [],
57 58 'button_default_text' => esc_html__( 'Click here', 'elementor' ),
58 59 'text_control_label' => esc_html__( 'Text', 'elementor' ),
60 + 'alignment_control_prefix_class' => 'elementor%s-align-',
61 + 'alignment_default' => '',
59 62 'icon_exclude_inline_options' => [],
60 63 ];
61 64
62 65 $args = wp_parse_args( $args, $default_args );
@@ -107,8 +110,37 @@
107 110 'condition' => $args['section_condition'],
108 111 ]
109 112 );
110 113
114 + $this->add_responsive_control(
115 + 'align',
116 + [
117 + 'label' => esc_html__( 'Alignment', 'elementor' ),
118 + 'type' => Controls_Manager::CHOOSE,
119 + 'options' => [
120 + 'left' => [
121 + 'title' => esc_html__( 'Left', 'elementor' ),
122 + 'icon' => 'eicon-text-align-left',
123 + ],
124 + 'center' => [
125 + 'title' => esc_html__( 'Center', 'elementor' ),
126 + 'icon' => 'eicon-text-align-center',
127 + ],
128 + 'right' => [
129 + 'title' => esc_html__( 'Right', 'elementor' ),
130 + 'icon' => 'eicon-text-align-right',
131 + ],
132 + 'justify' => [
133 + 'title' => esc_html__( 'Justified', 'elementor' ),
134 + 'icon' => 'eicon-text-align-justify',
135 + ],
136 + ],
137 + 'prefix_class' => $args['alignment_control_prefix_class'],
138 + 'default' => $args['alignment_default'],
139 + 'condition' => $args['section_condition'],
140 + ]
141 + );
142 +
111 143 $this->add_control(
112 144 'size',
113 145 [
114 146 'label' => esc_html__( 'Size', 'elementor' ),
@@ -115,9 +147,9 @@
115 147 'type' => Controls_Manager::SELECT,
116 148 'default' => 'sm',
117 149 'options' => self::get_button_sizes(),
118 150 'style_transfer' => true,
119 - 'condition' => array_merge( $args['section_condition'], [ 'size[value]!' => 'sm' ] ), // a workaround to hide the control, unless it's in use (not default).
151 + 'condition' => $args['section_condition'],
120 152 ]
121 153 );
122 154
123 155 $this->add_control(
@@ -136,35 +168,15 @@
136 168 $this->add_control(
137 169 'icon_align',
138 170 [
139 171 'label' => esc_html__( 'Icon Position', 'elementor' ),
140 - 'type' => Controls_Manager::CHOOSE,
141 - 'default' => is_rtl() ? 'row-reverse' : 'row',
172 + 'type' => Controls_Manager::SELECT,
173 + 'default' => 'left',
142 174 'options' => [
143 - 'row' => [
144 - 'title' => esc_html__( 'Start', 'elementor' ),
145 - 'icon' => 'eicon-h-align-left',
146 - ],
147 - 'row-reverse' => [
148 - 'title' => esc_html__( 'End', 'elementor' ),
149 - 'icon' => 'eicon-h-align-right',
150 - ],
175 + 'left' => esc_html__( 'Before', 'elementor' ),
176 + 'right' => esc_html__( 'After', 'elementor' ),
151 177 ],
152 - 'classes' => 'elementor-control-start-end',
153 - 'selectors_dictionary' => [
154 - 'left' => is_rtl() ? 'row-reverse' : 'row',
155 - 'right' => is_rtl() ? 'row' : 'row-reverse',
156 - ],
157 - 'selectors' => [
158 - '{{WRAPPER}} .elementor-button-content-wrapper' => 'flex-direction: {{VALUE}};',
159 - ],
160 - 'condition' => array_merge(
161 - $args['section_condition'],
162 - [
163 - 'text!' => '',
164 - 'selected_icon[value]!' => '',
165 - ]
166 - ),
178 + 'condition' => array_merge( $args['section_condition'], [ 'selected_icon[value]!' => '' ] ),
167 179 ]
168 180 );
169 181
170 182 $this->add_control(
@@ -184,17 +196,12 @@
184 196 'max' => 5,
185 197 ],
186 198 ],
187 199 'selectors' => [
188 - '{{WRAPPER}} .elementor-button .elementor-button-content-wrapper' => 'gap: {{SIZE}}{{UNIT}};',
200 + '{{WRAPPER}} .elementor-button .elementor-align-icon-right' => 'margin-left: {{SIZE}}{{UNIT}};',
201 + '{{WRAPPER}} .elementor-button .elementor-align-icon-left' => 'margin-right: {{SIZE}}{{UNIT}};',
189 202 ],
190 - 'condition' => array_merge(
191 - $args['section_condition'],
192 - [
193 - 'text!' => '',
194 - 'selected_icon[value]!' => '',
195 - ]
196 - ),
203 + 'condition' => $args['section_condition'],
197 204 ]
198 205 );
199 206
200 207 $this->add_control(
@@ -210,10 +217,9 @@
210 217 ],
211 218 'default' => '',
212 219 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'elementor' ),
213 220 'description' => sprintf(
214 - /* translators: 1: `<code>` opening tag, 2: `</code>` closing tag. */
215 - esc_html__( 'Please make sure the ID is unique and not used elsewhere on the page. This field allows %1$sA-z 0-9%2$s & underscore chars without spaces.', 'elementor' ),
221 + esc_html__( 'Please make sure the ID is unique and not used elsewhere on the page this form is displayed. This field allows %1$sA-z 0-9%2$s & underscore chars without spaces.', 'elementor' ),
216 222 '<code>',
217 223 '</code>'
218 224 ),
219 225 'separator' => 'before',
@@ -221,91 +227,15 @@
221 227 ]
222 228 );
223 229 }
224 230
225 - /**
226 - * @since 3.4.0
227 - *
228 - * @param array $args {
229 - * An array of values for the button adjustments.
230 - *
231 - * @type array $section_condition Set of conditions to hide the controls.
232 - * @type string $alignment_default Default position for the button.
233 - * @type string $alignment_control_prefix_class Prefix class name for the button position control.
234 - * @type string $content_alignment_default Default alignment for the button content.
235 - * }
236 - */
237 231 protected function register_button_style_controls( $args = [] ) {
238 232 $default_args = [
239 233 'section_condition' => [],
240 - 'alignment_default' => '',
241 - 'alignment_control_prefix_class' => 'elementor%s-align-',
242 - 'content_alignment_default' => '',
243 234 ];
244 235
245 236 $args = wp_parse_args( $args, $default_args );
246 237
247 - $this->add_responsive_control(
248 - 'align',
249 - [
250 - 'label' => esc_html__( 'Position', 'elementor' ),
251 - 'type' => Controls_Manager::CHOOSE,
252 - 'options' => [
253 - 'left' => [
254 - 'title' => esc_html__( 'Left', 'elementor' ),
255 - 'icon' => 'eicon-h-align-left',
256 - ],
257 - 'center' => [
258 - 'title' => esc_html__( 'Center', 'elementor' ),
259 - 'icon' => 'eicon-h-align-center',
260 - ],
261 - 'right' => [
262 - 'title' => esc_html__( 'Right', 'elementor' ),
263 - 'icon' => 'eicon-h-align-right',
264 - ],
265 - 'justify' => [
266 - 'title' => esc_html__( 'Stretch', 'elementor' ),
267 - 'icon' => 'eicon-h-align-stretch',
268 - ],
269 - ],
270 - 'prefix_class' => $args['alignment_control_prefix_class'],
271 - 'default' => $args['alignment_default'],
272 - 'condition' => $args['section_condition'],
273 - ]
274 - );
275 -
276 - $this->add_responsive_control(
277 - 'content_align',
278 - [
279 - 'label' => esc_html__( 'Alignment', 'elementor' ),
280 - 'type' => Controls_Manager::CHOOSE,
281 - 'options' => [
282 - 'start' => [
283 - 'title' => esc_html__( 'Start', 'elementor' ),
284 - 'icon' => 'eicon-text-align-left',
285 - ],
286 - 'center' => [
287 - 'title' => esc_html__( 'Center', 'elementor' ),
288 - 'icon' => 'eicon-text-align-center',
289 - ],
290 - 'end' => [
291 - 'title' => esc_html__( 'End', 'elementor' ),
292 - 'icon' => 'eicon-text-align-right',
293 - ],
294 - 'space-between' => [
295 - 'title' => esc_html__( 'Space between', 'elementor' ),
296 - 'icon' => 'eicon-text-align-justify',
297 - ],
298 - ],
299 - 'default' => $args['content_alignment_default'],
300 - 'classes' => 'elementor-control-start-end',
301 - 'selectors' => [
302 - '{{WRAPPER}} .elementor-button .elementor-button-content-wrapper' => 'justify-content: {{VALUE}};',
303 - ],
304 - 'condition' => array_merge( $args['section_condition'], [ 'align' => 'justify' ] ),
305 - ]
306 - );
307 -
308 238 $this->add_group_control(
309 239 Group_Control_Typography::get_type(),
310 240 [
311 241 'name' => 'typography',
@@ -371,17 +301,8 @@
371 301 'condition' => $args['section_condition'],
372 302 ]
373 303 );
374 304
375 - $this->add_group_control(
376 - Group_Control_Box_Shadow::get_type(),
377 - [
378 - 'name' => 'button_box_shadow',
379 - 'selector' => '{{WRAPPER}} .elementor-button',
380 - 'condition' => $args['section_condition'],
381 - ]
382 - );
383 -
384 305 $this->end_controls_tab();
385 306
386 307 $this->start_controls_tab(
387 308 'tab_button_hover',
@@ -424,8 +345,11 @@
424 345 'button_hover_border_color',
425 346 [
426 347 'label' => esc_html__( 'Border Color', 'elementor' ),
427 348 'type' => Controls_Manager::COLOR,
349 + 'condition' => [
350 + 'border_border!' => '',
351 + ],
428 352 'selectors' => [
429 353 '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'border-color: {{VALUE}};',
430 354 ],
431 355 'condition' => $args['section_condition'],
@@ -431,33 +355,9 @@
431 355 'condition' => $args['section_condition'],
432 356 ]
433 357 );
434 358
435 - $this->add_group_control(
436 - Group_Control_Box_Shadow::get_type(),
437 - [
438 - 'name' => 'button_hover_box_shadow',
439 - 'selector' => '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus',
440 - 'condition' => $args['section_condition'],
441 - ]
442 - );
443 -
444 359 $this->add_control(
445 - 'button_hover_transition_duration',
446 - [
447 - 'label' => esc_html__( 'Transition Duration', 'elementor' ),
448 - 'type' => Controls_Manager::SLIDER,
449 - 'size_units' => [ 's', 'ms', 'custom' ],
450 - 'default' => [
451 - 'unit' => 's',
452 - ],
453 - 'selectors' => [
454 - '{{WRAPPER}} .elementor-button' => 'transition-duration: {{SIZE}}{{UNIT}};',
455 - ],
456 - ]
457 - );
458 -
459 - $this->add_control(
460 360 'hover_animation',
461 361 [
462 362 'label' => esc_html__( 'Hover Animation', 'elementor' ),
463 363 'type' => Controls_Manager::HOVER_ANIMATION,
@@ -491,8 +391,17 @@
491 391 'condition' => $args['section_condition'],
492 392 ]
493 393 );
494 394
395 + $this->add_group_control(
396 + Group_Control_Box_Shadow::get_type(),
397 + [
398 + 'name' => 'button_box_shadow',
399 + 'selector' => '{{WRAPPER}} .elementor-button',
400 + 'condition' => $args['section_condition'],
401 + ]
402 + );
403 +
495 404 $this->add_responsive_control(
496 405 'text_padding',
497 406 [
498 407 'label' => esc_html__( 'Padding', 'elementor' ),
@@ -516,9 +425,9 @@
516 425 *
517 426 * @since 3.4.0
518 427 * @access protected
519 428 */
520 - protected function render_button( ?Widget_Base $instance = null ) {
429 + protected function render_button( Widget_Base $instance = null ) {
521 430 if ( empty( $instance ) ) {
522 431 $instance = $this;
523 432 }
524 433
@@ -523,14 +432,8 @@
523 432 }
524 433
525 434 $settings = $instance->get_settings_for_display();
526 435
527 - if ( empty( $settings['text'] ) && empty( $settings['selected_icon']['value'] ) ) {
528 - return;
529 - }
530 -
531 - $optimized_markup = Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
532 -
533 436 $instance->add_render_attribute( 'wrapper', 'class', 'elementor-button-wrapper' );
534 437
535 438 $instance->add_render_attribute( 'button', 'class', 'elementor-button' );
536 439
@@ -546,10 +449,8 @@
546 449 }
547 450
548 451 if ( ! empty( $settings['size'] ) ) {
549 452 $instance->add_render_attribute( 'button', 'class', 'elementor-size-' . $settings['size'] );
550 - } else {
551 - $instance->add_render_attribute( 'button', 'class', 'elementor-size-sm' ); // BC, to make sure the class is always present
552 453 }
553 454
554 455 if ( ! empty( $settings['hover_animation'] ) ) {
555 456 $instance->add_render_attribute( 'button', 'class', 'elementor-animation-' . $settings['hover_animation'] );
@@ -554,17 +455,13 @@
554 455 if ( ! empty( $settings['hover_animation'] ) ) {
555 456 $instance->add_render_attribute( 'button', 'class', 'elementor-animation-' . $settings['hover_animation'] );
556 457 }
557 458 ?>
558 - <?php if ( ! $optimized_markup ) : ?>
559 459 <div <?php $instance->print_render_attribute_string( 'wrapper' ); ?>>
560 - <?php endif; ?>
561 460 <a <?php $instance->print_render_attribute_string( 'button' ); ?>>
562 461 <?php $this->render_text( $instance ); ?>
563 462 </a>
564 - <?php if ( ! $optimized_markup ) : ?>
565 463 </div>
566 - <?php endif; ?>
567 464 <?php
568 465 }
569 466
570 467 /**
@@ -577,20 +474,14 @@
577 474 */
578 475 protected function content_template() {
579 476 ?>
580 477 <#
581 - if ( '' === settings.text && '' === settings.selected_icon.value ) {
582 - return;
583 - }
584 -
585 - const optimized_markup = elementorCommon.config.experimentalFeatures.e_optimized_markup;
586 -
587 478 view.addRenderAttribute( 'wrapper', 'class', 'elementor-button-wrapper' );
588 479
589 480 view.addRenderAttribute( 'button', 'class', 'elementor-button' );
590 481
591 - if ( '' !== settings.link?.url ) {
592 - view.addRenderAttribute( 'button', 'href', elementor.helpers.sanitizeUrl( settings.link?.url ) );
482 + if ( '' !== settings.link.url ) {
483 + view.addRenderAttribute( 'button', 'href', settings.link.url );
593 484 view.addRenderAttribute( 'button', 'class', 'elementor-button-link' );
594 485 } else {
595 486 view.addRenderAttribute( 'button', 'role', 'button' );
596 487 }
@@ -606,21 +497,18 @@
606 497 if ( '' !== settings.hover_animation ) {
607 498 view.addRenderAttribute( 'button', 'class', 'elementor-animation-' + settings.hover_animation );
608 499 }
609 500
610 - view.addRenderAttribute( 'icon', 'class', 'elementor-button-icon' );
611 501 view.addRenderAttribute( 'text', 'class', 'elementor-button-text' );
612 502 view.addInlineEditingAttributes( 'text', 'none' );
613 503 var iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
614 504 migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' );
615 505 #>
616 - <# if ( ! optimized_markup ) { #>
617 506 <div {{{ view.getRenderAttributeString( 'wrapper' ) }}}>
618 - <# } #>
619 507 <a {{{ view.getRenderAttributeString( 'button' ) }}}>
620 508 <span class="elementor-button-content-wrapper">
621 509 <# if ( settings.icon || settings.selected_icon ) { #>
622 - <span {{{ view.getRenderAttributeString( 'icon' ) }}}>
510 + <span class="elementor-button-icon elementor-align-icon-{{ settings.icon_align }}">
623 511 <# if ( ( migrated || ! settings.icon ) && iconHTML.rendered ) { #>
624 512 {{{ iconHTML.value }}}
625 513 <# } else { #>
626 514 <i class="{{ settings.icon }}" aria-hidden="true"></i>
@@ -626,16 +514,12 @@
626 514 <i class="{{ settings.icon }}" aria-hidden="true"></i>
627 515 <# } #>
628 516 </span>
629 517 <# } #>
630 - <# if ( settings.text ) { #>
631 - <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{ settings.text }}</span>
632 - <# } #>
518 + <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{{ settings.text }}}</span>
633 519 </span>
634 520 </a>
635 - <# if ( ! optimized_markup ) { #>
636 521 </div>
637 - <# } #>
638 522 <?php
639 523 }
640 524
641 525 /**
@@ -647,9 +531,9 @@
647 531 *
648 532 * @since 3.4.0
649 533 * @access protected
650 534 */
651 - protected function render_text( ?Widget_Base $instance = null ) {
535 + protected function render_text( Widget_Base $instance = null ) {
652 536 // The default instance should be `$this` (a Button widget), unless the Trait is being used from outside of a widget (e.g. `Skin_Base`) which should pass an `$instance`.
653 537 if ( empty( $instance ) ) {
654 538 $instance = $this;
655 539 }
@@ -658,14 +542,24 @@
658 542
659 543 $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
660 544 $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
661 545
546 + if ( ! $is_new && empty( $settings['icon_align'] ) ) {
547 + // @todo: remove when deprecated
548 + // added as bc in 2.6
549 + //old default
550 + $settings['icon_align'] = $instance->get_settings( 'icon_align' );
551 + }
552 +
662 553 $instance->add_render_attribute( [
663 554 'content-wrapper' => [
664 555 'class' => 'elementor-button-content-wrapper',
665 556 ],
666 - 'icon' => [
667 - 'class' => 'elementor-button-icon',
557 + 'icon-align' => [
558 + 'class' => [
559 + 'elementor-button-icon',
560 + 'elementor-align-icon-' . $settings['icon_align'],
561 + ],
668 562 ],
669 563 'text' => [
670 564 'class' => 'elementor-button-text',
671 565 ],
@@ -671,13 +565,13 @@
671 565 ],
672 566 ] );
673 567
674 568 // TODO: replace the protected with public
675 - // $instance->add_inline_editing_attributes( 'text', 'none' );
569 + //$instance->add_inline_editing_attributes( 'text', 'none' );
676 570 ?>
677 571 <span <?php $instance->print_render_attribute_string( 'content-wrapper' ); ?>>
678 572 <?php if ( ! empty( $settings['icon'] ) || ! empty( $settings['selected_icon']['value'] ) ) : ?>
679 - <span <?php $instance->print_render_attribute_string( 'icon' ); ?>>
573 + <span <?php $instance->print_render_attribute_string( 'icon-align' ); ?>>
680 574 <?php if ( $is_new || $migrated ) :
681 575 Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
682 576 else : ?>
683 577 <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i>
@@ -683,11 +577,9 @@
683 577 <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i>
684 578 <?php endif; ?>
685 579 </span>
686 580 <?php endif; ?>
687 - <?php if ( ! empty( $settings['text'] ) ) : ?>
688 - <span <?php $instance->print_render_attribute_string( 'text' ); ?>><?php echo wp_kses_post( $settings['text'] ); ?></span>
689 - <?php endif; ?>
581 + <span <?php $instance->print_render_attribute_string( 'text' ); ?>><?php $this->print_unescaped_setting( 'text' ); ?></span>
690 582 </span>
691 583 <?php
692 584 }
693 585