/deprecated/includes/display/processing/save-sub.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. function nf_save_sub() { 
  4. global $ninja_forms_processing, $ninja_forms_fields; 
  5.  
  6. // save forms by default 
  7. $save = true; 
  8.  
  9. // check if there's some legacy save settings saved in the database 
  10. if ( 0 === $ninja_forms_processing->get_form_setting('save_subs') ) { 
  11. $save = false; 
  12. $save = apply_filters ( 'ninja_forms_save_submission', $save, $ninja_forms_processing->get_form_ID() ); 
  13.  
  14. if( $save ) { 
  15.  
  16. $action = $ninja_forms_processing->get_action(); 
  17. $user_id = $ninja_forms_processing->get_user_ID(); 
  18. $sub_id = $ninja_forms_processing->get_form_setting( 'sub_id' ); 
  19. $form_id = $ninja_forms_processing->get_form_ID(); 
  20. $field_data = $ninja_forms_processing->get_all_fields(); 
  21.  
  22. // If we don't have a submission ID already, create a submission post. 
  23. if ( empty( $sub_id ) ) { 
  24. $sub_id = Ninja_Forms()->subs()->create( $form_id ); 
  25. Ninja_Forms()->sub( $sub_id )->update_user_id( $user_id ); 
  26. do_action( 'nf_create_sub', $sub_id ); 
  27. // Update our legacy $ninja_forms_processing with the new sub_id 
  28. $ninja_forms_processing->update_form_setting( 'sub_id', $sub_id ); 
  29.  
  30. do_action( 'nf_before_save_sub', $sub_id ); 
  31.  
  32. Ninja_Forms()->sub( $sub_id )->update_action( $action ); 
  33.  
  34. if ( is_array ( $field_data ) && ! empty ( $field_data ) ) { 
  35. // Loop through our submitted data and add the values found there. 
  36.  
  37. // Maintain backwards compatibility with older extensions that use the ninja_forms_save_sub_args filter. 
  38. $data = array(); 
  39. // 
  40.   
  41. foreach ( $field_data as $field_id => $user_value ) { 
  42. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  43. $field_type = $field_row['type']; 
  44. if ( isset ( $ninja_forms_fields[$field_type]['save_sub'] ) ) { 
  45. $save_sub = $ninja_forms_fields[$field_type]['save_sub']; 
  46. if( $save_sub ) { 
  47. $user_value = apply_filters( 'nf_save_sub_user_value', $user_value, $field_id ); 
  48. if( is_array( $user_value ) ) { 
  49. $user_value = ninja_forms_esc_html_deep( $user_value ); 
  50. }else{ 
  51. $user_value = esc_html( $user_value ); 
  52. // Add our submitted field value. 
  53. Ninja_Forms()->sub( $sub_id )->add_field( $field_id, $user_value ); 
  54.  
  55. // Maintain backwards compatibility with older extensions that use the ninja_forms_save_sub_args filter. 
  56. $data[] = array( 'field_id' => $field_id, 'user_value' => $user_value ); 
  57. // 
  58.  
  59.  
  60. // Maintain backwards compatibility with older extensions that still use the ninja_forms_save_sub_args filter. 
  61. $args = apply_filters( 'ninja_forms_save_sub_args', array( 
  62. 'sub_id' => $sub_id,  
  63. 'form_id' => $form_id,  
  64. 'data' => serialize( $data ),  
  65. ) ); 
  66.  
  67. ninja_forms_update_sub( $args ); 
  68. // 
  69.   
  70. do_action( 'nf_save_sub', $sub_id ); 
  71.  
  72. add_action('ninja_forms_post_process', 'nf_save_sub'); 
.