| @@ -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 | /** |
| @@ -137,34 +136,20 @@ | ||
| 137 | 136 | 'icon_align', |
| 138 | 137 | [ |
| 139 | 138 | 'label' => esc_html__( 'Icon Position', 'elementor' ), |
| 140 | 139 | 'type' => Controls_Manager::CHOOSE, |
| 141 | - 'default' => is_rtl() ? 'row-reverse' : 'row', | |
| 140 | + 'default' => 'left', | |
| 142 | 141 | 'options' => [ |
| 143 | - 'row' => [ | |
| 144 | - 'title' => esc_html__( 'Start', 'elementor' ), | |
| 142 | + 'left' => [ | |
| 143 | + 'title' => esc_html__( 'Left', 'elementor' ), | |
| 145 | 144 | 'icon' => 'eicon-h-align-left', |
| 146 | 145 | ], |
| 147 | - 'row-reverse' => [ | |
| 148 | - 'title' => esc_html__( 'End', 'elementor' ), | |
| 146 | + 'right' => [ | |
| 147 | + 'title' => esc_html__( 'Right', 'elementor' ), | |
| 149 | 148 | 'icon' => 'eicon-h-align-right', |
| 150 | 149 | ], |
| 151 | 150 | ], |
| 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 | - ), | |
| 151 | + 'condition' => array_merge( $args['section_condition'], [ 'selected_icon[value]!' => '' ] ), | |
| 167 | 152 | ] |
| 168 | 153 | ); |
| 169 | 154 | |
| 170 | 155 | $this->add_control( |
| @@ -184,17 +169,12 @@ | ||
| 184 | 169 | 'max' => 5, |
| 185 | 170 | ], |
| 186 | 171 | ], |
| 187 | 172 | 'selectors' => [ |
| 188 | - '{{WRAPPER}} .elementor-button .elementor-button-content-wrapper' => 'gap: {{SIZE}}{{UNIT}};', | |
| 173 | + '{{WRAPPER}} .elementor-button .elementor-align-icon-right' => 'margin-left: {{SIZE}}{{UNIT}};', | |
| 174 | + '{{WRAPPER}} .elementor-button .elementor-align-icon-left' => 'margin-right: {{SIZE}}{{UNIT}};', | |
| 189 | 175 | ], |
| 190 | - 'condition' => array_merge( | |
| 191 | - $args['section_condition'], | |
| 192 | - [ | |
| 193 | - 'text!' => '', | |
| 194 | - 'selected_icon[value]!' => '', | |
| 195 | - ] | |
| 196 | - ), | |
| 176 | + 'condition' => array_merge( $args['section_condition'], [ 'selected_icon[value]!' => '' ] ), | |
| 197 | 177 | ] |
| 198 | 178 | ); |
| 199 | 179 | |
| 200 | 180 | $this->add_control( |
| @@ -210,10 +190,9 @@ | ||
| 210 | 190 | ], |
| 211 | 191 | 'default' => '', |
| 212 | 192 | 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'elementor' ), |
| 213 | 193 | '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' ), | |
| 194 | + 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 | 195 | '<code>', |
| 217 | 196 | '</code>' |
| 218 | 197 | ), |
| 219 | 198 | 'separator' => 'before', |
| @@ -228,11 +207,10 @@ | ||
| 228 | 207 | * @param array $args { |
| 229 | 208 | * An array of values for the button adjustments. |
| 230 | 209 | * |
| 231 | 210 | * @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. | |
| 211 | + * @type string $alignment_default Default alignment for the button. | |
| 212 | + * @type string $alignment_control_prefix_class Prefix class name for the button alignment control. | |
| 235 | 213 | * } |
| 236 | 214 | */ |
| 237 | 215 | protected function register_button_style_controls( $args = [] ) { |
| 238 | 216 | $default_args = [ |
| @@ -238,9 +216,8 @@ | ||
| 238 | 216 | $default_args = [ |
| 239 | 217 | 'section_condition' => [], |
| 240 | 218 | 'alignment_default' => '', |
| 241 | 219 | 'alignment_control_prefix_class' => 'elementor%s-align-', |
| 242 | - 'content_alignment_default' => '', | |
| 243 | 220 | ]; |
| 244 | 221 | |
| 245 | 222 | $args = wp_parse_args( $args, $default_args ); |
| 246 | 223 | |
| @@ -246,26 +223,26 @@ | ||
| 246 | 223 | |
| 247 | 224 | $this->add_responsive_control( |
| 248 | 225 | 'align', |
| 249 | 226 | [ |
| 250 | - 'label' => esc_html__( 'Position', 'elementor' ), | |
| 227 | + 'label' => esc_html__( 'Alignment', 'elementor' ), | |
| 251 | 228 | 'type' => Controls_Manager::CHOOSE, |
| 252 | 229 | 'options' => [ |
| 253 | 230 | 'left' => [ |
| 254 | 231 | 'title' => esc_html__( 'Left', 'elementor' ), |
| 255 | - 'icon' => 'eicon-h-align-left', | |
| 232 | + 'icon' => 'eicon-text-align-left', | |
| 256 | 233 | ], |
| 257 | 234 | 'center' => [ |
| 258 | 235 | 'title' => esc_html__( 'Center', 'elementor' ), |
| 259 | - 'icon' => 'eicon-h-align-center', | |
| 236 | + 'icon' => 'eicon-text-align-center', | |
| 260 | 237 | ], |
| 261 | 238 | 'right' => [ |
| 262 | 239 | 'title' => esc_html__( 'Right', 'elementor' ), |
| 263 | - 'icon' => 'eicon-h-align-right', | |
| 240 | + 'icon' => 'eicon-text-align-right', | |
| 264 | 241 | ], |
| 265 | 242 | 'justify' => [ |
| 266 | - 'title' => esc_html__( 'Stretch', 'elementor' ), | |
| 267 | - 'icon' => 'eicon-h-align-stretch', | |
| 243 | + 'title' => esc_html__( 'Justified', 'elementor' ), | |
| 244 | + 'icon' => 'eicon-text-align-justify', | |
| 268 | 245 | ], |
| 269 | 246 | ], |
| 270 | 247 | 'prefix_class' => $args['alignment_control_prefix_class'], |
| 271 | 248 | 'default' => $args['alignment_default'], |
| @@ -272,40 +249,8 @@ | ||
| 272 | 249 | 'condition' => $args['section_condition'], |
| 273 | 250 | ] |
| 274 | 251 | ); |
| 275 | 252 | |
| 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 | 253 | $this->add_group_control( |
| 309 | 254 | Group_Control_Typography::get_type(), |
| 310 | 255 | [ |
| 311 | 256 | 'name' => 'typography', |
| @@ -371,17 +316,8 @@ | ||
| 371 | 316 | 'condition' => $args['section_condition'], |
| 372 | 317 | ] |
| 373 | 318 | ); |
| 374 | 319 | |
| 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 | 320 | $this->end_controls_tab(); |
| 385 | 321 | |
| 386 | 322 | $this->start_controls_tab( |
| 387 | 323 | 'tab_button_hover', |
| @@ -424,8 +360,11 @@ | ||
| 424 | 360 | 'button_hover_border_color', |
| 425 | 361 | [ |
| 426 | 362 | 'label' => esc_html__( 'Border Color', 'elementor' ), |
| 427 | 363 | 'type' => Controls_Manager::COLOR, |
| 364 | + 'condition' => [ | |
| 365 | + 'border_border!' => '', | |
| 366 | + ], | |
| 428 | 367 | 'selectors' => [ |
| 429 | 368 | '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'border-color: {{VALUE}};', |
| 430 | 369 | ], |
| 431 | 370 | 'condition' => $args['section_condition'], |
| @@ -431,17 +370,8 @@ | ||
| 431 | 370 | 'condition' => $args['section_condition'], |
| 432 | 371 | ] |
| 433 | 372 | ); |
| 434 | 373 | |
| 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 | 374 | $this->add_control( |
| 445 | 375 | 'button_hover_transition_duration', |
| 446 | 376 | [ |
| 447 | 377 | 'label' => esc_html__( 'Transition Duration', 'elementor' ), |
| @@ -491,8 +421,17 @@ | ||
| 491 | 421 | 'condition' => $args['section_condition'], |
| 492 | 422 | ] |
| 493 | 423 | ); |
| 494 | 424 | |
| 425 | + $this->add_group_control( | |
| 426 | + Group_Control_Box_Shadow::get_type(), | |
| 427 | + [ | |
| 428 | + 'name' => 'button_box_shadow', | |
| 429 | + 'selector' => '{{WRAPPER}} .elementor-button', | |
| 430 | + 'condition' => $args['section_condition'], | |
| 431 | + ] | |
| 432 | + ); | |
| 433 | + | |
| 495 | 434 | $this->add_responsive_control( |
| 496 | 435 | 'text_padding', |
| 497 | 436 | [ |
| 498 | 437 | 'label' => esc_html__( 'Padding', 'elementor' ), |
| @@ -516,9 +455,9 @@ | ||
| 516 | 455 | * |
| 517 | 456 | * @since 3.4.0 |
| 518 | 457 | * @access protected |
| 519 | 458 | */ |
| 520 | - protected function render_button( ?Widget_Base $instance = null ) { | |
| 459 | + protected function render_button( Widget_Base $instance = null ) { | |
| 521 | 460 | if ( empty( $instance ) ) { |
| 522 | 461 | $instance = $this; |
| 523 | 462 | } |
| 524 | 463 | |
| @@ -523,14 +462,8 @@ | ||
| 523 | 462 | } |
| 524 | 463 | |
| 525 | 464 | $settings = $instance->get_settings_for_display(); |
| 526 | 465 | |
| 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 | 466 | $instance->add_render_attribute( 'wrapper', 'class', 'elementor-button-wrapper' ); |
| 534 | 467 | |
| 535 | 468 | $instance->add_render_attribute( 'button', 'class', 'elementor-button' ); |
| 536 | 469 | |
| @@ -554,17 +487,13 @@ | ||
| 554 | 487 | if ( ! empty( $settings['hover_animation'] ) ) { |
| 555 | 488 | $instance->add_render_attribute( 'button', 'class', 'elementor-animation-' . $settings['hover_animation'] ); |
| 556 | 489 | } |
| 557 | 490 | ?> |
| 558 | - <?php if ( ! $optimized_markup ) : ?> | |
| 559 | 491 | <div <?php $instance->print_render_attribute_string( 'wrapper' ); ?>> |
| 560 | - <?php endif; ?> | |
| 561 | 492 | <a <?php $instance->print_render_attribute_string( 'button' ); ?>> |
| 562 | 493 | <?php $this->render_text( $instance ); ?> |
| 563 | 494 | </a> |
| 564 | - <?php if ( ! $optimized_markup ) : ?> | |
| 565 | 495 | </div> |
| 566 | - <?php endif; ?> | |
| 567 | 496 | <?php |
| 568 | 497 | } |
| 569 | 498 | |
| 570 | 499 | /** |
| @@ -577,20 +506,14 @@ | ||
| 577 | 506 | */ |
| 578 | 507 | protected function content_template() { |
| 579 | 508 | ?> |
| 580 | 509 | <# |
| 581 | - if ( '' === settings.text && '' === settings.selected_icon.value ) { | |
| 582 | - return; | |
| 583 | - } | |
| 584 | - | |
| 585 | - const optimized_markup = elementorCommon.config.experimentalFeatures.e_optimized_markup; | |
| 586 | - | |
| 587 | 510 | view.addRenderAttribute( 'wrapper', 'class', 'elementor-button-wrapper' ); |
| 588 | 511 | |
| 589 | 512 | view.addRenderAttribute( 'button', 'class', 'elementor-button' ); |
| 590 | 513 | |
| 591 | - if ( '' !== settings.link?.url ) { | |
| 592 | - view.addRenderAttribute( 'button', 'href', elementor.helpers.sanitizeUrl( settings.link?.url ) ); | |
| 514 | + if ( '' !== settings.link.url ) { | |
| 515 | + view.addRenderAttribute( 'button', 'href', settings.link.url ); | |
| 593 | 516 | view.addRenderAttribute( 'button', 'class', 'elementor-button-link' ); |
| 594 | 517 | } else { |
| 595 | 518 | view.addRenderAttribute( 'button', 'role', 'button' ); |
| 596 | 519 | } |
| @@ -606,21 +529,18 @@ | ||
| 606 | 529 | if ( '' !== settings.hover_animation ) { |
| 607 | 530 | view.addRenderAttribute( 'button', 'class', 'elementor-animation-' + settings.hover_animation ); |
| 608 | 531 | } |
| 609 | 532 | |
| 610 | - view.addRenderAttribute( 'icon', 'class', 'elementor-button-icon' ); | |
| 611 | 533 | view.addRenderAttribute( 'text', 'class', 'elementor-button-text' ); |
| 612 | 534 | view.addInlineEditingAttributes( 'text', 'none' ); |
| 613 | 535 | var iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ), |
| 614 | 536 | migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' ); |
| 615 | 537 | #> |
| 616 | - <# if ( ! optimized_markup ) { #> | |
| 617 | 538 | <div {{{ view.getRenderAttributeString( 'wrapper' ) }}}> |
| 618 | - <# } #> | |
| 619 | 539 | <a {{{ view.getRenderAttributeString( 'button' ) }}}> |
| 620 | 540 | <span class="elementor-button-content-wrapper"> |
| 621 | 541 | <# if ( settings.icon || settings.selected_icon ) { #> |
| 622 | - <span {{{ view.getRenderAttributeString( 'icon' ) }}}> | |
| 542 | + <span class="elementor-button-icon elementor-align-icon-{{ settings.icon_align }}"> | |
| 623 | 543 | <# if ( ( migrated || ! settings.icon ) && iconHTML.rendered ) { #> |
| 624 | 544 | {{{ iconHTML.value }}} |
| 625 | 545 | <# } else { #> |
| 626 | 546 | <i class="{{ settings.icon }}" aria-hidden="true"></i> |
| @@ -626,16 +546,12 @@ | ||
| 626 | 546 | <i class="{{ settings.icon }}" aria-hidden="true"></i> |
| 627 | 547 | <# } #> |
| 628 | 548 | </span> |
| 629 | 549 | <# } #> |
| 630 | - <# if ( settings.text ) { #> | |
| 631 | - <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{ settings.text }}</span> | |
| 632 | - <# } #> | |
| 550 | + <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{{ settings.text }}}</span> | |
| 633 | 551 | </span> |
| 634 | 552 | </a> |
| 635 | - <# if ( ! optimized_markup ) { #> | |
| 636 | 553 | </div> |
| 637 | - <# } #> | |
| 638 | 554 | <?php |
| 639 | 555 | } |
| 640 | 556 | |
| 641 | 557 | /** |
| @@ -647,9 +563,9 @@ | ||
| 647 | 563 | * |
| 648 | 564 | * @since 3.4.0 |
| 649 | 565 | * @access protected |
| 650 | 566 | */ |
| 651 | - protected function render_text( ?Widget_Base $instance = null ) { | |
| 567 | + protected function render_text( Widget_Base $instance = null ) { | |
| 652 | 568 | // 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 | 569 | if ( empty( $instance ) ) { |
| 654 | 570 | $instance = $this; |
| 655 | 571 | } |
| @@ -658,14 +574,24 @@ | ||
| 658 | 574 | |
| 659 | 575 | $migrated = isset( $settings['__fa4_migrated']['selected_icon'] ); |
| 660 | 576 | $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed(); |
| 661 | 577 | |
| 578 | + if ( ! $is_new && empty( $settings['icon_align'] ) ) { | |
| 579 | + // @todo: remove when deprecated | |
| 580 | + // added as bc in 2.6 | |
| 581 | + //old default | |
| 582 | + $settings['icon_align'] = $instance->get_settings( 'icon_align' ); | |
| 583 | + } | |
| 584 | + | |
| 662 | 585 | $instance->add_render_attribute( [ |
| 663 | 586 | 'content-wrapper' => [ |
| 664 | 587 | 'class' => 'elementor-button-content-wrapper', |
| 665 | 588 | ], |
| 666 | - 'icon' => [ | |
| 667 | - 'class' => 'elementor-button-icon', | |
| 589 | + 'icon-align' => [ | |
| 590 | + 'class' => [ | |
| 591 | + 'elementor-button-icon', | |
| 592 | + 'elementor-align-icon-' . $settings['icon_align'], | |
| 593 | + ], | |
| 668 | 594 | ], |
| 669 | 595 | 'text' => [ |
| 670 | 596 | 'class' => 'elementor-button-text', |
| 671 | 597 | ], |
| @@ -671,13 +597,13 @@ | ||
| 671 | 597 | ], |
| 672 | 598 | ] ); |
| 673 | 599 | |
| 674 | 600 | // TODO: replace the protected with public |
| 675 | - // $instance->add_inline_editing_attributes( 'text', 'none' ); | |
| 601 | + //$instance->add_inline_editing_attributes( 'text', 'none' ); | |
| 676 | 602 | ?> |
| 677 | 603 | <span <?php $instance->print_render_attribute_string( 'content-wrapper' ); ?>> |
| 678 | 604 | <?php if ( ! empty( $settings['icon'] ) || ! empty( $settings['selected_icon']['value'] ) ) : ?> |
| 679 | - <span <?php $instance->print_render_attribute_string( 'icon' ); ?>> | |
| 605 | + <span <?php $instance->print_render_attribute_string( 'icon-align' ); ?>> | |
| 680 | 606 | <?php if ( $is_new || $migrated ) : |
| 681 | 607 | Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] ); |
| 682 | 608 | else : ?> |
| 683 | 609 | <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i> |
| @@ -683,11 +609,9 @@ | ||
| 683 | 609 | <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i> |
| 684 | 610 | <?php endif; ?> |
| 685 | 611 | </span> |
| 686 | 612 | <?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; ?> | |
| 613 | + <span <?php $instance->print_render_attribute_string( 'text' ); ?>><?php $this->print_unescaped_setting( 'text' ); ?></span> | |
| 690 | 614 | </span> |
| 691 | 615 | <?php |
| 692 | 616 | } |
| 693 | 617 | |