traits
5 months ago
accordion.php
2 weeks ago
alert.php
2 weeks ago
audio.php
2 weeks ago
button.php
2 weeks ago
common-base.php
2 weeks ago
common-optimized.php
1 year ago
common.php
1 year ago
counter.php
2 weeks ago
divider.php
2 weeks ago
google-maps.php
2 weeks ago
heading.php
2 weeks ago
html.php
2 weeks ago
icon-box.php
2 weeks ago
icon-list.php
2 weeks ago
icon.php
2 weeks ago
image-box.php
2 weeks ago
image-carousel.php
2 weeks ago
image-gallery.php
2 weeks ago
image.php
2 weeks ago
inner-section.php
2 years ago
menu-anchor.php
2 weeks ago
progress.php
2 weeks ago
rating.php
2 weeks ago
read-more.php
2 weeks ago
shortcode.php
2 weeks ago
sidebar.php
1 year ago
social-icons.php
2 weeks ago
spacer.php
2 weeks ago
star-rating.php
2 weeks ago
tabs.php
2 weeks ago
testimonial.php
2 weeks ago
text-editor.php
2 weeks ago
toggle.php
2 weeks ago
video.php
2 weeks ago
wordpress.php
1 year ago
button.php
164 lines
| 1 | <?php |
| 2 | namespace Elementor; |
| 3 | |
| 4 | use Elementor\Includes\Widgets\Traits\Button_Trait; |
| 5 | use Elementor\Modules\Promotions\Controls\Promotion_Control; |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; // Exit if accessed directly. |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * Elementor button widget. |
| 13 | * |
| 14 | * Elementor widget that displays a button with the ability to control every |
| 15 | * aspect of the button design. |
| 16 | * |
| 17 | * @since 1.0.0 |
| 18 | */ |
| 19 | class Widget_Button extends Widget_Base { |
| 20 | |
| 21 | use Button_Trait; |
| 22 | |
| 23 | /** |
| 24 | * Get widget name. |
| 25 | * |
| 26 | * Retrieve button widget name. |
| 27 | * |
| 28 | * @since 1.0.0 |
| 29 | * @access public |
| 30 | * |
| 31 | * @return string Widget name. |
| 32 | */ |
| 33 | public function get_name() { |
| 34 | return 'button'; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Get widget title. |
| 39 | * |
| 40 | * Retrieve button widget title. |
| 41 | * |
| 42 | * @since 1.0.0 |
| 43 | * @access public |
| 44 | * |
| 45 | * @return string Widget title. |
| 46 | */ |
| 47 | public function get_title() { |
| 48 | return esc_html__( 'Button', 'elementor' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Get widget icon. |
| 53 | * |
| 54 | * Retrieve button widget icon. |
| 55 | * |
| 56 | * @since 1.0.0 |
| 57 | * @access public |
| 58 | * |
| 59 | * @return string Widget icon. |
| 60 | */ |
| 61 | public function get_icon() { |
| 62 | return 'eicon-button'; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get widget categories. |
| 67 | * |
| 68 | * Retrieve the list of categories the button widget belongs to. |
| 69 | * |
| 70 | * Used to determine where to display the widget in the editor. |
| 71 | * |
| 72 | * @since 2.0.0 |
| 73 | * @access public |
| 74 | * |
| 75 | * @return array Widget categories. |
| 76 | */ |
| 77 | public function get_categories() { |
| 78 | return [ 'basic' ]; |
| 79 | } |
| 80 | |
| 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 | /** |
| 90 | * Get widget upsale data. |
| 91 | * |
| 92 | * Retrieve the widget promotion data. |
| 93 | * |
| 94 | * @since 3.19.0 |
| 95 | * @access protected |
| 96 | * |
| 97 | * @return array Widget promotion data. |
| 98 | */ |
| 99 | protected function get_upsale_data() { |
| 100 | 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' ), |
| 108 | ]; |
| 109 | } |
| 110 | |
| 111 | protected function register_controls() { |
| 112 | $this->start_controls_section( |
| 113 | 'section_button', |
| 114 | [ |
| 115 | 'label' => esc_html__( 'Button', 'elementor' ), |
| 116 | ] |
| 117 | ); |
| 118 | |
| 119 | $this->register_button_content_controls(); |
| 120 | |
| 121 | $this->end_controls_section(); |
| 122 | |
| 123 | $this->start_controls_section( |
| 124 | 'section_style', |
| 125 | [ |
| 126 | 'label' => esc_html__( 'Button', 'elementor' ), |
| 127 | 'tab' => Controls_Manager::TAB_STYLE, |
| 128 | ] |
| 129 | ); |
| 130 | |
| 131 | $this->register_button_style_controls(); |
| 132 | |
| 133 | $this->end_controls_section(); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Render button widget output on the frontend. |
| 138 | * |
| 139 | * Written in PHP and used to generate the final HTML. |
| 140 | * |
| 141 | * @since 1.0.0 |
| 142 | * @access protected |
| 143 | */ |
| 144 | protected function render() { |
| 145 | $this->render_button(); |
| 146 | } |
| 147 | |
| 148 | public function render_markdown(): string { |
| 149 | $settings = $this->get_settings_for_display(); |
| 150 | |
| 151 | $text = Utils::html_to_plain_text( $settings['text'] ?? '' ); |
| 152 | |
| 153 | if ( empty( $text ) ) { |
| 154 | return ''; |
| 155 | } |
| 156 | |
| 157 | if ( ! empty( $settings['link']['url'] ) ) { |
| 158 | return '[' . $text . '](' . esc_url( $settings['link']['url'] ) . ')'; |
| 159 | } |
| 160 | |
| 161 | return '**' . $text . '**'; |
| 162 | } |
| 163 | } |
| 164 |