dummy plugin
<?php
namespace Elementor;
class My_Widget extends Widget_Base {
public function __construct() {
parent::__construct(
'my-widget',
__('My Widget', 'text-domain'),
array(
'description' => __('A simple widget', 'text-domain'),
'categories' => array('general'),
'icon' => 'fa fa-bell',
)
);
}
public function get_render_template() {
return plugin_dir_path(__FILE__) . 'my-widget-template.php';
}
public function _content_template() {
?>
<div class="my-widget">
<h3>{{{ settings.title }}}</h3>
<p>{{{ settings.content }}}</p>
</div>
<?php
}
protected function _register_controls() {
$this->start_controls_section(
'section_content',
array(
'label' => __('Content', 'text-domain'),
)
);
$this->add_control(
'title',
array(
'label' => __('Title', 'text-domain'),
'type' => Controls_Manager::TEXT,
'default' => __('My Widget Title', 'text-domain'),
'placeholder' => __('Enter title', 'text-domain'),
)
);
$this->add_control(
'content',
array(
'label' => __('Content', 'text-domain'),
'type' => Controls_Manager::TEXTAREA,
'default' => __('My Widget Content', 'text-domain'),
'placeholder' => __('Enter content', 'text-domain'),
)
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$this->add_render_attribute('wrapper', 'class', 'my-widget');
?>
<div <?php echo $this->get_render_attribute_string('wrapper'); ?>>
<h3><?php echo $settings['title']; ?></h3>
<p><?php echo $settings['content']; ?></p>
</div>
<?php
}
}
Plugin::instance()->widgets_manager->register_widget_type( new My_Widget() );