PluginProbe
Elementor Website Builder – more than just a page builder / 3.4.4
Elementor Website Builder – more than just a page builder v3.4.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/widgets/button.php +459 -37 4.2.23.4.4 View file →
@@ -1,14 +1,14 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Includes\Widgets\Traits\Button_Trait;
5 -use Elementor\Modules\Promotions\Controls\Promotion_Control;
6 -
7 4 if ( ! defined( 'ABSPATH' ) ) {
8 5 exit; // Exit if accessed directly.
9 6 }
10 7
8 +use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
9 +use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
10 +
11 11 /**
12 12 * Elementor button widget.
13 13 *
14 14 * Elementor widget that displays a button with the ability to control every
@@ -17,10 +17,8 @@
17 17 * @since 1.0.0
18 18 */
19 19 class Widget_Button extends Widget_Base {
20 20
21 - use Button_Trait;
22 -
23 21 /**
24 22 * Get widget name.
25 23 *
26 24 * Retrieve button widget name.
@@ -77,38 +75,37 @@
77 75 public function get_categories() {
78 76 return [ 'basic' ];
79 77 }
80 78
81 - protected function is_dynamic_content(): bool {
82 - return false;
83 - }
84 -
85 - public function has_widget_inner_wrapper(): bool {
86 - return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
87 - }
88 -
89 79 /**
90 - * Get widget upsale data.
80 + * Get button sizes.
91 81 *
92 - * Retrieve the widget promotion data.
82 + * Retrieve an array of button sizes for the button widget.
93 83 *
94 - * @since 3.19.0
95 - * @access protected
84 + * @since 1.0.0
85 + * @access public
86 + * @static
96 87 *
97 - * @return array Widget promotion data.
88 + * @return array An array containing button sizes.
98 89 */
99 - protected function get_upsale_data() {
90 + public static function get_button_sizes() {
100 91 return [
101 - 'condition' => ! Utils::has_pro(),
102 - 'image' => esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ),
103 - 'image_alt' => esc_attr__( 'Upgrade', 'elementor' ),
104 - 'title' => esc_html__( 'Convert visitors into customers', 'elementor' ),
105 - 'description' => esc_html__( 'Get the Call to Action widget and grow your toolbox with Elementor Pro.', 'elementor' ),
106 - 'upgrade_url' => esc_url( 'https://go.elementor.com/go-pro-button-widget/' ),
107 - 'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ),
92 + 'xs' => esc_html__( 'Extra Small', 'elementor' ),
93 + 'sm' => esc_html__( 'Small', 'elementor' ),
94 + 'md' => esc_html__( 'Medium', 'elementor' ),
95 + 'lg' => esc_html__( 'Large', 'elementor' ),
96 + 'xl' => esc_html__( 'Extra Large', 'elementor' ),
108 97 ];
109 98 }
110 99
100 + /**
101 + * Register button widget controls.
102 + *
103 + * Adds different input fields to allow the user to change and customize the widget settings.
104 + *
105 + * @since 3.1.0
106 + * @access protected
107 + */
111 108 protected function register_controls() {
112 109 $this->start_controls_section(
113 110 'section_button',
114 111 [
@@ -115,10 +112,166 @@
115 112 'label' => esc_html__( 'Button', 'elementor' ),
116 113 ]
117 114 );
118 115
119 - $this->register_button_content_controls();
116 + $this->add_control(
117 + 'button_type',
118 + [
119 + 'label' => esc_html__( 'Type', 'elementor' ),
120 + 'type' => Controls_Manager::SELECT,
121 + 'default' => '',
122 + 'options' => [
123 + '' => esc_html__( 'Default', 'elementor' ),
124 + 'info' => esc_html__( 'Info', 'elementor' ),
125 + 'success' => esc_html__( 'Success', 'elementor' ),
126 + 'warning' => esc_html__( 'Warning', 'elementor' ),
127 + 'danger' => esc_html__( 'Danger', 'elementor' ),
128 + ],
129 + 'prefix_class' => 'elementor-button-',
130 + ]
131 + );
120 132
133 + $this->add_control(
134 + 'text',
135 + [
136 + 'label' => esc_html__( 'Text', 'elementor' ),
137 + 'type' => Controls_Manager::TEXT,
138 + 'dynamic' => [
139 + 'active' => true,
140 + ],
141 + 'default' => esc_html__( 'Click here', 'elementor' ),
142 + 'placeholder' => esc_html__( 'Click here', 'elementor' ),
143 + ]
144 + );
145 +
146 + $this->add_control(
147 + 'link',
148 + [
149 + 'label' => esc_html__( 'Link', 'elementor' ),
150 + 'type' => Controls_Manager::URL,
151 + 'dynamic' => [
152 + 'active' => true,
153 + ],
154 + 'placeholder' => esc_html__( 'https://your-link.com', 'elementor' ),
155 + 'default' => [
156 + 'url' => '#',
157 + ],
158 + ]
159 + );
160 +
161 + $this->add_responsive_control(
162 + 'align',
163 + [
164 + 'label' => esc_html__( 'Alignment', 'elementor' ),
165 + 'type' => Controls_Manager::CHOOSE,
166 + 'options' => [
167 + 'left' => [
168 + 'title' => esc_html__( 'Left', 'elementor' ),
169 + 'icon' => 'eicon-text-align-left',
170 + ],
171 + 'center' => [
172 + 'title' => esc_html__( 'Center', 'elementor' ),
173 + 'icon' => 'eicon-text-align-center',
174 + ],
175 + 'right' => [
176 + 'title' => esc_html__( 'Right', 'elementor' ),
177 + 'icon' => 'eicon-text-align-right',
178 + ],
179 + 'justify' => [
180 + 'title' => esc_html__( 'Justified', 'elementor' ),
181 + 'icon' => 'eicon-text-align-justify',
182 + ],
183 + ],
184 + 'prefix_class' => 'elementor%s-align-',
185 + 'default' => '',
186 + ]
187 + );
188 +
189 + $this->add_control(
190 + 'size',
191 + [
192 + 'label' => esc_html__( 'Size', 'elementor' ),
193 + 'type' => Controls_Manager::SELECT,
194 + 'default' => 'sm',
195 + 'options' => self::get_button_sizes(),
196 + 'style_transfer' => true,
197 + ]
198 + );
199 +
200 + $this->add_control(
201 + 'selected_icon',
202 + [
203 + 'label' => esc_html__( 'Icon', 'elementor' ),
204 + 'type' => Controls_Manager::ICONS,
205 + 'fa4compatibility' => 'icon',
206 + 'skin' => 'inline',
207 + 'label_block' => false,
208 + ]
209 + );
210 +
211 + $this->add_control(
212 + 'icon_align',
213 + [
214 + 'label' => esc_html__( 'Icon Position', 'elementor' ),
215 + 'type' => Controls_Manager::SELECT,
216 + 'default' => 'left',
217 + 'options' => [
218 + 'left' => esc_html__( 'Before', 'elementor' ),
219 + 'right' => esc_html__( 'After', 'elementor' ),
220 + ],
221 + 'condition' => [
222 + 'selected_icon[value]!' => '',
223 + ],
224 + ]
225 + );
226 +
227 + $this->add_control(
228 + 'icon_indent',
229 + [
230 + 'label' => esc_html__( 'Icon Spacing', 'elementor' ),
231 + 'type' => Controls_Manager::SLIDER,
232 + 'range' => [
233 + 'px' => [
234 + 'max' => 50,
235 + ],
236 + ],
237 + 'selectors' => [
238 + '{{WRAPPER}} .elementor-button .elementor-align-icon-right' => 'margin-left: {{SIZE}}{{UNIT}};',
239 + '{{WRAPPER}} .elementor-button .elementor-align-icon-left' => 'margin-right: {{SIZE}}{{UNIT}};',
240 + ],
241 + ]
242 + );
243 +
244 + $this->add_control(
245 + 'view',
246 + [
247 + 'label' => esc_html__( 'View', 'elementor' ),
248 + 'type' => Controls_Manager::HIDDEN,
249 + 'default' => 'traditional',
250 + ]
251 + );
252 +
253 + $this->add_control(
254 + 'button_css_id',
255 + [
256 + 'label' => esc_html__( 'Button ID', 'elementor' ),
257 + 'type' => Controls_Manager::TEXT,
258 + 'dynamic' => [
259 + 'active' => true,
260 + ],
261 + 'default' => '',
262 + 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'elementor' ),
263 + 'description' => sprintf(
264 + /* translators: %1$s Code open tag, %2$s: Code close tag. */
265 + 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' ),
266 + '<code>',
267 + '</code>'
268 + ),
269 + 'separator' => 'before',
270 +
271 + ]
272 + );
273 +
121 274 $this->end_controls_section();
122 275
123 276 $this->start_controls_section(
124 277 'section_style',
@@ -127,10 +280,174 @@
127 280 'tab' => Controls_Manager::TAB_STYLE,
128 281 ]
129 282 );
130 283
131 - $this->register_button_style_controls();
284 + $this->add_group_control(
285 + Group_Control_Typography::get_type(),
286 + [
287 + 'name' => 'typography',
288 + 'global' => [
289 + 'default' => Global_Typography::TYPOGRAPHY_ACCENT,
290 + ],
291 + 'selector' => '{{WRAPPER}} .elementor-button',
292 + ]
293 + );
132 294
295 + $this->add_group_control(
296 + Group_Control_Text_Shadow::get_type(),
297 + [
298 + 'name' => 'text_shadow',
299 + 'selector' => '{{WRAPPER}} .elementor-button',
300 + ]
301 + );
302 +
303 + $this->start_controls_tabs( 'tabs_button_style' );
304 +
305 + $this->start_controls_tab(
306 + 'tab_button_normal',
307 + [
308 + 'label' => esc_html__( 'Normal', 'elementor' ),
309 + ]
310 + );
311 +
312 + $this->add_control(
313 + 'button_text_color',
314 + [
315 + 'label' => esc_html__( 'Text Color', 'elementor' ),
316 + 'type' => Controls_Manager::COLOR,
317 + 'default' => '',
318 + 'selectors' => [
319 + '{{WRAPPER}} .elementor-button' => 'fill: {{VALUE}}; color: {{VALUE}};',
320 + ],
321 + ]
322 + );
323 +
324 + $this->add_group_control(
325 + Group_Control_Background::get_type(),
326 + [
327 + 'name' => 'background',
328 + 'label' => esc_html__( 'Background', 'elementor' ),
329 + 'types' => [ 'classic', 'gradient' ],
330 + 'exclude' => [ 'image' ],
331 + 'selector' => '{{WRAPPER}} .elementor-button',
332 + 'fields_options' => [
333 + 'background' => [
334 + 'default' => 'classic',
335 + ],
336 + 'color' => [
337 + 'global' => [
338 + 'default' => Global_Colors::COLOR_ACCENT,
339 + ],
340 + ],
341 + ],
342 + ]
343 + );
344 +
345 + $this->end_controls_tab();
346 +
347 + $this->start_controls_tab(
348 + 'tab_button_hover',
349 + [
350 + 'label' => esc_html__( 'Hover', 'elementor' ),
351 + ]
352 + );
353 +
354 + $this->add_control(
355 + 'hover_color',
356 + [
357 + 'label' => esc_html__( 'Text Color', 'elementor' ),
358 + 'type' => Controls_Manager::COLOR,
359 + 'selectors' => [
360 + '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'color: {{VALUE}};',
361 + '{{WRAPPER}} .elementor-button:hover svg, {{WRAPPER}} .elementor-button:focus svg' => 'fill: {{VALUE}};',
362 + ],
363 + ]
364 + );
365 +
366 + $this->add_group_control(
367 + Group_Control_Background::get_type(),
368 + [
369 + 'name' => 'button_background_hover',
370 + 'label' => esc_html__( 'Background', 'elementor' ),
371 + 'types' => [ 'classic', 'gradient' ],
372 + 'exclude' => [ 'image' ],
373 + 'selector' => '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus',
374 + 'fields_options' => [
375 + 'background' => [
376 + 'default' => 'classic',
377 + ],
378 + ],
379 + ]
380 + );
381 +
382 + $this->add_control(
383 + 'button_hover_border_color',
384 + [
385 + 'label' => esc_html__( 'Border Color', 'elementor' ),
386 + 'type' => Controls_Manager::COLOR,
387 + 'condition' => [
388 + 'border_border!' => '',
389 + ],
390 + 'selectors' => [
391 + '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'border-color: {{VALUE}};',
392 + ],
393 + ]
394 + );
395 +
396 + $this->add_control(
397 + 'hover_animation',
398 + [
399 + 'label' => esc_html__( 'Hover Animation', 'elementor' ),
400 + 'type' => Controls_Manager::HOVER_ANIMATION,
401 + ]
402 + );
403 +
404 + $this->end_controls_tab();
405 +
406 + $this->end_controls_tabs();
407 +
408 + $this->add_group_control(
409 + Group_Control_Border::get_type(),
410 + [
411 + 'name' => 'border',
412 + 'selector' => '{{WRAPPER}} .elementor-button',
413 + 'separator' => 'before',
414 + ]
415 + );
416 +
417 + $this->add_control(
418 + 'border_radius',
419 + [
420 + 'label' => esc_html__( 'Border Radius', 'elementor' ),
421 + 'type' => Controls_Manager::DIMENSIONS,
422 + 'size_units' => [ 'px', '%', 'em' ],
423 + 'selectors' => [
424 + '{{WRAPPER}} .elementor-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
425 + ],
426 + ]
427 + );
428 +
429 + $this->add_group_control(
430 + Group_Control_Box_Shadow::get_type(),
431 + [
432 + 'name' => 'button_box_shadow',
433 + 'selector' => '{{WRAPPER}} .elementor-button',
434 + ]
435 + );
436 +
437 + $this->add_responsive_control(
438 + 'text_padding',
439 + [
440 + 'label' => esc_html__( 'Padding', 'elementor' ),
441 + 'type' => Controls_Manager::DIMENSIONS,
442 + 'size_units' => [ 'px', 'em', '%' ],
443 + 'selectors' => [
444 + '{{WRAPPER}} .elementor-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
445 + ],
446 + 'separator' => 'before',
447 + ]
448 + );
449 +
133 450 $this->end_controls_section();
134 451 }
135 452
136 453 /**
@@ -141,23 +458,128 @@
141 458 * @since 1.0.0
142 459 * @access protected
143 460 */
144 461 protected function render() {
145 - $this->render_button();
462 + $settings = $this->get_settings_for_display();
463 +
464 + $this->add_render_attribute( 'wrapper', 'class', 'elementor-button-wrapper' );
465 +
466 + if ( ! empty( $settings['link']['url'] ) ) {
467 + $this->add_link_attributes( 'button', $settings['link'] );
468 + $this->add_render_attribute( 'button', 'class', 'elementor-button-link' );
469 + }
470 +
471 + $this->add_render_attribute( 'button', 'class', 'elementor-button' );
472 + $this->add_render_attribute( 'button', 'role', 'button' );
473 +
474 + if ( ! empty( $settings['button_css_id'] ) ) {
475 + $this->add_render_attribute( 'button', 'id', $settings['button_css_id'] );
476 + }
477 +
478 + if ( ! empty( $settings['size'] ) ) {
479 + $this->add_render_attribute( 'button', 'class', 'elementor-size-' . $settings['size'] );
480 + }
481 +
482 + if ( $settings['hover_animation'] ) {
483 + $this->add_render_attribute( 'button', 'class', 'elementor-animation-' . $settings['hover_animation'] );
484 + }
485 + ?>
486 + <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
487 + <a <?php $this->print_render_attribute_string( 'button' ); ?>>
488 + <?php $this->render_text(); ?>
489 + </a>
490 + </div>
491 + <?php
146 492 }
147 493
148 - public function render_markdown(): string {
494 + /**
495 + * Render button widget output in the editor.
496 + *
497 + * Written as a Backbone JavaScript template and used to generate the live preview.
498 + *
499 + * @since 2.9.0
500 + * @access protected
501 + */
502 + protected function content_template() {
503 + ?>
504 + <#
505 + view.addRenderAttribute( 'text', 'class', 'elementor-button-text' );
506 + view.addInlineEditingAttributes( 'text', 'none' );
507 + var iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
508 + migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' );
509 + #>
510 + <div class="elementor-button-wrapper">
511 + <a id="{{ settings.button_css_id }}" class="elementor-button elementor-size-{{ settings.size }} elementor-animation-{{ settings.hover_animation }}" href="{{ settings.link.url }}" role="button">
512 + <span class="elementor-button-content-wrapper">
513 + <# if ( settings.icon || settings.selected_icon ) { #>
514 + <span class="elementor-button-icon elementor-align-icon-{{ settings.icon_align }}">
515 + <# if ( ( migrated || ! settings.icon ) && iconHTML.rendered ) { #>
516 + {{{ iconHTML.value }}}
517 + <# } else { #>
518 + <i class="{{ settings.icon }}" aria-hidden="true"></i>
519 + <# } #>
520 + </span>
521 + <# } #>
522 + <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{{ settings.text }}}</span>
523 + </span>
524 + </a>
525 + </div>
526 + <?php
527 + }
528 +
529 + /**
530 + * Render button text.
531 + *
532 + * Render button widget text.
533 + *
534 + * @since 1.5.0
535 + * @access protected
536 + */
537 + protected function render_text() {
149 538 $settings = $this->get_settings_for_display();
150 539
151 - $text = Utils::html_to_plain_text( $settings['text'] ?? '' );
540 + $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
541 + $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
152 542
153 - if ( empty( $text ) ) {
154 - return '';
543 + if ( ! $is_new && empty( $settings['icon_align'] ) ) {
544 + // @todo: remove when deprecated
545 + // added as bc in 2.6
546 + //old default
547 + $settings['icon_align'] = $this->get_settings( 'icon_align' );
155 548 }
156 549
157 - if ( ! empty( $settings['link']['url'] ) ) {
158 - return '[' . $text . '](' . esc_url( $settings['link']['url'] ) . ')';
159 - }
550 + $this->add_render_attribute( [
551 + 'content-wrapper' => [
552 + 'class' => 'elementor-button-content-wrapper',
553 + ],
554 + 'icon-align' => [
555 + 'class' => [
556 + 'elementor-button-icon',
557 + 'elementor-align-icon-' . $settings['icon_align'],
558 + ],
559 + ],
560 + 'text' => [
561 + 'class' => 'elementor-button-text',
562 + ],
563 + ] );
160 564
161 - return '**' . $text . '**';
565 + $this->add_inline_editing_attributes( 'text', 'none' );
566 + ?>
567 + <span <?php $this->print_render_attribute_string( 'content-wrapper' ); ?>>
568 + <?php if ( ! empty( $settings['icon'] ) || ! empty( $settings['selected_icon']['value'] ) ) : ?>
569 + <span <?php $this->print_render_attribute_string( 'icon-align' ); ?>>
570 + <?php if ( $is_new || $migrated ) :
571 + Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
572 + else : ?>
573 + <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i>
574 + <?php endif; ?>
575 + </span>
576 + <?php endif; ?>
577 + <span <?php $this->print_render_attribute_string( 'text' ); ?>><?php $this->print_unescaped_setting( 'text' ); ?></span>
578 + </span>
579 + <?php
580 + }
581 +
582 + public function on_import( $element ) {
583 + return Icons_Manager::on_import_migration( $element, 'icon', 'selected_icon' );
162 584 }
163 585 }