cf_custom_fields_save_meta_data

Save meta data from form.

Description

cf_custom_fields_save_meta_data( (array) $config, (array) $form ); 

Parameters (2)

0. $config (array)
Processor config.
1. $form (array)
Form config.

Usage

  1. if ( !function_exists( 'cf_custom_fields_save_meta_data' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'caldera-custom-fields/includes/metabox.php'; 
  3.  
  4. // Processor config. 
  5. $config = array(); 
  6.  
  7. // Form config. 
  8. $form = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = cf_custom_fields_save_meta_data($config, $form); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/metabox.php  
  1. function cf_custom_fields_save_meta_data($config, $form) { 
  2. global $post; 
  3.  
  4. if(!is_admin()) { 
  5. return; 
  6.  
  7. $data = Caldera_Forms::get_submission_data($form); 
  8.  
  9. $field_toremove = array(); 
  10.  
  11. foreach($form['fields'] as $field_id => $field) { 
  12. if( 'button' == Caldera_Forms_Field_Util::get_type($field, $form ) && $field['config']['type'] === 'submit' ) { 
  13. unset( $form[ 'fields' ][ $field_id ] ); 
  14. }elseif ( Caldera_Forms_Field_Util::is_file_field( $field, $form ) ) { 
  15. unset( $form[ 'fields' ][ $field_id ] ); 
  16. }elseif( Caldera_Forms_Fields::not_support( Caldera_Forms_Field_Util::get_type( $field, $form ), 'entry_list')) { 
  17. unset( $form[ 'fields' ][ $field_id ] ); 
  18.  
  19.  
  20. delete_post_meta( $post->ID, $field['slug'] ); 
  21.  
  22. // add filter to remove submit buttons 
  23.  
  24. // add filter to remove file fields 
  25.  
  26. foreach($data as $key=>$value) { 
  27. if(empty($form['fields'][$key])) { 
  28. continue; 
  29.  
  30. $slug = $form['fields'][$key]['slug']; 
  31.  
  32. /** 
  33. * Filter value before saving using to metabox processor 
  34. * @since 2.0.3 
  35. * @param mixed $value The value to be saved 
  36. * @param string $slug Slug of field 
  37. * @param int $post_id ID of post 
  38. */ 
  39. $value = apply_filters( 'cf_custom_fields_pre_save_meta_key_metabox', $value, $slug, $post->ID ); 
  40. if( is_array( $value ) ) { 
  41. delete_post_meta( $post->ID, $slug ); 
  42. foreach( $value as $single_value ) { 
  43. add_post_meta( $post->ID, $slug, $single_value );  
  44. }else{ 
  45. update_post_meta( $post->ID, $slug, $value ); 
  46. if(isset($field_toremove[$form['fields'][$key]['slug']])) { 
  47. unset($field_toremove[$form['fields'][$key]['slug']]); 
  48.  
  49. return $data;