How to create dynamic fields in visual composer? - php

I am creating visual composer plugin for price table. I want to add dynamic textfield so user become able to add multiple text fields for item list as want.
For now it's showing only one text field but user should able to add multiple fields.
array (
"type" => "textfield",
"heading" => __( 'List Items', 'pt-vc' ),
"param_name" => "price_list",
"description" => __( 'Write the list item that you offer', 'pt-vc' ),
"group" => 'List Item',
),

You can use param_group. Here is the code example.
'params'=> array (
array(
'type' => 'param_group',
'value' => '',
'heading' => __( 'List Items', 'pt-vc' ),
'param_name' => 'price_list',
// Note params is mapped inside param-group:
'params' => array(
array(
'type' => 'textfield',
'value' => '',
'heading' => __( 'List Items', 'pt-vc' ),
'param_name' => 'list_itmes',
)
)
)
);
I think answer may be late but help others.

You may use param_group for that. It's not mentioned in the documentation but you may find it "How To's"
https://kb.wpbakery.com/docs/developers-how-tos/use-param-group-in-elements/
Code snippet from link (in case link expires again):
vc_map(
array(
'base' => 'your_shortcode',
'params' => array(
array(
'type' => 'textfield',
'value' => '',
'heading' => 'Title',
'param_name' => 'simple_textfield',
),
// params group
array(
'type' => 'param_group',
'value' => '',
'param_name' => 'titles',
// Note params is mapped inside param-group:
'params' => array(
array(
'type' => 'textfield',
'value' => '',
'heading' => 'Enter your title(multiple field)',
'param_name' => 'title',
)
)
)
)
)
)

Related

Add multiple checkboxes as single field to Custom Shipping Method Settings Page

