PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.4
Elementor Website Builder – more than just a page builder v3.2.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 +458 -40 4.1.0-dev23.2.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.
@@ -44,9 +42,9 @@
44 42 *
45 43 * @return string Widget title.
46 44 */
47 45 public function get_title() {
48 - return esc_html__( 'Button', 'elementor' );
46 + return __( 'Button', 'elementor' );
49 47 }
50 48
51 49 /**
52 50 * Get widget icon.
@@ -77,60 +75,374 @@
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' => __( 'Extra Small', 'elementor' ),
93 + 'sm' => __( 'Small', 'elementor' ),
94 + 'md' => __( 'Medium', 'elementor' ),
95 + 'lg' => __( 'Large', 'elementor' ),
96 + 'xl' => __( '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 - 'label' => esc_html__( 'Button', 'elementor' ),
112 + 'label' => __( 'Button', 'elementor' ),
116 113 ]
117 114 );
118 115
119 - $this->register_button_content_controls();
116 + $this->add_control(
117 + 'button_type',
118 + [
119 + 'label' => __( 'Type', 'elementor' ),
120 + 'type' => Controls_Manager::SELECT,
121 + 'default' => '',
122 + 'options' => [
123 + '' => __( 'Default', 'elementor' ),
124 + 'info' => __( 'Info', 'elementor' ),
125 + 'success' => __( 'Success', 'elementor' ),
126 + 'warning' => __( 'Warning', 'elementor' ),
127 + 'danger' => __( 'Danger', 'elementor' ),
128 + ],
129 + 'prefix_class' => 'elementor-button-',
130 + ]
131 + );
120 132
133 + $this->add_control(
134 + 'text',
135 + [
136 + 'label' => __( 'Text', 'elementor' ),
137 + 'type' => Controls_Manager::TEXT,
138 + 'dynamic' => [
139 + 'active' => true,
140 + ],
141 + 'default' => __( 'Click here', 'elementor' ),
142 + 'placeholder' => __( 'Click here', 'elementor' ),
143 + ]
144 + );
145 +
146 + $this->add_control(
147 + 'link',
148 + [
149 + 'label' => __( 'Link', 'elementor' ),
150 + 'type' => Controls_Manager::URL,
151 + 'dynamic' => [
152 + 'active' => true,
153 + ],
154 + 'placeholder' => __( 'https://your-link.com', 'elementor' ),
155 + 'default' => [
156 + 'url' => '#',
157 + ],
158 + ]
159 + );
160 +
161 + $this->add_responsive_control(
162 + 'align',
163 + [
164 + 'label' => __( 'Alignment', 'elementor' ),
165 + 'type' => Controls_Manager::CHOOSE,
166 + 'options' => [
167 + 'left' => [
168 + 'title' => __( 'Left', 'elementor' ),
169 + 'icon' => 'eicon-text-align-left',
170 + ],
171 + 'center' => [
172 + 'title' => __( 'Center', 'elementor' ),
173 + 'icon' => 'eicon-text-align-center',
174 + ],
175 + 'right' => [
176 + 'title' => __( 'Right', 'elementor' ),
177 + 'icon' => 'eicon-text-align-right',
178 + ],
179 + 'justify' => [
180 + 'title' => __( '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' => __( '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' => __( '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' => __( 'Icon Position', 'elementor' ),
215 + 'type' => Controls_Manager::SELECT,
216 + 'default' => 'left',
217 + 'options' => [
218 + 'left' => __( 'Before', 'elementor' ),
219 + 'right' => __( 'After', 'elementor' ),
220 + ],
221 + 'condition' => [
222 + 'selected_icon[value]!' => '',
223 + ],
224 + ]
225 + );
226 +
227 + $this->add_control(
228 + 'icon_indent',
229 + [
230 + 'label' => __( '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' => __( 'View', 'elementor' ),
248 + 'type' => Controls_Manager::HIDDEN,
249 + 'default' => 'traditional',
250 + ]
251 + );
252 +
253 + $this->add_control(
254 + 'button_css_id',
255 + [
256 + 'label' => __( 'Button ID', 'elementor' ),
257 + 'type' => Controls_Manager::TEXT,
258 + 'dynamic' => [
259 + 'active' => true,
260 + ],
261 + 'default' => '',
262 + 'title' => __( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'elementor' ),
263 + 'description' => __( 'Please make sure the ID is unique and not used elsewhere on the page this form is displayed. This field allows <code>A-z 0-9</code> & underscore chars without spaces.', 'elementor' ),
264 + 'separator' => 'before',
265 +
266 + ]
267 + );
268 +
121 269 $this->end_controls_section();
122 270
123 271 $this->start_controls_section(
124 272 'section_style',
125 273 [
126 - 'label' => esc_html__( 'Button', 'elementor' ),
274 + 'label' => __( 'Button', 'elementor' ),
127 275 'tab' => Controls_Manager::TAB_STYLE,
128 276 ]
129 277 );
130 278
131 - $this->register_button_style_controls();
279 + $this->add_group_control(
280 + Group_Control_Typography::get_type(),
281 + [
282 + 'name' => 'typography',
283 + 'global' => [
284 + 'default' => Global_Typography::TYPOGRAPHY_ACCENT,
285 + ],
286 + 'selector' => '{{WRAPPER}} .elementor-button',
287 + ]
288 + );
132 289
290 + $this->add_group_control(
291 + Group_Control_Text_Shadow::get_type(),
292 + [
293 + 'name' => 'text_shadow',
294 + 'selector' => '{{WRAPPER}} .elementor-button',
295 + ]
296 + );
297 +
298 + $this->start_controls_tabs( 'tabs_button_style' );
299 +
300 + $this->start_controls_tab(
301 + 'tab_button_normal',
302 + [
303 + 'label' => __( 'Normal', 'elementor' ),
304 + ]
305 + );
306 +
307 + $this->add_control(
308 + 'button_text_color',
309 + [
310 + 'label' => __( 'Text Color', 'elementor' ),
311 + 'type' => Controls_Manager::COLOR,
312 + 'default' => '',
313 + 'selectors' => [
314 + '{{WRAPPER}} .elementor-button' => 'fill: {{VALUE}}; color: {{VALUE}};',
315 + ],
316 + ]
317 + );
318 +
319 + $this->add_group_control(
320 + Group_Control_Background::get_type(),
321 + [
322 + 'name' => 'background',
323 + 'label' => __( 'Background', 'elementor' ),
324 + 'types' => [ 'classic', 'gradient' ],
325 + 'exclude' => [ 'image' ],
326 + 'selector' => '{{WRAPPER}} .elementor-button',
327 + 'fields_options' => [
328 + 'background' => [
329 + 'default' => 'classic',
330 + ],
331 + 'color' => [
332 + 'global' => [
333 + 'default' => Global_Colors::COLOR_ACCENT,
334 + ],
335 + ],
336 + ],
337 + ]
338 + );
339 +
340 + $this->end_controls_tab();
341 +
342 + $this->start_controls_tab(
343 + 'tab_button_hover',
344 + [
345 + 'label' => __( 'Hover', 'elementor' ),
346 + ]
347 + );
348 +
349 + $this->add_control(
350 + 'hover_color',
351 + [
352 + 'label' => __( 'Text Color', 'elementor' ),
353 + 'type' => Controls_Manager::COLOR,
354 + 'selectors' => [
355 + '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'color: {{VALUE}};',
356 + '{{WRAPPER}} .elementor-button:hover svg, {{WRAPPER}} .elementor-button:focus svg' => 'fill: {{VALUE}};',
357 + ],
358 + ]
359 + );
360 +
361 + $this->add_group_control(
362 + Group_Control_Background::get_type(),
363 + [
364 + 'name' => 'button_background_hover',
365 + 'label' => __( 'Background', 'elementor' ),
366 + 'types' => [ 'classic', 'gradient' ],
367 + 'exclude' => [ 'image' ],
368 + 'selector' => '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus',
369 + 'fields_options' => [
370 + 'background' => [
371 + 'default' => 'classic',
372 + ],
373 + ],
374 + ]
375 + );
376 +
377 + $this->add_control(
378 + 'button_hover_border_color',
379 + [
380 + 'label' => __( 'Border Color', 'elementor' ),
381 + 'type' => Controls_Manager::COLOR,
382 + 'condition' => [
383 + 'border_border!' => '',
384 + ],
385 + 'selectors' => [
386 + '{{WRAPPER}} .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'border-color: {{VALUE}};',
387 + ],
388 + ]
389 + );
390 +
391 + $this->add_control(
392 + 'hover_animation',
393 + [
394 + 'label' => __( 'Hover Animation', 'elementor' ),
395 + 'type' => Controls_Manager::HOVER_ANIMATION,
396 + ]
397 + );
398 +
399 + $this->end_controls_tab();
400 +
401 + $this->end_controls_tabs();
402 +
403 + $this->add_group_control(
404 + Group_Control_Border::get_type(),
405 + [
406 + 'name' => 'border',
407 + 'selector' => '{{WRAPPER}} .elementor-button',
408 + 'separator' => 'before',
409 + ]
410 + );
411 +
412 + $this->add_control(
413 + 'border_radius',
414 + [
415 + 'label' => __( 'Border Radius', 'elementor' ),
416 + 'type' => Controls_Manager::DIMENSIONS,
417 + 'size_units' => [ 'px', '%', 'em' ],
418 + 'selectors' => [
419 + '{{WRAPPER}} .elementor-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
420 + ],
421 + ]
422 + );
423 +
424 + $this->add_group_control(
425 + Group_Control_Box_Shadow::get_type(),
426 + [
427 + 'name' => 'button_box_shadow',
428 + 'selector' => '{{WRAPPER}} .elementor-button',
429 + ]
430 + );
431 +
432 + $this->add_responsive_control(
433 + 'text_padding',
434 + [
435 + 'label' => __( 'Padding', 'elementor' ),
436 + 'type' => Controls_Manager::DIMENSIONS,
437 + 'size_units' => [ 'px', 'em', '%' ],
438 + 'selectors' => [
439 + '{{WRAPPER}} .elementor-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
440 + ],
441 + 'separator' => 'before',
442 + ]
443 + );
444 +
133 445 $this->end_controls_section();
134 446 }
135 447
136 448 /**
@@ -141,23 +453,129 @@
141 453 * @since 1.0.0
142 454 * @access protected
143 455 */
144 456 protected function render() {
145 - $this->render_button();
457 + $settings = $this->get_settings_for_display();
458 +
459 + $this->add_render_attribute( 'wrapper', 'class', 'elementor-button-wrapper' );
460 +
461 + if ( ! empty( $settings['link']['url'] ) ) {
462 + $this->add_link_attributes( 'button', $settings['link'] );
463 + $this->add_render_attribute( 'button', 'class', 'elementor-button-link' );
464 + }
465 +
466 + $this->add_render_attribute( 'button', 'class', 'elementor-button' );
467 + $this->add_render_attribute( 'button', 'role', 'button' );
468 +
469 + if ( ! empty( $settings['button_css_id'] ) ) {
470 + $this->add_render_attribute( 'button', 'id', $settings['button_css_id'] );
471 + }
472 +
473 + if ( ! empty( $settings['size'] ) ) {
474 + $this->add_render_attribute( 'button', 'class', 'elementor-size-' . $settings['size'] );
475 + }
476 +
477 + if ( $settings['hover_animation'] ) {
478 + $this->add_render_attribute( 'button', 'class', 'elementor-animation-' . $settings['hover_animation'] );
479 + }
480 +
481 + ?>
482 + <div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>>
483 + <a <?php echo $this->get_render_attribute_string( 'button' ); ?>>
484 + <?php $this->render_text(); ?>
485 + </a>
486 + </div>
487 + <?php
146 488 }
147 489
148 - public function render_markdown(): string {
490 + /**
491 + * Render button widget output in the editor.
492 + *
493 + * Written as a Backbone JavaScript template and used to generate the live preview.
494 + *
495 + * @since 2.9.0
496 + * @access protected
497 + */
498 + protected function content_template() {
499 + ?>
500 + <#
501 + view.addRenderAttribute( 'text', 'class', 'elementor-button-text' );
502 + view.addInlineEditingAttributes( 'text', 'none' );
503 + var iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
504 + migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' );
505 + #>
506 + <div class="elementor-button-wrapper">
507 + <a id="{{ settings.button_css_id }}" class="elementor-button elementor-size-{{ settings.size }} elementor-animation-{{ settings.hover_animation }}" href="{{ settings.link.url }}" role="button">
508 + <span class="elementor-button-content-wrapper">
509 + <# if ( settings.icon || settings.selected_icon ) { #>
510 + <span class="elementor-button-icon elementor-align-icon-{{ settings.icon_align }}">
511 + <# if ( ( migrated || ! settings.icon ) && iconHTML.rendered ) { #>
512 + {{{ iconHTML.value }}}
513 + <# } else { #>
514 + <i class="{{ settings.icon }}" aria-hidden="true"></i>
515 + <# } #>
516 + </span>
517 + <# } #>
518 + <span {{{ view.getRenderAttributeString( 'text' ) }}}>{{{ settings.text }}}</span>
519 + </span>
520 + </a>
521 + </div>
522 + <?php
523 + }
524 +
525 + /**
526 + * Render button text.
527 + *
528 + * Render button widget text.
529 + *
530 + * @since 1.5.0
531 + * @access protected
532 + */
533 + protected function render_text() {
149 534 $settings = $this->get_settings_for_display();
150 535
151 - $text = Utils::html_to_plain_text( $settings['text'] ?? '' );
536 + $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
537 + $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
152 538
153 - if ( empty( $text ) ) {
154 - return '';
539 + if ( ! $is_new && empty( $settings['icon_align'] ) ) {
540 + // @todo: remove when deprecated
541 + // added as bc in 2.6
542 + //old default
543 + $settings['icon_align'] = $this->get_settings( 'icon_align' );
155 544 }
156 545
157 - if ( ! empty( $settings['link']['url'] ) ) {
158 - return '[' . $text . '](' . esc_url( $settings['link']['url'] ) . ')';
159 - }
546 + $this->add_render_attribute( [
547 + 'content-wrapper' => [
548 + 'class' => 'elementor-button-content-wrapper',
549 + ],
550 + 'icon-align' => [
551 + 'class' => [
552 + 'elementor-button-icon',
553 + 'elementor-align-icon-' . $settings['icon_align'],
554 + ],
555 + ],
556 + 'text' => [
557 + 'class' => 'elementor-button-text',
558 + ],
559 + ] );
160 560
161 - return '**' . $text . '**';
561 + $this->add_inline_editing_attributes( 'text', 'none' );
562 + ?>
563 + <span <?php echo $this->get_render_attribute_string( 'content-wrapper' ); ?>>
564 + <?php if ( ! empty( $settings['icon'] ) || ! empty( $settings['selected_icon']['value'] ) ) : ?>
565 + <span <?php echo $this->get_render_attribute_string( 'icon-align' ); ?>>
566 + <?php if ( $is_new || $migrated ) :
567 + Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
568 + else : ?>
569 + <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i>
570 + <?php endif; ?>
571 + </span>
572 + <?php endif; ?>
573 + <span <?php echo $this->get_render_attribute_string( 'text' ); ?>><?php echo $settings['text']; ?></span>
574 + </span>
575 + <?php
576 + }
577 +
578 + public function on_import( $element ) {
579 + return Icons_Manager::on_import_migration( $element, 'icon', 'selected_icon' );
162 580 }
163 581 }