本文介绍了如何访问 vc_map() 内部值来为 WPBakery 界面创建自定义标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有人问了一个类似的问题,没有任何可行的答案:用于自定义短代码 (vc_map) 的 Visual Composer 自定义标记

A similar question has been asked here, without any viable responses: Visual Composer custom markup for custom shortcode (vc_map)

这里:Visual Composer 自定义简码模板 -custom_markup 显示用户输入

我正在尝试在 WPBakery 界面中创建自定义标记.

I am trying to create custom markup within the WPBakery interface.

我可以通过以下方式添加自定义标记:

I can add custom markup no problem by doing:

$markup = 'test'; 
vc_map( array(
   "name" => __("MyShortcode"),
   "base" => "myshortcode",
   "category" => __('Content'),
   "custom_markup" => $markup, // @TODO how do we access shortcode's attributes here to display in bakery grid
   "params" => $params
) );

这将在 WPBakery 网格中输出测试",这很好,但是如何访问 vc_map() 内部值以显示?

This will output "test" in the WPBakery grid which is good, but how do I access vc_map() internal values to display?

例如,我将帖子类型"作为此短代码的字段.例如,如果有人选择页面"帖子类型,我想在 WPBakery 网格中显示这些帖子.我无法弄清楚的是如何获取用户选择显示的值.

For instance I have "post types" as a field for this shortcode. If someone selects "page" post type for example, I would like to display those posts within the WPBakery grid. What I cannot figure out is how to get the values that the user selected to display.

任何帮助将不胜感激.我已经无休止地搜索了这个.

Any help would be greatly appreciated. I've searched endlessly on this one.

推荐答案

我找到了解决方案.通过扩展类 WPBakeryShortCode,您可以更改 contentAdmin 输出:

I found a solution. By extending the class WPBakeryShortCode, you could change the contentAdmin output :

// Extend Class WPBakeryShortCodesContainer
if (class_exists('WPBakeryShortCode')) {
class WPBakeryShortCode_Custom_Element extends WPBakeryShortCode {
    /**
     * @param $atts
     * @param $content
     *
     * @return string
     * @throws \Exception
     */
    public function contentAdmin( $atts, $content = null ) {
        $output = $custom_markup = $width = $el_position = '';
        if ( null !== $content ) {
            $content = wpautop( stripslashes( $content ) );
        }

        $shortcode_attributes = array( 'width' => '1/1' );
        $atts = vc_map_get_attributes( $this->getShortcode(), $atts ) + $shortcode_attributes;
        $this->atts = $atts;
        $elem = $this->getElementHolder( $width );
        if ( isset( $this->settings['custom_markup'] ) && '' !== $this->settings['custom_markup'] ) {
            $markup = $this->settings['custom_markup'];
            $elem = str_ireplace( '%wpb_element_content%', $this->customMarkup( $markup, $content ), $elem );
            $output .= $elem;
        } else {
            $inner = $this->outputTitle( $this->settings['name'] );
            $inner .= $this->paramsHtmlHolders( $atts );
            $elem = str_ireplace( '%wpb_element_content%', $inner, $elem );
            $output .= $elem;
        }

        return $output;
    }
}
}

我按照这个 Git 示例来创建我的自定义元素:https://gist.github.com/Webcreations907/ff0b068c5c364f63e45d

I follow this Git example to create my custom elements : https://gist.github.com/Webcreations907/ff0b068c5c364f63e45d

这篇关于如何访问 vc_map() 内部值来为 WPBakery 界面创建自定义标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 03:02