Оператор Else выполняется в пользовательском шорткоде - PullRequest
0 голосов
/ 10 июля 2019

У меня следующий шорткод, отображаемый для отображения выпадающего поля в WPBakery:

array(
    'type' => 'dropdown',
    'heading' => esc_html__( 'Type of container', 'js_composer' ),
    'param_name' => 'container_type',
    'value' => array(
        'Container' => 'container',
        'Container fluid (full width)' => 'container-fluid',
    ),
    'std' => 'container',
    'description' => esc_html__( 'Select whether you want the content to be contained or full width on the screen.', 'js_composer' ),
)

Он инициализируется в другом файле, где определены его атрибуты и разметка:

<?php

/**
 * Shortcode attributes
 * @var $container_type
 */

class vcRow extends WPBakeryShortCode {

    function __construct() {
    	add_action( 'init', array( $this, 'vc_row_mapping' ) );
    	add_shortcode( 'vc_row', array( $this, 'vc_row' ) );
    }
    
    public function vc_text_mapping() {
	    vc_map(
            array(
            'name' => __('row', 'text-domain'),
            'base' => 'vc_row', 
            'description' => __('', 'text-domain'), 
            'params' => array(
                array(
        			'type' => 'dropdown',
        			'heading' => esc_html__( 'Type of container', 'js_composer' ),
        			'param_name' => 'container_type',
        			'value' => array(
                    	'Container' => 'container',
                    	'Container fluid (full width)' => 'container-fluid',
                    ),
                    'std' => 'container',
        		),
            );
    }

    public function vc_row($atts, $content) {
    	extract(
            shortcode_atts(
                array(
                    'container_type'  => '',
                ),
                $atts
            )
        );
          
        if ($container_type == "container-fluid"){
            echo "container-fluid";
        } else {
            echo "container";
        }
    
        echo "<p>".$container_type."</p>";
    }
   
}

new vcRow();?>

Одно из моих полей установлено как 'container-liquid , but an echo of $ container_type` показывает "контейнер" (означает, что выполняется оператор else. Не знаете, почему?

...