【问题标题】:How to get parent module atts value at it's child module in divi builder?如何在 divi builder 的子模块中获取父模块 atts 值?
【发布时间】:2017-12-22 05:24:19
【问题描述】:

我已经创建了自定义 divi builder 模块及其子模块。现在我需要它的子模块的父 atts 值,但我找不到解决这个问题的方法。 这是我的自定义模块类

父模块类:

class Wb_Custom_Module_Revision extends ET_Builder_Module {

function init () {
    $this->name = __( 'Wb Revision Log', 'wb' );
    $this->slug = 'et_pb_wb_revision';
    $this->fb_support      = true;
    $this->child_slug      = 'et_pb_wb_revision_child';
    $this->child_item_text = esc_html__( 'Revision Item', 'et_builder' );
    $this->whitelisted_fields = array('vertical_divider_line');
    $this->fields_defaults = array(
        'title' => array( 'Revision Log', 'add_default_setting' ),
    );
    $this->main_css_element = '%%order_class%%';
}
function get_fields () {
    $fields = array(
        'vertical_divider_line' => array(
            'label' => __( 'Horizontal line', 'wb' ),
            'type' => 'text',
            'description' => __( 'Leave empty to not display', 'wb' ),
        ),
    );
    return $fields;
}
function shortcode_callback ( $atts, $content = null, $function_name ) {

   //my shortcode function 
    return ;
}
}
new Wb_Custom_Module_Revision;

子模块类:

class Wb_Custom_Module_Revision_Item extends ET_Builder_Module {

function init() {
    $this->name             = esc_html__( 'Revision Item', 'et_builder' );
    $this->slug             = 'et_pb_wb_revision_child';
    $this->fb_support       = true;
    $this->type             = 'child';
    $this->child_title_var  = 'content_new';

function shortcode_callback( $atts, $content = null, $function_name ) {
    //i need here it's parent "vertical_divider_line" field value. 

    return $output;
}
}
new Wb_Custom_Module_Revision_Item;

我需要在其子模块 shortcode_callback 函数中的父模块字段值。 请帮我解决这个问题。 谢谢

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    调用这个类方法可以得到父模块:

    $parent_module = self::get_parent_modules('page')['et_pb_wb_revision'];

    然后就可以得到想要的字段值了:

    $parent_module->shortcode_atts['vertical_divider_line'];

    希望对你有帮助!

    【讨论】:

    • self::get_parent_modules('page')['et_pb_section'] 为我工作!
    • jsx文件呢?如何在 jsx 文件中做同样的事情?
    猜你喜欢
    • 2017-10-05
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2020-12-06
    • 2020-06-02
    • 2020-10-04
    相关资源
    最近更新 更多