【问题标题】:How to add fields to custom module in divi builder plugin如何在 divi builder 插件中将字段添加到自定义模块
【发布时间】:2017-12-18 13:16:13
【问题描述】:

我在 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】:

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

    whitelisted_fields 属性中添加您的自定义归档 slug,然后在 get_fields() 函数中添加详细信息。我希望它能解决你的问题。

    【讨论】:

    • 我收到通知,whitelisted_fields 已被弃用。
    • 当前版本的 Divi (3.6) 使用高级字段而不是白名单字段。
    猜你喜欢
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    相关资源
    最近更新 更多