0

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

参考网址:- https://developers.elementor.com/creating-an-extension-for-elementor/

4

1 回答 1

2

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

<?php
class Elementor_Test_Widget extends \Elementor\Widget_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 Elementor\Widget_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' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
    );

    $this->add_control(
        'url',
        [
            'label' => __( 'URL to embed', 'plugin-name' ),
            'type' => \Elementor\Controls_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>';

}

}
于 2019-02-04T12:14:24.237 回答