# jc-importer/trunk/class/Common/AddonAPI/Importer/Template/CustomFields.php

Import WP – CSV &amp; XML Import Export for WordPress, version trunk. 59 lines.

- Page: https://pluginprobe.com/plugins/jc-importer/trunk/code/class/Common/AddonAPI/Importer/Template/CustomFields.php
- Raw: https://pluginprobe.com/plugins/jc-importer/trunk/raw/class/Common/AddonAPI/Importer/Template/CustomFields.php
- Modified: 2024-07-14T15:13:26+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/jc-importer/trunk/code/class/Common/AddonAPI/Importer/Template/CustomFields.php#L10-L20`.

```php
<?php

namespace ImportWP\Common\AddonAPI\Importer\Template;

class CustomFields
{
    private $_name;
    private $_prefix;
    private $_fields = [];

    public function __construct($name, $prefix)
    {
        $this->_name = $name;
        $this->_prefix = $prefix;
    }

    public function get_prefix()
    {
        return $this->_prefix;
    }

    public function register_field($name, $args = [])
    {
        $id = isset($args['id']) ? $args['id'] : sanitize_title($name);
        $type = isset($args['type']) ? $args['type'] : 'text';

        $this->_fields[$id] = [
            'id' => $id,
            'name' => $name,
            'type' => $type
        ];
    }

    public function get_dropdown_fields()
    {

        $tmp_fields = [];
        foreach ($this->_fields as $field_id => $field) {

            $tmp_fields[] = [
                'value' => $this->_prefix . '::' . $field['type'] . '::' . $field_id,
                'label' => $this->_name . ' - ' . $field['name']
            ];
        }

        return $tmp_fields;
    }

    public function get_fields()
    {
        return $this->_fields;
    }

    public function get_field($field_id)
    {
        return isset($this->_fields[$field_id]) ? $this->_fields[$field_id] : false;
    }
}

```
