Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created July 21, 2017 22:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/3aea78e4c7021cf6a96e97d126ce6399 to your computer and use it in GitHub Desktop.
Save Shelob9/3aea78e4c7021cf6a96e97d126ce6399 to your computer and use it in GitHub Desktop.
Add custom Caldera Forms field types. See: https://calderaforms.com/doc/caldera_forms_get_field_types/
/**
<?php
/**
Add a copy of Caldera Forms default select fields with new slug "special_select"
*/
add_filter('caldera_forms_get_field_types', function($fieldtypes){
$fieldtypes['special_select'] = => array(
"field" => __( 'Special Select', 'caldera-forms' ),
"description" => __( 'Special Select', 'caldera-forms' ),
'icon' => CFCORE_URL . 'assets/build/images/plus.svg',
"file" => CFCORE_PATH . "fields/dropdown/field.php",
"category" => __( 'Select', 'caldera-forms' ),
"options" => "single",
"static" => true,
"viewer" => array( Caldera_Forms::get_instance(), 'filter_options_calculator' ),
"setup" => array(
"template" => CFCORE_PATH . "fields/dropdown/config_template.php",
"preview" => CFCORE_PATH . "fields/dropdown/preview.php",
"default" => array(),
)
),
return $fieldtypes;
}
/**
* Set options for special_select field
*/
add_filter( 'caldera_forms_render_get_field_type-special_select', function( $field ){
$field[ 'config' ][ 'option' ] = array(
array(
'value' => 1,
'label' => 'One'
),
array(
'value' => 200,
'label' => 'Two Hundred'
),
);
return $field;
});
<?php
/**
Basic exmaple of how to add new field type to Caldera Forms
*/
add_filter('caldera_forms_get_field_types', function($fieldtypes){
$fieldtypes['field_name'] = array(
"field" => "Field Name",
"file" => " " //@todo path to the file for the field itself.
"category" => "basic", //@todo set category or categories
"description" => " " //@todo set description
"setup" => array(
//optional
)
);
return $fieldtypes;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment