PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.2
Elementor Website Builder – more than just a page builder v3.13.2
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 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | includes/widgets/traits/button-trait.php +91 -219 4.3.0-beta33.13.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 );
@@ -100,8 +103,9 @@
100 103 'type' => Controls_Manager::URL,
101 104 'dynamic' => [
102 105 'active' => true,
103 106 ],
107 + 'placeholder' => esc_html__( 'https://your-link.com', 'elementor' ),
104 108 'default' => [
105 109 'url' => '#',
106 110 ],
107 111 'condition' => $args['section_condition'],
@@ -107,8 +111,37 @@
107 111 'condition' => $args['section_condition'],
108 112 ]
109 113 );
110 114
115 + $this->add_responsive_control(
116 + 'align',
117 + [
118 + 'label' => esc_html__( 'Alignment', 'elementor' ),
119 + 'type' => Controls_Manager::CHOOSE,
120 + 'options' => [
121 + 'left' => [
122 + 'title' => esc_html__( 'Left', 'elementor' ),
123 + 'icon' => 'eicon-text-align-left',
124 + ],
125 + 'center' => [
126 + 'title' => esc_html__( 'Center', 'elementor' ),
127 + 'icon' => 'eicon-text-align-center',
128 + ],
129 + 'right' => [
130 + 'title' => esc_html__( 'Right', 'elementor' ),
131 + 'icon' => 'eicon-text-align-right',
132 + ],
133 + 'justify' => [
134 + 'title' => esc_html__( 'Justified', 'elementor' ),
135 + 'icon' => 'eicon-text-align-justify',
136 + ],
137 + ],
138 + 'prefix_class' => $args['alignment_control_prefix_class'],
139 + 'default' => $args['alignment_default'],
140 + 'condition' => $args['section_condition'],
141 + ]
142 + );
143 +
111 144 $this->add_control(
112 145 'size',
113 146 [
114 147 'label' => esc_html__( 'Size', 'elementor' ),
@@ -115,9 +148,9 @@
115 148 'type' => Controls_Manager::SELECT,
116 149 'default' => 'sm',
117 150 'options' => self::get_button_sizes(),
118 151 '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).
152 + 'condition' => $args['section_condition'],
120 153 ]
121 154 );
122 155
123 156 $this->add_control(
@@ -136,35 +169,15 @@
136 169 $this->add_control(
137 170 'icon_align',
138 171 [
139 172 'label' => esc_html__( 'Icon Position', 'elementor' ),
140 - 'type' => Controls_Manager::CHOOSE,
141 - 'default' => is_rtl() ? 'row-reverse' : 'row',
173 + 'type' => Controls_Manager::SELECT,
174 + 'default' => 'left',
142 175 '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 - ],
176 + 'left' => esc_html__( 'Before', 'elementor' ),
177 + 'right' => esc_html__( 'After', 'elementor' ),
151 178 ],
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 - ),
179 + 'condition' => array_merge( $args['section_condition'], [ 'selected_icon[value]!' => '' ] ),
167 180 ]
168 181 );
169 182
170 183 $this->add_control(
@@ -171,34 +184,32 @@
171 184 'icon_indent',
172 185 [
173 186 'label' => esc_html__( 'Icon Spacing', 'elementor' ),
174 187 'type' => Controls_Manager::SLIDER,
175 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
176 188 'range' => [
177 189 'px' => [
178 190 'max' => 50,
179 191 ],
180 - 'em' => [
181 - 'max' => 5,
182 - ],
183 - 'rem' => [
184 - 'max' => 5,
185 - ],
186 192 ],
187 193 'selectors' => [
188 - '{{WRAPPER}} .elementor-button .elementor-button-content-wrapper' => 'gap: {{SIZE}}{{UNIT}};',
194 + '{{WRAPPER}} .elementor-button .elementor-align-icon-right' => 'margin-left: {{SIZE}}{{UNIT}};',
195 + '{{WRAPPER}} .elementor-button .elementor-align-icon-left' => 'margin-right: {{SIZE}}{{UNIT}};',
189 196 ],
190 - 'condition' => array_merge(
191 - $args['section_condition'],
192 - [
193 - 'text!' => '',
194 - 'selected_icon[value]!' => '',
195 - ]
196 - ),
197 + 'condition' => $args['section_condition'],
197 198 ]
198 199 );
199 200
200 201 $this->add_control(
202 + 'view',
203 + [
204 + 'label' => esc_html__( 'View', 'elementor' ),
205 + 'type' => Controls_Manager::HIDDEN,
206 + 'default' => 'traditional',
207 + 'condition' => $args['section_condition'],
208 + ]
209 + );
210 +
211 + $this->add_control(
201 212 'button_css_id',
202 213 [
203 214 'label' => esc_html__( 'Button ID', 'elementor' ),
204 215 'type' => Controls_Manager::TEXT,
@@ -210,10 +221,9 @@
210 221 ],
211 222 'default' => '',
212 223 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'elementor' ),
213 224 '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' ),
225 + 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 226 '<code>',
217 227 '</code>'
218 228 ),
219 229 'separator' => 'before',
@@ -221,91 +231,15 @@
221 231 ]
222 232 );
223 233 }
224 234
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 235 protected function register_button_style_controls( $args = [] ) {
238 236 $default_args = [
239 237 'section_condition' => [],
240 - 'alignment_default' => '',
241 - 'alignment_control_prefix_class' => 'elementor%s-align-',
242 - 'content_alignment_default' => '',
243 238 ];
244 239
245 240 $args = wp_parse_args( $args, $default_args );
246 241
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 242 $this->add_group_control(
309 243 Group_Control_Typography::get_type(),
310 244 [
311 245 'name' => 'typography',
@@ -371,17 +305,8 @@
371 305 'condition' => $args['section_condition'],
372 306 ]
373 307 );
374 308
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 309 $this->end_controls_tab();
385 310
386 311 $this->start_controls_tab(
387 312 'tab_button_hover',
@@ -424,8 +349,11 @@
424 349 'button_hover_border_color',
425 350 [
426 351 'label' => esc_html__( 'Border Color', 'elementor' ),
427 352 'type' => Controls_Manager::COLOR,
353 + 'condition' => [
354 + 'border_border!' => '',
355 + ],
428 356 'selectors' => [
429 357 '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'border-color: {{VALUE}};',
430 358 ],
431 359 'condition' => $args['section_condition'],
@@ -431,33 +359,9 @@
431 359 'condition' => $args['section_condition'],
432 360 ]
433 361 );
434 362
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 363 $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 364 'hover_animation',
461 365 [
462 366 'label' => esc_html__( 'Hover Animation', 'elementor' ),
463 367 'type' => Controls_Manager::HOVER_ANIMATION,
@@ -491,8 +395,17 @@
491 395 'condition' => $args['section_condition'],
492 396 ]
493 397 );
494 398
399 + $this->add_group_control(
400 + Group_Control_Box_Shadow::get_type(),
401 + [
402 + 'name' => 'button_box_shadow',
403 + 'selector' => '{{WRAPPER}} .elementor-button',
404 + 'condition' => $args['section_condition'],
405 + ]
406 + );
407 +
495 408 $this->add_responsive_control(
496 409 'text_padding',
497 410 [
498 411 'label' => esc_html__( 'Padding', 'elementor' ),
@@ -516,9 +429,9 @@
516 429 *
517 430 * @since 3.4.0
518 431 * @access protected
519 432 */
520 - protected function render_button( ?Widget_Base $instance = null ) {
433 + protected function render_button( Widget_Base $instance = null ) {
521 434 if ( empty( $instance ) ) {
522 435 $instance = $this;
523 436 }
524 437
@@ -523,25 +436,18 @@
523 436 }
524 437
525 438 $settings = $instance->get_settings_for_display();
526 439
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 440 $instance->add_render_attribute( 'wrapper', 'class', 'elementor-button-wrapper' );
534 441
535 - $instance->add_render_attribute( 'button', 'class', 'elementor-button' );
536 -
537 442 if ( ! empty( $settings['link']['url'] ) ) {
538 443 $instance->add_link_attributes( 'button', $settings['link'] );
539 444 $instance->add_render_attribute( 'button', 'class', 'elementor-button-link' );
540 - } else {
541 - $instance->add_render_attribute( 'button', 'role', 'button' );
542 445 }
543 446
447 + $instance->add_render_attribute( 'button', 'class', 'elementor-button' );
448 + $instance->add_render_attribute( 'button', 'role', 'button' );
449 +
544 450 if ( ! empty( $settings['button_css_id'] ) ) {
545 451 $instance->add_render_attribute( 'button', 'id', $settings['button_css_id'] );
546 452 }
547 453
@@ -546,10 +452,8 @@
546 452 }
547 453
548 454 if ( ! empty( $settings['size'] ) ) {
549 455 $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 456 }
553 457
554 458 if ( ! empty( $settings['hover_animation'] ) ) {
555 459 $instance->add_render_attribute( 'button', 'class', 'elementor-animation-' . $settings['hover_animation'] );
@@ -554,17 +458,13 @@
554 458 if ( ! empty( $settings['hover_animation'] ) ) {
555 459 $instance->add_render_attribute( 'button', 'class', 'elementor-animation-' . $settings['hover_animation'] );
556 460 }
557 461 ?>
558 - <?php if ( ! $optimized_markup ) : ?>
559 462 <div <?php $instance->print_render_attribute_string( 'wrapper' ); ?>>
560 - <?php endif; ?>
561 463 <a <?php $instance->print_render_attribute_string( 'button' ); ?>>
562 464 <?php $this->render_text( $instance ); ?>
563 465 </a>
564 - <?php if ( ! $optimized_markup ) : ?>
565 466 </div>
566 - <?php endif; ?>
567 467 <?php
568 468 }
569 469
570 470 /**
@@ -577,50 +477,18 @@
577 477 */
578 478 protected function content_template() {
579 479 ?>
580 480 <#
581 - if ( '' === settings.text && '' === settings.selected_icon.value ) {
582 - return;
583 - }
584 -
585 - const optimized_markup = elementorCommon.config.experimentalFeatures.e_optimized_markup;
586 -
587 - view.addRenderAttribute( 'wrapper', 'class', 'elementor-button-wrapper' );
588 -
589 - view.addRenderAttribute( 'button', 'class', 'elementor-button' );
590 -
591 - if ( '' !== settings.link?.url ) {
592 - view.addRenderAttribute( 'button', 'href', elementor.helpers.sanitizeUrl( settings.link?.url ) );
593 - view.addRenderAttribute( 'button', 'class', 'elementor-button-link' );
594 - } else {
595 - view.addRenderAttribute( 'button', 'role', 'button' );
596 - }
597 -
598 - if ( '' !== settings.button_css_id ) {
599 - view.addRenderAttribute( 'button', 'id', settings.button_css_id );
600 - }
601 -
602 - if ( '' !== settings.size ) {
603 - view.addRenderAttribute( 'button', 'class', 'elementor-size-' + settings.size );
604 - }
605 -
606 - if ( '' !== settings.hover_animation ) {
607 - view.addRenderAttribute( 'button', 'class', 'elementor-animation-' + settings.hover_animation );
608 - }
609 -
610 - view.addRenderAttribute( 'icon', 'class', 'elementor-button-icon' );
611 481 view.addRenderAttribute( 'text', 'class', 'elementor-button-text' );
612 482 view.addInlineEditingAttributes( 'text', 'none' );
613 483 var iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
614 484 migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' );
615 485 #>
616 - <# if ( ! optimized_markup ) { #>
617 - <div {{{ view.getRenderAttributeString( 'wrapper' ) }}}>
618 - <# } #>
619 - <a {{{ view.getRenderAttributeString( 'button' ) }}}>
486 + <div class="elementor-button-wrapper">
487 + <a id="{{ settings.button_css_id }}" class="elementor-button elementor-size-{{ settings.size }} elementor-animation-{{ settings.hover_animation }}" href="{{ settings.link.url }}" role="button">
620 488 <span class="elementor-button-content-wrapper">
621 489 <# if ( settings.icon || settings.selected_icon ) { #>
622 - <span {{{ view.getRenderAttributeString( 'icon' ) }}}>
490 + <span class="elementor-button-icon elementor-align-icon-{{ settings.icon_align }}">
623 491 <# if ( ( migrated || ! settings.icon ) && iconHTML.rendered ) { #>
624 492 {{{ iconHTML.value }}}
625 493 <# } else { #>
626 494 <i class="{{ settings.icon }}" aria-hidden="true"></i>
@@ -626,16 +494,12 @@
626 494 <i class="{{ settings.icon }}" aria-hidden="true"></i>
627 495 <# } #>
628 496 </span>
629 497 <# } #>
630 - <# if ( settings.text ) { #>
631 - <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{ settings.text }}</span>
632 - <# } #>
498 + <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{{ settings.text }}}</span>
633 499 </span>
634 500 </a>
635 - <# if ( ! optimized_markup ) { #>
636 501 </div>
637 - <# } #>
638 502 <?php
639 503 }
640 504
641 505 /**
@@ -647,9 +511,9 @@
647 511 *
648 512 * @since 3.4.0
649 513 * @access protected
650 514 */
651 - protected function render_text( ?Widget_Base $instance = null ) {
515 + protected function render_text( Widget_Base $instance = null ) {
652 516 // 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 517 if ( empty( $instance ) ) {
654 518 $instance = $this;
655 519 }
@@ -658,14 +522,24 @@
658 522
659 523 $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
660 524 $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
661 525
526 + if ( ! $is_new && empty( $settings['icon_align'] ) ) {
527 + // @todo: remove when deprecated
528 + // added as bc in 2.6
529 + //old default
530 + $settings['icon_align'] = $instance->get_settings( 'icon_align' );
531 + }
532 +
662 533 $instance->add_render_attribute( [
663 534 'content-wrapper' => [
664 535 'class' => 'elementor-button-content-wrapper',
665 536 ],
666 - 'icon' => [
667 - 'class' => 'elementor-button-icon',
537 + 'icon-align' => [
538 + 'class' => [
539 + 'elementor-button-icon',
540 + 'elementor-align-icon-' . $settings['icon_align'],
541 + ],
668 542 ],
669 543 'text' => [
670 544 'class' => 'elementor-button-text',
671 545 ],
@@ -671,13 +545,13 @@
671 545 ],
672 546 ] );
673 547
674 548 // TODO: replace the protected with public
675 - // $instance->add_inline_editing_attributes( 'text', 'none' );
549 + //$instance->add_inline_editing_attributes( 'text', 'none' );
676 550 ?>
677 551 <span <?php $instance->print_render_attribute_string( 'content-wrapper' ); ?>>
678 552 <?php if ( ! empty( $settings['icon'] ) || ! empty( $settings['selected_icon']['value'] ) ) : ?>
679 - <span <?php $instance->print_render_attribute_string( 'icon' ); ?>>
553 + <span <?php $instance->print_render_attribute_string( 'icon-align' ); ?>>
680 554 <?php if ( $is_new || $migrated ) :
681 555 Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
682 556 else : ?>
683 557 <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i>
@@ -683,11 +557,9 @@
683 557 <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i>
684 558 <?php endif; ?>
685 559 </span>
686 560 <?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; ?>
561 + <span <?php $instance->print_render_attribute_string( 'text' ); ?>><?php $this->print_unescaped_setting( 'text' ); ?></span>
690 562 </span>
691 563 <?php
692 564 }
693 565