This is my first WP plugin. And I have been able to get it working perfectly with the settings page and also showing the shipping method on the checkout page. On a requested feature I need to have another field in my settings page that will have multiple checkboxes to allow users to service types they prefer on their site. This is an example of what I am trying to achieve:
The shot above was taken on from the Woocommerce product settings page. Hence I had to look at the code from WC's files. I found the snippet below but I can't get it to work on my settings page:
array(
'title' => __( 'Enable reviews', 'woocommerce' ),
'desc' => __( 'Enable product reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_reviews',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
All the fields I have currently displayed on my settings page was done in this manner:
$this->form_fields = array(
'is_enabled' => array(
'title' => __('Enable', 'plugin_id'),
'type' => 'checkbox',
'description' => __('Enable this shipping.','plugin_id'),
'default' => 'no'
),
'api_key' => array(
'title' => __('API Key', 'plugin_id'),
'type' => 'text',
'description' => __('Obtain API key from Lastmal DIP','plugin_id'),
'default' => null
),
...
)
How can I add the multiple checkboxes to my fields and save them along with the other settings I have?

Adding Row settings to WPBakery plugin

How do I get the settings to the frontend? I need to add classes to vc_row.
/**
* Ken Burns Effect for Row.
*/
add_action( 'vc_after_init', 'ken_burns_effect_add_option_to_vc_row' );
function ken_burns_effect_add_option_to_vc_row() {
// Ken Burns Effect Attributes
$ken_burns_effect_attributes =
array(
array(
'type' => 'checkbox',
'heading' => __( 'Ken Burns for image background', 'ken_burns_effect' ),
'param_name' => 'enable_ken_burns_effect',
'value' => array(
__( 'Yes', 'ken_burns_effect' ) => 'yes',
),
'description' => 'Check this box if you want to enable ken burns effect for this row.',
),
array(
'type' => 'dropdown',
'heading' => __( 'Direction', 'ken_burns_effect' ),
'param_name' => 'direction_ken_burns_effect',
'value' => array(
'Zoom In' => 'zoom_in',
'Zoom Out' => 'zoom_out',
),
'description' => __( '', 'ken_burns_effect' ),
'dependency' => array(
'element' => 'enable_ken_burns_effect',
'value' => array( 'yes' ),
),
),
array(
'type' => 'textfield',
'heading' => __( 'Transition speed', 'ken_burns_effect' ),
'param_name' => 'transition_speed_ken_burns_effect',
'value' => '',
'description' => __( '', 'ken_burns_effect' ),
'dependency' => array(
'element' => 'enable_ken_burns_effect',
'value' => array( 'yes' ),
),
),
);
vc_add_params( 'vc_row', $ken_burns_effect_attributes);
}
You will have to override the vc_row.php by copying it to your theme or plugin.
You can check their documentation on how to set the override directory: https://kb.wpbakery.com/docs/inner-api/vc_set_shortcodes_templates_dir/
Then you can use your custom params inside vc_row.php using their param_name eg:
$enable_ken_burns_effect;
$direction_ken_burns_effect;
$transition_speed_ken_burns_effect;
Keep in mind that you have to override vc_row_inner.php too if you want to use options there. Same goes for section and columns.

wordpress redux framework - create a repeater field and show values later

I am trying to use Redux inside the wordpress theme and not as a plugin. In functions.php I included both redux-framework.php and sample-config.php .
Now I need to create a repeater field.
From Redux doc, I got the following code to use in order to create a repeater field:
$this->sections[] = array(
'title' => __('Repeater Field', 'redux-framework-demo' ),
'icon' => 'el-icon-thumbs-up',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
);
but if I place the code inside functions.php, what will the $this variable refer to? It'll produce errors. So how to use the snippet so that I can retrieve the values from template files as well?
You have to tried an old version system to create a section. You can try the new version system, I'm not sure if this works or not, but you can try this way:
Redux::setSection($opt_name, array(
'title' => __('Ads Sections', 'cbnews'),
'id' => 'ads-sections',
'desc' => __('You can manage your ads', 'cbnews'),
'icon' => 'dashicons dashicons-dashboard',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
));

WordPress taxonomy checkboxes

I have a metabox in my post editor which allows me to pick a single category, I would like this changed to a checkbox where more than one can be picked. I have worked on the following, I would imagine it's a case of changing taxonomy_radio to something like taxonomy_checkbox, however that crashes the metabox completely:
$meta_boxes['test_metabox'] = array(
'id' => 'test_metabox',
'title' => __( 'TEST', 'cmb' ),
'pages' => array( 'post', ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Category', 'cmb' ),
'desc' => __( 'field description (optional)', 'cmb' ),
'id' => 'test-cat',
'type' => 'taxonomy_radio',
'taxonomy' => 'category'
),
Any help would be great.
Just found out that it needs to be changed to taxonomy_multicheck

Wordpress metabox not showing up

I need a Webinar in my wordpress site. So I'm registering an meta box for my custom post type. I can see my custom post in the wordpress admin panel, but inside the custom post meta box is missing. What is wrong here!
// Meta boxes
add_filter( 'rwmb_meta_boxes', 'navbig_webinars_register_meta_boxes' );
//Register meta boxes
function navbig_webinars_register_meta_boxes( $meta_boxes )
{
$prefix = 'navbig_webinars_';
$meta_boxes[] = array(
'id' => 'standard',
'title' => __( 'Webinar Data', 'rwmb' ),
'pages' => array( 'webinar' ),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => array(
array(
'name' => __( 'Date of Webinar', 'rwmb' ),
'id' => "webinar_date",
'type' => 'date',
// jQuery date picker options. See here http://api.jqueryui.com/datepicker
'js_options' => array(
'dateFormat' => __( 'dd-MM-yy', 'rwmb' ),
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
array(
'name' => __( 'Location', 'rwmb' ),
'id' => "webinar-location",
'type' => 'text',
'std' => __( 'Default text value', 'rwmb' ),
),
array(
'name' => __( 'Time Of Webinar', 'rwmb' ),
'id' => 'webinar_time',
'type' => 'time',
'js_options' => array(
'stepMinute' => 5,
'showSecond' => true,
'stepSecond' => 10,
),
),
array(
'name' => __( 'Select Time Zone', 'rwmb' ),
'id' => "select-timezone",
'type' => 'select_advanced',
'options' => array(
'value1' => __( 'PST', 'rwmb' ),
'value2' => __( 'EST', 'rwmb' ),
),
'multiple' => false,
'placeholder' => __( 'Select an Coures Type', 'rwmb' ),
),
// URL
array(
'name' => __( 'Webinar URL', 'rwmb' ),
'id' => "webinar_url",
'type' => 'url',
'std' => 'http://google.com',
),
array(
'name' => __( 'Webinar Banner', 'rwmb' ),
'id' => "webinar_banner",
'type' => 'thickbox_image',
),
),
);
return $meta_boxes;
}
You can find more detail about meta boxes here.
Here is sample add_meta_box code:-
add_meta_box(
'some_meta_box_name'
,__( 'Some Meta Box Headline', 'plugin_textdomain' )
,'render_meta_box_content' //this is callback function.
,'post_type'
,'advanced'
,'high'
);

Categories