File: /mnt/data/dreamsrent-wp/wp-content/plugins/dreamsrent-widgets/widgets/class-btn_action.php
<?php
namespace Dreamsrentelementor\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Elementor Hello World
*
* Elementor widget for hello world.
*
* @since 1.0.0
*/
class DSR_btn_action extends Widget_Base {
/**
* Retrieve the widget name.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'dreamsrent_elementor_btn_action';
}
/**
* Retrieve the widget title.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return __( 'DR Button Action', 'dreamsrent_elementor' );
}
/**
* Retrieve the widget icon.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'eicon-posts-ticker';
}
/**
* Retrieve the list of categories the widget belongs to.
*
* Used to determine where to display the widget in the editor.
*
* Note that currently Elementor supports only one category.
* When multiple categories passed, Elementor uses the first one.
*
* @since 1.0.0
*
* @access public
*
* @return array Widget categories.
*/
public function get_categories() {
return [ 'dreamsrentelemetortheme' ];
}
/**
* Retrieve the list of scripts the widget depended on.
*
* Used to set scripts dependencies required to run the widget.
*
* @since 1.0.0
*
* @access public
*
* @return array Widget scripts dependencies.
*/
// public function get_script_depends() {
// return [ 'dreamsrent_elementor' ];
// }
/**
* Register the widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
*
* @access protected
*/
protected function register_controls() {
$this->start_controls_section(
'section_content',
[
'label' => __( 'Content', 'dreamsrent_elementor' ),
]
);
$this->add_control(
'btn_text',
[
'label' => __( 'Button Text', 'dreamsrent_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => __( 'Go to all Cars', 'dreamsrent_elementor' ),
]
);
$this->add_control(
'website_link',
[
'label' => __( 'Link','dreamsrent_elementor' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => __( 'https://your-link.com', 'dreamsrent_elementor' ),
'show_external' => true,
'default' => [
'url' => '',
'is_external' => true,
'nofollow' => true,
],
]
);
$this->add_control(
'style',
[
'label' => __( 'Style', 'dreamsrent_elementor' ),
'type' => Controls_Manager::SELECT,
'default' => 'center',
'options' => [
'center' => __( 'Center', 'dreamsrent_elementor' ),
],
]
);
$this->add_control(
'class',
[
'label' => __( 'Class', 'dreamsrent_elementor' ),
'type' => Controls_Manager::TEXT,
]
);
$this->end_controls_section();
// Style tab: Button
$this->start_controls_section(
'btn_action_style_section',
[
'label' => __( 'Button', 'dreamsrent_elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'btn_action_bg_color',
[
'label' => __( 'Background Color', 'dreamsrent_elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .view-all .btn-view' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'btn_action_text_color',
[
'label' => __( 'Text Color', 'dreamsrent_elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .view-all .btn-view' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'btn_action_typography',
'label' => __( 'Typography', 'dreamsrent_elementor' ),
'selector' => '{{WRAPPER}} .view-all .btn-view',
]
);
$this->end_controls_section();
}
/**
* Render the widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
*
* @access protected
*/
protected function render() {
$settings = $this->get_settings();
$target = $settings['website_link']['is_external'] ? ' target="_blank"' : '';
$nofollow = $settings['website_link']['nofollow'] ? ' rel="nofollow"' : '';
if(!empty($settings['website_link']['url'])){
$full_url = $settings['website_link']['url'];
} else {
$full_url = '';
}
?>
<div class="view-all text-center aos-init aos-animate" data-aos="fade-down">
<a href="<?php echo $full_url; ?>" <?php echo $target; ?> <?php echo $nofollow; ?> class="btn btn-view d-inline-flex align-items-center"><?php echo $settings['btn_text']; ?> <span><i class="feather-arrow-right ms-2"></i></span></a>
</div>
<?php
}
}