自定义 Elementor Widget 控件不接受默认常量

问题描述 投票:0回答:1

我一直在关注 Elementor 关于创建自定义小部件的文档。注册控件时,Elementor 编辑器开始崩溃,永远卡在加载状态。

原代码:

<?php
class Custom_Widget extends \Elementor\Widget_Base 
{
    $this->start_controls_section(
        'content_section',
        [
            'label' => esc_html__( 'Content', 'textdomain' ),
            'tab' => \Elementor\Controls_Manager::TAB_CONTENT, //causes the issue.
        ]
    );
}
?>

我一遍又一遍地检查语法,但不明白为什么。在偶然发现这个支持票之后,我注意到OP使用的是SECTION常量而不是TAB_CONTENT或TAB_STYLE。这解决了我的问题,但我无法使用这两个常量注册任何部分而不会使 Elementor 编辑器崩溃。

新代码:

<?php
class Custom_Widget extends \Elementor\Widget_Base 
{
    $this->start_controls_section(
        'content_section',
        [
            'label' => esc_html__( 'Content', 'textdomain' ),
            'tab' => \Elementor\Controls_Manager::SECTION, //Loads the Elementor editor
        ]
    );
}
?>

TAB_CONTENT 和 TAB_STYLE 都是 默认 Elementor Tabs 常量。那么,为什么它们不适合我?另外,由于 SECTION 常量不是默认常量,因此它不应该引起问题吗?

custom-controls elementor custom-widgets
1个回答
0
投票

我不知道 Elementor 中有类似

Controls_Manager::SECTION
的内容。据我了解文档,控制部分是控件的包装器,而不是控件本身。另外,您在此处粘贴的代码有点断章取义。您是否正确注册了控件?

© www.soinside.com 2019 - 2024. All rights reserved.