Wordpress Divi自定义模块可视化编辑器错误

时间:2018-04-04 18:32:14

标签: wordpress wordpress-theming visual-editor

我正在开发一个自定义Divi模块,我的 fb_support 我的模块加载有问题,除了在可视化编辑器中工作完美。当我将变量 $ this-> fb_support = true 时,我的模块会在可视化编辑器中消失并出现此JavaScript错误。

bundle.js?ver=3.0.106:formatted:1422 Uncaught TypeError: Cannot read property 'lockedParent' of undefined
   at A (bundle.js?ver=3.0.106:formatted:1422)
   at Object.ID_2 (bundle.js?ver=3.0.106:formatted:3571)
   at e._invokeCallback (bundle.js?ver=3.0.106:formatted:35300)
   at e.dispatch (bundle.js?ver=3.0.106:formatted:35288)
   at Object.moduleActive (bundle.js?ver=3.0.106:formatted:7203)
   at t.value (bundle.js?ver=3.0.106:formatted:8759)
   at Object.l (bundle.js?ver=3.0.106:formatted:24713)
   at Object.invokeGuardedCallback (bundle.js?ver=3.0.106:formatted:28497)
   at Object.invokeGuardedCallbackAndCatchFirstError (bundle.js?ver=3.0.106:formatted:28500)
   at h (bundle.js?ver=3.0.106:formatted:24781)

我认为这个错误是因为我没有在JavaScript部分注册我的插件。存在任何方法来做到这一点?这是正确的方法吗?

以下是我的插件的代码:

class Price_Manager extends ET_Builder_Module
{

    function init ()
    {
        $this->name = 'Price Manager;
        $this->slug = 'et_pb_prices';
        $this->fb_support = true;
        $this->whitelisted_fields = array(
            'widget_title',
            'widget_type',
            'admin_label',
            'module_id',
            'module_class',
        );
        $this->main_css_element = '%%order_class%%';
        $this->advanced_options = array(
            'custom_margin_padding' => array(
                'css' => array(
                    'important' => 'all',
                ),
            ),
            'filters' => array(),
        );
    }
    function get_fields ()
    {
        $fields = array(
            'widget_title' => array(
                'label' => 'Title',
                'type' => 'text',
                'option_category' => 'basic_option',
                'description' => 'This is your widget title',
            ),
            'widget_type' => array(
                'label' => 'Type of Widget',
                'type' => 'select',
                'option_category' => 'basic_option',
                'options' => array(
                    'company' => 'Company',
                    'residential' => 'Residential'
                ),
                'description' => 'Here you can choose the type of widget.',
            ),
            'admin_label' => array(
                'label' => 'Admin Label',
                'type' => 'text',
                'description' => 'This will change the label of the module in the builder for easy identification.',
            ),
            'module_id' => array(
                'label' => 'CSS ID',
                'type' => 'text',
                'option_category' => 'configuration',
                'tab_slug' => 'custom_css',
                'option_class' => 'et_pb_custom_css_regular',
            ),
            'module_class' => array(
                'label' => 'CSS Class',
                'type' => 'text',
                'option_category' => 'configuration',
                'tab_slug' => 'custom_css',
                'option_class' => 'et_pb_custom_css_regular',
            ),
        );

        return $fields;
    }
    function shortcode_callback ($atts, $content = null, $function_name)
    {
        $module_id = $this->shortcode_atts['module_id'];
        $module_class = $this->shortcode_atts['module_class'];
        $widget_title = $this->shortcode_atts['widget_title'];
        $widget_type = $this->shortcode_atts['widget_type'];

        $module_class = ET_Builder_Element::add_module_order_class($module_class, $function_name);
        $module_id = '' !== $module_id ? sprintf('id="%s"', esc_attr($module_id)) : '';
        $module_class = '' !== $module_class ? sprintf('%s', esc_attr($module_class)) : '';

        $content = 'My title: ' . $widget_title; // TODO: Fetch the item from DB and prepare HTML for output.
        $content .= '<br />';
        $content .= 'My type of widget: ' . $widget_type;

        $output = sprintf(
            '<div class="et_pb_prices_module_wrapper et_pb_module">
                                <div %1$s class="et_pb_prices%2$s et_pb_module">%3$s</div>
                            </div>',
            $module_id,
            $module_class,
            $content
        );
        return $output;
    }

}

new Price_Manager();

感谢。

0 个答案:

没有答案