Visual Composer; 自定义元素不会加载textarea_html /'content'

Ann*_*tor 2 wordpress

目前正在使用WordPress 4.4.2,我正在开发一些自定义的Visual Composer元素.

然而,似乎(但是),每当我想使用textarea_html参数时(所以最终用户可以使用wysiwyg编辑器)我在渲染模板时似乎无法抓住它的内容.

'titled_content_box.php'的内容

// called during vc_before_init
function integrate_titled_content_box(){
    register_titled_content_box();
    add_shortcode( 'titled_content_box', 'titled_content_box_func');
}

//Mapping of titled-contentbox
function register_titled_content_box(){
    vc_map( array(
        "name"              =>  __( "Content box with Title", "mytheme"),
        "base"              =>  "titled_content_box",
        "class"             =>  "",
        "category"          =>  "Content",
        "params"            =>  array(
            array(
                "type"          =>  "textfield",
                "holder"        =>  "div",
                "class"         =>  "",
                "heading"       =>  __( "Title", "mytheme"),
                "param_name"    =>  "title",
                "value"         =>  __("Box title", "mytheme"),
                "description"   =>  __("The title covering the content box", "mytheme")
            ),
            array(
                "type"          =>  "textarea_html",
                "holder"        =>  "div",
                "class"         =>  "",
                "heading"       =>  __( "Description", "mytheme"),
                "param_name"    =>  "content",
                "value"         =>  '<p>Placeholder</p>',
                "description"   =>  __("The content", "mytheme")
            )
        )
    ));
}

// Setting values where necessary and fetching the template
function titled_content_box_func( $atts ){
    extract( shortcode_atts( array(
        'title'      =>  'title',
        'content'    =>  'content'
    ), $atts) );

    return include_vc_template('titled_content_box.php', $atts);
}

add_action ( 'vc_before_init', 'integrate_titled_content_box');
Run Code Online (Sandbox Code Playgroud)

return语句中使用的模板的内容:

<div class="titled-content-box">
    <div class="title"><span><?php echo $atts['title']; ?></span></div>    
    <div class="content">
        <?php echo $atts['content']; ?>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我的内容字段没有加载?元素本身已加载,我可以在VC中使用它...即使标题将被加载,如果我用文本框替换字段,所有仍然工作正常和花花公子...我的最终用户想要格式化他的内容和无法使用html格式.

唯一没有包含的函数是'include_vc_template'函数,但所有这一切都是在预定位置获取字符串定义的php文件并注入$ atts数组.在我所做的所有其他元素中,它完美无缺.但是,为了完整性,我会在这里包括它;

function include_vc_template($template, $atts){
    if(is_file(__DIR__.'/vc_templates/'.$template)){
        ob_start();
        include __DIR__.'/vc_templates/'.$template;
        return ob_get_clean();
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

由于这是我在业余时间工作的一个项目,我不禁会因为一个功能无法正常工作而感到恼火...我做过的大多数搜索都只是简单地将我的内容提交给wpbakery的知识库页面对于vc_map()...任何指针都会很棒!

Пав*_*нов 8

将模板回调函数更新为:

function titled_content_box_func( $atts, $content ) {
    $atts = shortcode_atts( array(
        'title'      =>  'title',
    ), $atts) );
    $atts['content'] = $content;

    return include_vc_template('titled_content_box.php', $atts);
}
Run Code Online (Sandbox Code Playgroud)

更新:07-11-2016:

我建议使用也vc_map_get_attributes函数,它还将所有默认值与您提供的值组合在一起.

正如您在之前的PHP函数中所看到的,我们使用了title带默认值的属性,title该属性与vc_map(__("Box title", "mytheme"))的默认值不兼容,实际上这是一个错误.

为避免错误,请使用vc_map_get_attributes函数for $attsvariable.

function titled_content_box_func( $atts, $content, $tag ) {
    $atts = vc_map_get_attributes($tag, $atts);
    $atts['content'] = $content;

    return include_vc_template('titled_content_box.php', $atts);
}
Run Code Online (Sandbox Code Playgroud)