为与列小部件相同的新结构创建元素插件扩展



我想为与列小部件相同的新结构创建元素或插件扩展,这可以允许在其中添加其他小部件。
除了元素或列结构之外,我需要新的不同结构。
我在下面提到了用于创建小部件的 URL,但它可以创建唯一的小部件,而不是部分。

引用网址:- https://developers.elementor.com/creating-an-extension-for-elementor/

您可以创建自己的自定义插件,以扩展现有插件的功能,也可以创建自己的功能。

<?php
class Elementor_Test_Widget extends ElementorWidget_Base {
    public function get_name() {}
    public function get_title() {}
    public function get_icon() {}
    public function get_categories() {}
    protected function _register_controls() {}
    protected function render() {}
    protected function _content_template() {}
}

Widget Name – The get_name() method is a simple one, you just need to return a widget name that will be used in the code.
Widget Title – The get_title() method, which again, is a very simple one, you need to return the widget title that will be displayed as the widget label.
Widget Icon – The get_icon() method, is an optional but recommended method, it lets you set the widget icon. you can use any of the eicon or font-awesome icons, simply return the class name as a string.
Widget Categories – The get_categories method, lets you set the category of the widget, return the category name as a string.
Widget Controls – The _register_controls method lets you define which controls (setting fields) your widget will have.
Render Frontend Output – The render() method, which is where you actually render the code and generate the final HTML on the frontend using PHP.
Render Editor Output – The _content_template() method, is where you render the editor output to generate the live preview using a Backbone JavaScript template.

Widget_Base类有更多的方法可以用来做不同的事情,但现在,这应该足够好了。

小部件示例

<?php
use ElementorWidget_Base;
class Elementor_oEmbed_Widget extends Widget_Base {

public function get_name() {
    return 'oembed';
}

public function get_title() {
    return __( 'oEmbed', 'plugin-name' );
}

public function get_icon() {
    return 'fa fa-code';
}
/* categories. */
public function get_categories() {
    return [ 'general' ];
}

protected function _register_controls() {
    $this->start_controls_section(
        'content_section',
        [
            'label' => __( 'Content', 'plugin-name' ),
            'tab' => ElementorControls_Manager::TAB_CONTENT,
        ]
    );
    $this->add_control(
        'url',
        [
            'label' => __( 'URL to embed', 'plugin-name' ),
            'type' => ElementorControls_Manager::TEXT,
            'input_type' => 'url',
            'placeholder' => __( 'https://your-link.com', 'plugin-name' ),
        ]
    );
    $this->end_controls_section();
}

protected function render() {
    $settings = $this->get_settings_for_display();
    $html = wp_oembed_get( $settings['url'] );
    echo '<div class="oembed-elementor-widget">';
    echo ( $html ) ? $html : $settings['url'];
    echo '</div>';
}
}

最新更新