2

My code:

    // 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']);
    }

The vc_add_param() works, but the second part of the code throws the following error:

( ! ) Fatal error: Wrong vc_map object. Base attribute is required in /Users/mike/Sites/Fun/wordpress/web/app/plugins/js_composer/include/helpers/helpers_api.php on line 26

These are the resources I previously looked at:

Relevant documentation:

Any help would be greatly appreciated.

Community
  • 1
  • 1

2 Answers2

2

I found a solution:

I figured out that I was overcomplicating this. I found the Visual Composer method for manually setting the vc_templates directory. There was no need to update the shortcode html_template parameter and no need to map the new shortcode.

This simplified the code to the following:

// 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' ) );
0

Actually, function vc_map_update return only params of shortcode but not all settings.

You need to use vc_get_shortcode function which will return the whole element.

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

Also, there are no needs to replace element because vc_map_update will update it obviously.