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

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

108 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 /**
16 * @inheritDoc
17 */
18 public function get_name() {
19 return 'admin-button';
20 }
21
22 public function print_button() {
23 $options = $this->get_options();
24
25 if ( empty( $options['text'] ) ) {
26 return;
27 }
28
29 $html_tag = ! empty( $options['url'] ) ? 'a' : 'button';
30 $before = '';
31 $icon = '';
32 $attributes = [];
33
34 if ( ! empty( $options['icon'] ) ) {
35 $icon = '<i class="' . esc_attr( $options['icon'] ) . '"></i>';
36 }
37
38 $classes = $options['classes'];
39
40 $default_classes = $this->get_default_options( 'classes' );
41
42 $classes = array_merge( $classes, $default_classes );
43
44 if ( ! empty( $options['type'] ) ) {
45 $classes[] = 'e-button--' . $options['type'];
46 }
47
48 if ( ! empty( $options['variant'] ) ) {
49 $classes[] = 'e-button--' . $options['variant'];
50 }
51
52 if ( ! empty( $options['before'] ) ) {
53 $before = '<span>' . wp_kses_post( $options['before'] ) . '</span>';
54 }
55
56 if ( ! empty( $options['url'] ) ) {
57 $attributes['href'] = $options['url'];
58 if ( $options['new_tab'] ) {
59 $attributes['target'] = '_blank';
60 }
61 }
62
63 $attributes['class'] = $classes;
64
65 $html = $before . '<' . $html_tag . ' ' . Utils::render_html_attributes( $attributes ) . '>';
66 $html .= $icon;
67 $html .= '<span>' . sanitize_text_field( $options['text'] ) . '</span>';
68 $html .= '</' . $html_tag . '>';
69
70 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
71 }
72
73 /**
74 * @param string $option Optional default is null.
75 * @return array|mixed
76 */
77 private function get_options( $option = null ) {
78 return $this->get_items( $this->options, $option );
79 }
80
81 /**
82 * @param null $option
83 * @return array
84 */
85 private function get_default_options( $option = null ) {
86 $default_options = [
87 'classes' => [ 'e-button' ],
88 'icon' => '',
89 'new_tab' => false,
90 'text' => '',
91 'type' => '',
92 'url' => '',
93 'variant' => '',
94 'before' => '',
95 ];
96
97 if ( null !== $option && -1 !== in_array( $option, $default_options, true ) ) {
98 return $default_options[ $option ];
99 }
100
101 return $default_options;
102 }
103
104 public function __construct( array $options ) {
105 $this->options = $this->merge_properties( $this->get_default_options(), $options );
106 }
107 }
108