PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.0-dev3
Elementor Website Builder – more than just a page builder v3.19.0-dev3
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
elementor / core / admin / ui / components / button.php

button.php in Elementor Website Builder – more than just a page builder 3.19.0-dev3, at core/admin/ui/components/button.php

107 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Admin\UI\Components;
3
4 use Elementor\Core\Base\Base_Object;
5 use Elementor\Utils;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Button extends Base_Object {
12
13 private $options;
14 /**
15 * @inheritDoc
16 */
17 public function get_name() {
18 return 'admin-button';
19 }
20
21 public function print_button() {
22 $options = $this->get_options();
23
24 if ( empty( $options['text'] ) ) {
25 return;
26 }
27
28 $html_tag = ! empty( $options['url'] ) ? 'a' : 'button';
29 $before = '';
30 $icon = '';
31 $attributes = [];
32
33 if ( ! empty( $options['icon'] ) ) {
34 $icon = '<i class="' . esc_attr( $options['icon'] ) . '"></i>';
35 }
36
37 $classes = $options['classes'];
38
39 $default_classes = $this->get_default_options( 'classes' );
40
41 $classes = array_merge( $classes, $default_classes );
42
43 if ( ! empty( $options['type'] ) ) {
44 $classes[] = 'e-button--' . $options['type'];
45 }
46
47 if ( ! empty( $options['variant'] ) ) {
48 $classes[] = 'e-button--' . $options['variant'];
49 }
50
51 if ( ! empty( $options['before'] ) ) {
52 $before = '<span>' . wp_kses_post( $options['before'] ) . '</span>';
53 }
54
55 if ( ! empty( $options['url'] ) ) {
56 $attributes['href'] = $options['url'];
57 if ( $options['new_tab'] ) {
58 $attributes['target'] = '_blank';
59 }
60 }
61
62 $attributes['class'] = $classes;
63
64 $html = $before . '<' . $html_tag . ' ' . Utils::render_html_attributes( $attributes ) . '>';
65 $html .= $icon;
66 $html .= '<span>' . sanitize_text_field( $options['text'] ) . '</span>';
67 $html .= '</' . $html_tag . '>';
68
69 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
70 }
71
72 /**
73 * @param string $option Optional default is null
74 * @return array|mixed
75 */
76 private function get_options( $option = null ) {
77 return $this->get_items( $this->options, $option );
78 }
79
80 /**
81 * @param null $option
82 * @return array
83 */
84 private function get_default_options( $option = null ) {
85 $default_options = [
86 'classes' => [ 'e-button' ],
87 'icon' => '',
88 'new_tab' => false,
89 'text' => '',
90 'type' => '',
91 'url' => '',
92 'variant' => '',
93 'before' => '',
94 ];
95
96 if ( null !== $option && -1 !== in_array( $option, $default_options ) ) {
97 return $default_options[ $option ];
98 }
99
100 return $default_options;
101 }
102
103 public function __construct( array $options ) {
104 $this->options = $this->merge_properties( $this->get_default_options(), $options );
105 }
106 }
107