Creating Custom Field Types

Registering your custom field type

add_filter('cfs_field_types', 'my_custom_field_type');

function my_custom_field_type($field_types)
{
    $field_types['custom_text'] = FULL_PATH_TO_YOUR_CLASS_FILE;
    return $field_types;
}

Example class file

<?php
class cfs_numeric extends cfs_Field
{
    function __construct($parent)
    {
        $this->name = 'numeric';
        $this->label = __('Numeric', 'cfs');
        $this->parent = $parent;
    }

    function html($field)
    {
    ?>
        <input type="text" name="<?php echo $field->input_name; ?>" class="<?php echo $field->input_class; ?>" value="<?php echo $field->value; ?>" />
    <?php
    }

    function format_value_for_input($value, $field)
    {
        return htmlspecialchars($value, ENT_QUOTES);
    }
}

Available class methods

// (required) initializes the base class
__construct($parent)
{
    $this->name = 'text';
    $this->label = __('Text', 'cfs');
    $this->parent = $parent;
}
// the input field’s HTML. By default, this will be a standard text input.
html($field)
{
?>
    <input type="text" name="<?php echo $field->input_name; ?>" class="<?php echo $field->input_class; ?>" value="<?php echo $field->value; ?>" />
<?php
}
// HTML for any extra options on the field configuration page
options_html($key, $field)
{
}
// Add any CSS or scripts on the data input page
input_head($field = null)
{
}
// Format the raw value array
// By default, this method returns a scalar value
// Override this method and return $value for field types expecting an array value
prepare_value($value, $field = null)
{
    return $value[0];
}
// Format the value for use with $cfs->get()
format_value_for_api($value, $field = null)
{
    return $value;
}
// Format the value for HTML input elements
format_value_for_input($value, $field = null)
{
    return $value;
}
// Override a value before saving to database
pre_save($value, $field = null)
{
    return $value;
}
// Override field settings before saving field to the database
pre_save_field($field)
{
    return $field;
}