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

And we need to enqueue our component script

Now we need to create Component with Repeater Logic, encapsulated from the main app.

Now we need to specify input field to store our setting

So final code in /path/to/my-folder/my_super_field.php looks like:

And our JS component file: /path/to/my-folder/js_components/my_super_field.js

Field looks like this now:

And file structure:

Last updated

Was this helpful?