Comment on page
Registering field
We have quite enough fields to use, but if you need something extra functional and you familiar with Vue and with Components you can make your own fields type.
Here we will explain how to create own field called Repeater
First of all, you should specify the directory to add a custom field template:
my-plugin/my-own-fields/setup.php
In your config file specify field type.
'awesome_field' => array(
'type' => 'my_super_field',
'label' => esc_html__('Simple Repeater', 'my-domain'),
'value' => 'Awesome default value',
'submenu' => esc_html__('General fields', 'my-domain'),
),
Now we have a new field type my_super_field
add_filter('wpcfto_field_my_super_field', function($path){
return dirname(__FILE__) . '/my_super_field.php';
});
The framework will watch for the directory you specified above with template name my_super_field.php
In the template will be available certain variables : /path/to/my-folder/my_super_field.php
<?php
/**
* @var $field
* @var $field_id
* @var $field_value
* @var $field_label
* @var $field_name
* @var $section_name
*
*/
And we need to enqueue our component script
wp_enqueue_script('my-super-component', plugin_dir_url(__FILE__) . '/js_components/my_super_field.js');