nf_save_sub

The Ninja Forms nf save sub function.

Description

nf_save_sub(); 

Usage

  1. if ( !function_exists( 'nf_save_sub' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/display/processing/save-sub.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = nf_save_sub(); 
  7.  

Defined (1)

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

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