参数在自定义Visual Composer图标中返回空

时间:2017-01-25 16:50:55

标签: php arrays wordpress visual-composer

我在VC中设置了一个自定义元素,供用户添加一个带有自定义文本,链接和(自定义)字体图标的按钮。

我可以回显标题和链接,但字体图标是空白的。 当我print_r($ atts)时,我得到了这个:

Array
(
    [reach_vc_button_text] => More Information
    [reach_vc_button_link] => url:http%3A%2F%2Flocalhost%2FWordPress%2FJammyCustard%2Freach%2Ffunding%2Fthriving-rural-communities-scheme-trc%2F|||
    [reach_vc_button_icon] => 
);
    <?php
function reach_vc_button_html( $atts ) {

    $atts = shortcode_atts(
        array(
            'reach_vc_button_text' => '',
            'reach_vc_button_link' => '',
            'reach_vc_button_icon' => '',
        ), $atts, 'reach_vc_button'
    );

    ob_start();
    ?>

        <?php
            $href = $atts['reach_vc_button_link'];
            $button_link = vc_build_link( $href );

            //echo '<pre>'; print_r($atts); echo '</pre>';

        ?>  

    <a href="<?php echo $button_link['url']; ?>" class="read-more excerpt-read-more project-read-more"><?php echo $atts['reach_vc_button_text']; ?><i class="<?php echo $atts['reach_vc_button_icon']; ?>"></i></a>

    <?php
    $html = ob_get_clean(); 
    return $html;

}

add_shortcode( 'reach_vc_button', 'reach_vc_button_html' );

编辑:添加了参数代码:

array(
                "type"        => "iconpicker",
                "heading"     => __( "Button Icon", "reach-rdp" ),
                "param_name"  => "reach_vc_button_icon",
                "value"       => "icon-more-information",
                "description" => __( "Select the icon to display for this button", "reach-rdp" ),
                "settings"   => array(
                    "emptyIcon"    => false,
                    "type"         => "reach",
                    "iconsPerPage" => "50",
                ),
                "dependency" => array(
                    "element" => "icon_type",
                    "value"   => "reach",
                ),
            ),

1 个答案:

答案 0 :(得分:0)

您的问题可能出在您的参数声明代码中。尝试以下代码

array(
      'type' => 'iconpicker',
      'heading' => __( 'Button Icon', 'reach-rdp' ),
      'param_name' => 'reach_vc_button_icon',
      'settings' => array(
        'emptyIcon' => false, // default true, display an "EMPTY" icon?
        'type' => 'openiconic',
        'iconsPerPage' => 200, // default 100, how many icons per/page to display
      ),
      'dependency' => array(
        'element' => 'icon_type',
        'value' => 'openiconic',
      ),
      'description' => __( 'Select icon from library.', 'reach-rdp' ),
    ),

下一步是将Openiconic样式排入队列,或者在短代码输出文件中使用Visual Composer给定的函数。请遵循此代码

vc_icon_element_fonts_enqueue( $i_type );

有关详细信息,请查看此链接https://wpbakery.atlassian.net/wiki/display/VC/Adding+Icons+to+vc_icon