Example Caldera Forms Proccesor See: https://calderaforms.com/doc/getting-submission-data-in-a-form-processor/
<?php | |
/** | |
* UI for Example Caldera Forms Processor | |
* | |
* Using the UI generator is way simpler than reverse engineering UI markup and provides for better forward-compatibility | |
*/ | |
echo Caldera_Forms_Processor_UI::config_fields( my_processor_extra_meta_processor_fields() ); |
<?php | |
/** | |
Plugin Name: Caldera Forms Processor To Save Extra Data | |
Description: Example Caldera Forms processor to save extra data to post meta | |
*/ | |
/** | |
* Register processor | |
*/ | |
add_filter( 'caldera_forms_get_form_processors', function( $processors ) { | |
$processors['my_processor_extra_meta'] = array( | |
'name' => 'Extra Post Meta', | |
'description' => 'Save extra data to post meta', | |
'processor' => 'my_processor_extra_meta_processor', | |
'template' => __DIR__ . '/config.php' | |
); | |
return $processors; | |
} ); | |
/** | |
* At process, get the post ID and the data and save in post meta | |
* | |
* @param array $config Processor config | |
* @param array $form Form config | |
* @param string $process_id Unique process ID for this submission | |
* | |
* @return void|array | |
*/ | |
function my_processor_extra_meta_processor( $config, $form, $process_id ){ | |
$post_id = Caldera_Forms::do_magic_tags( $config[ 'post' ] ); | |
$field_value = Caldera_Forms::do_magic_tags( $config[ 'field' ] ); | |
if( is_numeric( $post_id ) && is_object( $post = get_post( $post_id ) ) ){ | |
update_post_meta( $post_id, 'extra_meta_field', $field_value ); | |
} | |
} | |
/** | |
* Setup fields to pass to Caldera_Forms_Processor_UI::config_fields() in config | |
* | |
* @return array | |
*/ | |
function my_processor_extra_meta_processor_fields(){ | |
return array( | |
array( | |
'id' => 'post', | |
'label' => 'Post ID', | |
'type' => 'number', | |
'required' => true, | |
'magic' => true, | |
'desc' => 'Post to save field data in. Use {embed_post:ID}' | |
), | |
array( | |
'id' => 'field', | |
'label' => 'Field to save', | |
'type' => 'text', | |
'required' => true, | |
'magic' => true, | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment