【问题标题】:Create elementor plugin extension for new structure same as column widget为与列小部件相同的新结构创建 elementor 插件扩展
【发布时间】:2019-01-14 11:08:57
【问题描述】:

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

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

【问题讨论】:

    标签: wordpress plugins elementor


    【解决方案1】:

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

    <?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>';
    
    }
    
    }
    

    【讨论】:

    • 我目前面临类似的问题,但我看不出这如何回答与我相关的部分问题。如此处所述“可以允许在其中添加其他小部件”也许我认为 OP 意味着其他 Elementor 小部件,或者我误解了 wp_oembed_get 在这里的工作原理。但似乎带有 wp_oembed_get 的小部件的这种扩展不允许用户将另一个小部件拖到我自己的插件生成的小部件中。
    • @MostafaElBeheiry 你能解释一下你想买什么吗?您正在创建新的 Elementor 小部件吗?以上代码将帮助您创建自己的 Elementor 小部件,然后您可以像其他 Elementor 小部件一样将其拖放到您的项目中。我已经为 Elementor 创建了自己的扩展插件,请看一下:wordpress.org/plugins/extensions-for-elementor
    • 那我的实现一定有问题,我会用你的链接再试一次,谢谢!重申一下,我制作了一个简单的轮播插件(或 elementor 小部件),我想在其中添加一个内部部分。其他 Elementor 用户可以简单地将其他 Elementor 小部件拖入其中。所以我自己的插件必须能够接受可拖动元素。如果这就是上面的代码所做的,那么我确定我在此过程中错误地实现了它。感谢您的回复!
    • 只是跟进:如果我没有误解这个线程:github.com/elementor/elementor/issues/4070 这似乎在 Elementor 中还不可行,我已经让我的小部件工作了我只是想得到更多可定制。哦,好吧,我会求助于更有创意的解决方法,直到希望我们得到这个功能。
    • 在讨论有关整个网站/页面的问题时完全正确。就像我说的,我制作了自己的自定义小部件,我希望它能够接受元素或内部部分。这不同于在整个页面上创建任何类型的结构。我并没有说我想重新创建内部小部件,我希望能够将它(或任何其他)添加到现有的自定义小部件中。正如上面的问题所示,目前似乎遥不可及。或者至少不容易获得。但无论如何感谢您的提议和见解!
    猜你喜欢
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    相关资源
    最近更新 更多