Files
beep/includes/class-elementor-widget.php
T

129 lines
3.5 KiB
PHP
Executable File

<?php
/**
* Beep Elementor Widget
* Drag-and-drop Elementor widget for the Beep feed.
*/
if (!defined('ABSPATH')) {
exit;
}
// Beep works fine without Elementor: this file is only loaded from the
// 'elementor/widgets/register' hook, and bails unless Elementor is present.
if (!class_exists('\Elementor\Widget_Base')) {
return;
}
class Beep_Elementor_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'beep-feed';
}
public function get_title() {
return 'Beep Feed';
}
public function get_icon() {
return 'eicon-social-icons';
}
public function get_categories() {
return ['general'];
}
protected function register_controls() {
$this->start_controls_section(
'section_feed',
['label' => 'Feed Settings']
);
$this->add_control(
'header',
[
'label' => 'Header Title',
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Beep',
'description' => 'Text shown in the feed header. Leave empty to show the wordmark logo.',
]
);
$this->add_control(
'show_wordmark',
[
'label' => 'Show Wordmark Logo',
'type' => \Elementor\Controls_Manager::SWITCHER,
'default' => 'yes',
]
);
$this->add_control(
'sort',
[
'label' => 'Default Sort',
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'latest',
'options' => [
'latest' => 'Latest First',
'top' => 'Top / Most Liked',
],
]
);
$this->add_control(
'limit',
[
'label' => 'Posts Per Page',
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 100,
'default' => 20,
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_style',
['label' => 'Appearance']
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'feed_typography',
'label' => 'Feed Typography',
'selector' => '{{WRAPPER}} .beep-feed',
]
);
$this->add_control(
'card_radius',
[
'label' => 'Card Border Radius',
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => ['px'],
'range' => ['px' => ['min' => 0, 'max' => 32]],
'default' => ['unit' => 'px', 'size' => 0],
'selectors' => [
'{{WRAPPER}} .beep-post' => 'border-radius: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$atts = [
'header' => $settings['header'] ?: 'Beep',
'show_wordmark' => $settings['show_wordmark'] ? '1' : '0',
'sort' => $settings['sort'],
'limit' => (int) $settings['limit'],
];
echo Beep_Shortcode::render_feed($atts);
}
}