如何在divi builder插件中向自定义模块添加字段

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

我在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');

我需要向这个自定义模块添加字段。我怎么能实现这一点。

php wordpress plugins
1个回答
3
投票

如果要在自定义模块中添加自定义字段,则必须使用“$ this-> 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;
}

在白名单字段属性中添加自定义字段slug,然后在get_fields()函数中添加详细信息。我希望它能解决你的问题。

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