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 (2)

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) { 
  12. // remove old data 
  13. delete_post_meta( $post->ID, $field['slug'] ); 
  14.  
  15. foreach($data as $key=>$value) { 
  16. if(empty($form['fields'][$key])) { 
  17. continue; 
  18.  
  19. $slug = $form['fields'][$key]['slug']; 
  20.  
  21. /** 
  22. * Filter value before saving using to metabox processor 
  23. * @since 2.0.3 
  24. * @param mixed $value The value to be saved 
  25. * @param string $slug Slug of field 
  26. * @param int $post_id ID of post 
  27. */ 
  28. $value = apply_filters( 'cf_custom_fields_pre_save_meta_key_metabox', $value, $slug, $post->ID ); 
  29. if( is_array( $value ) ) { 
  30. delete_post_meta( $post->ID, $slug ); 
  31. foreach( $value as $single_value ) { 
  32. add_post_meta( $post->ID, $slug, $single_value );  
  33. }else{ 
  34. update_post_meta( $post->ID, $slug, $value ); 
  35. if(isset($field_toremove[$form['fields'][$key]['slug']])) { 
  36. unset($field_toremove[$form['fields'][$key]['slug']]); 
  37.  
  38. return $data; 
  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) { 
  12. // remove old data 
  13. delete_post_meta( $post->ID, $field['slug'] ); 
  14.  
  15. foreach($data as $key=>$value) { 
  16. if(empty($form['fields'][$key])) { 
  17. continue; 
  18.  
  19. $slug = $form['fields'][$key]['slug']; 
  20.  
  21. /** 
  22. * Filter value before saving using to metabox processor 
  23. * @since 2.0.3 
  24. * @param mixed $value The value to be saved 
  25. * @param string $slug Slug of field 
  26. * @param int $post_id ID of post 
  27. */ 
  28. $value = apply_filters( 'cf_custom_fields_pre_save_meta_key_metabox', $value, $slug, $post->ID ); 
  29. if( is_array( $value ) ) { 
  30. delete_post_meta( $post->ID, $slug ); 
  31. foreach( $value as $single_value ) { 
  32. add_post_meta( $post->ID, $slug, $single_value );  
  33. }else{ 
  34. update_post_meta( $post->ID, $slug, $value ); 
  35. if(isset($field_toremove[$form['fields'][$key]['slug']])) { 
  36. unset($field_toremove[$form['fields'][$key]['slug']]); 
  37.  
  38. return $data;