2017-12-18 170 views
1

我已經在divi生成器中創建了自定義模塊。下面給出的是代碼:如何在divi builder插件中爲自定義模塊添加字段

function ex_divi_child_theme_setup() { 

    if (class_exists('ET_Builder_Module')) { 

     class ET_Builder_Module_Image2 extends ET_Builder_Module { 
     function init() { 
      $this->name = __('Image_1', 'et_builder'); 
      $this->slug = 'et_pb_image2'; 
      // a whole bunch of php code that defines how the class functions 
     } 
     } 
     $et_builder_module_image2 = new ET_Builder_Module_Image2(); 
     add_shortcode('et_pb_image2', array($et_builder_module_image2, '_shortcode_callback')); 

    } 

} 
add_action('et_builder_ready', 'ex_divi_child_theme_setup'); 

我需要添加字段到這個自定義模塊。我怎麼能做到這一點。

回答

1

如果你想添加自定義模塊中的自定義字段,你必須使用「$這個 - > whitelisted_fields」財產和get_fields()功能。生病給你舉一些例子,如何添加文本字段。

class ET_Builder_Module_Image2 extends ET_Builder_Module { 
    function init() { 
     $this->name = __('Image_1', 'et_builder'); 
     $this->slug = 'et_pb_image2'; 
     // a whole bunch of php code that defines how the class functions 
    } 
$this->whitelisted_fields = array(
     'my_title', 
    ); 
function get_fields() { 
    $fields = array(
     'my_title' => array(
      'label' => __('My Title', 'wb'), 
      'type' => 'text', 
     ), 
    ); 
    return $fields; 
} 

添加自定義歸檔塞在whitelisted_fields然後 propertys在get_fields()功能添加細節。我希望它能解決你的問題。

+0

我試過了,它不適合我。 – Sandra

相關問題