如何在Avada子主题函数中覆盖Fusion Element Container?

时间:2019-05-16 09:43:07

标签: php wordpress

嗨,我正在尝试更改Fusion Builder容器的工作方式。我想添加更多自定义字段,更改显示html和默认变量。 我需要覆盖/plugin/fusion-builder/shorcode/fusion-container.php

我正在使用avada的子主题。覆盖它的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

就在我发布问题之后,我就在GitHub上得到了答案: https://github.com/Theme-Fusion/Fusion-Builder-Sample-Add-On/issues/34

解决方案是将以下代码添加到子模板中的functions.php中:

/**
 * Filter already set maps, add in a new option to container.
 */
function filter_available_element( $fusion_builder_elements ) {
    if ( isset( $fusion_builder_elements['fusion_builder_container'] ) ) {
        $fusion_builder_elements['fusion_builder_container']['params'][] = array(
            'type'        => 'radio_button_set',
            'heading'     => esc_attr__( 'Container Design Mode', 'fusion-builder' ),
            'description' => esc_attr__( 'Controls whether the container should be dark or light.', 'fusion-builder' ),
            'param_name'  => 'container_mode',
            'value'       => array(
                'light' => esc_attr__( 'Light', 'fusion-builder' ),
                'dark'  => esc_attr__( 'Dark', 'fusion-builder' ),
            ),
            'default'     => 'light',
            'group'       => esc_attr__( 'Design', 'fusion-builder' ),
        );
    }
    return $fusion_builder_elements;
}
add_filter( 'fusion_builder_all_elements', 'filter_available_element' );

/**
 * Filter the parameters, check for container_mode and if set add to class parameter.
 */
function filter_container_parameters( $out, $pairs, $atts, $shortcode ) {

    // If set, use it, otherwise set to default.
    $out['container_mode'] = isset( $atts['container_mode'] ) ? $atts['container_mode'] : 'light';

    // Set to class parameter which container already has and uses.
    if ( ! isset( $out['class'] ) || '' === $out['class'] ) {
        $out['class'] = 'my-class-' . $out['container_mode'];
    } else {
        $out['class'] .= ' my-class-' . $out['container_mode'];
    }
    return $out;
}
add_filter( 'shortcode_atts_fusion_builder_container', 'filter_container_parameters', 10, 4 );