Добавление параметра html_template в шорткод vc_row в Visual Composer

Мой код:

    // Add language dropdown to visual composer settings
    if (function_exists('vc_add_param')) {
        vc_add_param('vc_row', array(
            'type' => 'dropdown',
            'heading' => "Language",
            'param_name' => 'language',
            'value' => array("English", "Russian"),
            'description' => __("Select Language", "discprofile"),
            'weight' => 1, //  default 0 (unsorted, appened to bottom, 1- append to top)
        ));
    }

    // Set custom html_template to display data-lang attribute
    if (function_exists('vc_map')) {

        // setup custom attributes
        $attributes = array(
            'html_template' => 'vc_templates/vc_row.php'
        );

        // Update 'vc_row' to include custom vc_row template and remap shortcode
        $params = vc_map_update('vc_row', $attributes);

        // Remove default vc_row
        vc_remove_element('vc_row');

        // Remap shortcode with custom template
        vc_map($params['vc_row']);
    }

vc_add_param() работает, но вторая часть кода выдает следующую ошибку:

( !) Неустранимая ошибка: Неверный объект vc_map. Базовый атрибут требуется в /Users/mike/Sites/Fun/wordpress/web/app/plugins/js_composer/include/helpers/helpers_api.php в строке 26.

Это ресурсы, которые я ранее просматривал:

Соответствующая документация:

Любая помощь будет принята с благодарностью.


person Allure Web Solutions    schedule 06.12.2016    source источник


Ответы (2)


Я нашел решение:

Я понял, что слишком усложняю это. Я нашел метод Visual Composer для ручной настройки каталога vc_templates. Не нужно было обновлять параметр шорткода html_template и не нужно было сопоставлять новый шорткод.

Это упростило код до следующего:

// Set custom html_template to display data-lang attribute
$dir = __DIR__ . '/vc_templates';
vc_set_shortcodes_templates_dir( $dir );
var_dump( vc_shortcodes_theme_templates_dir( 'vc_row.php' ) );
person Allure Web Solutions    schedule 18.04.2017

На самом деле функция vc_map_update возвращает только параметры шорткода, а не все настройки.

Вам нужно использовать функцию vc_get_shortcode, которая вернет весь элемент.

С: $element = vc_get_shortcode('vc_row');

Кроме того, нет необходимости заменять элемент, потому что vc_map_update, очевидно, обновит его.

person Павел Иванов    schedule 07.12.2016
comment
Можете ли вы помочь мне с тем, как будет выглядеть полный код? @Павел - person Allure Web Solutions; 12.12.2016
comment
@AllureWebSolutions, используйте $shortcode = vc_get_shortcode('vc_row'); затем измените переменную $shortcode и используйте vc_map_update('vc_row',$shortcode); - person Павел Иванов; 01.03.2017
comment
Когда я пытаюсь это сделать, я получаю следующую ошибку: Error: Wrong setting_name for shortcode:vc_row. Base can't be modified. - person Allure Web Solutions; 02.03.2017
comment
Я придумал альтернативное решение. Спасибо за вашу помощь! - person Allure Web Solutions; 02.03.2017
comment
@AllureWebSolutions, вы можете показать нам свое решение для будущих искателей. Кстати, вы также можете использовать unset($shortcode['base']); перед vc_map_update - person Павел Иванов; 02.03.2017
comment
@Pavel, я обновил свой исходный пост, чтобы показать свое решение, так как у меня недостаточно очков репутации, чтобы опубликовать ответ. - person Allure Web Solutions; 02.03.2017