File "room-widget.php"
Full Path: /home/romayxjt/public_html/wp-content/plugins/mphb-elementor/widgets/room-widget.php
File size: 6.41 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace mphbe\widgets;
use \Elementor\Controls_Manager;
class RoomWidget extends AbstractGalleryWidget
{
public function get_name()
{
return 'mphbe-room';
}
public function get_title()
{
return __('Single Accommodation', 'mphb-elementor');
}
public function get_icon()
{
// Elementor icon class ( https://pojome.github.io/elementor-icons/ ) or
// Font Awesome icon class ( https://fontawesome.com/ ), like:
return 'eicon-image-box';
}
/**
* Adds different input fields to allow the user to change and customize the
* widget settings.
*/
protected function register_controls()
{
$this->start_controls_section('section_parameters', array(
'label' => __('Parameters', 'mphb-elementor')
));
// "id" required, but it will cause Backbone error "A "url" property or function must be specified"
$this->add_control('type_id', array(
'type' => Controls_Manager::TEXT,
'label' => __('ID', 'mphb-elementor'),
'description' => __('ID of accommodation type to display.', 'mphb-elementor'),
'default' => ''
));
$this->add_control('title', array(
'type' => Controls_Manager::SELECT,
'label' => __('Title', 'mphb-elementor'),
'description' => __('Whether to display title of the accommodation type.', 'mphb-elementor'),
'default' => 'true',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('featured_image', array(
'type' => Controls_Manager::SELECT,
'label' => __('Featured image', 'mphb-elementor'),
'description' => __('Whether to display featured image of the accommodation type.', 'mphb-elementor'),
'default' => 'true',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('gallery', array(
'type' => Controls_Manager::SELECT,
'label' => __('Gallery', 'mphb-elementor'),
'description' => __('Whether to display gallery of the accommodation type.', 'mphb-elementor'),
'default' => 'true',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('excerpt', array(
'type' => Controls_Manager::SELECT,
'label' => __('Excerpt', 'mphb-elementor'),
'description' => __('Whether to display excerpt (short description) of the accommodation type.', 'mphb-elementor'),
'default' => 'true',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('details', array(
'type' => Controls_Manager::SELECT,
'label' => __('Details', 'mphb-elementor'),
'description' => __('Whether to display details of the accommodation type.', 'mphb-elementor'),
'default' => 'true',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('price', array(
'type' => Controls_Manager::SELECT,
'label' => __('Price', 'mphb-elementor'),
'description' => __('Whether to display price of the accommodation type.', 'mphb-elementor'),
'default' => 'true',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('view_button', array(
'type' => Controls_Manager::SELECT,
'label' => __('View button', 'mphb-elementor'),
'description' => __('Whether to display "View Details" button with the link to accommodation type.', 'mphb-elementor'),
'default' => 'false',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('book_button', array(
'type' => Controls_Manager::SELECT,
'label' => __('Book Button', 'mphb-elementor'),
'description' => __('Whether to display "Book" button.', 'mphb-elementor'),
'default' => 'true',
'options' => array(
'true' => __('Yes', 'mphb-elementor'),
'false' => __('No', 'mphb-elementor')
)
));
$this->add_control('class', array(
'type' => Controls_Manager::TEXT,
'label' => __('Class', 'mphb-elementor'),
'description' => __('Custom CSS class for shortcode wrapper.', 'mphb-elementor'),
'default' => ''
));
$this->end_controls_section();
}
/**
* Render the widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*/
protected function render()
{
$atts = $this->get_settings();
$atts['id'] = 0;
if(!empty($atts['type_id'])){
$atts['id'] = $atts['type_id'];
}
if(empty($atts['type_id']) && is_singular(MPHB()->postTypes()->roomType()->getPostType())){
$atts['id'] = MPHB()->getCurrentRoomType()->getId();
}
do_action('mphbe_before_room_widget_render', $atts);
$shortcode = MPHB()->getShortcodes()->getRoom();
echo $shortcode->render($atts, null, $shortcode->getName()); // phpcs:ignore
parent::render();
do_action('mphbe_after_room_widget_render', $atts);
}
}