ninja_forms_calc_listen_field_class

Function that adds a calc filter class to the field if appropriate.

Description

ninja_forms_calc_listen_field_class( $form_id ); 

Parameters (1)

0. $form_id
The form id.

Usage

  1. if ( !function_exists( 'ninja_forms_calc_listen_field_class' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/display/fields/calc-field-class.php'; 
  3.  
  4. // The form id. 
  5. $form_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = ninja_forms_calc_listen_field_class($form_id); 
  9.  

Defined (1)

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

/deprecated/includes/display/fields/calc-field-class.php  
  1. function ninja_forms_calc_listen_field_class( $form_id ) { 
  2. global $ninja_forms_loading, $ninja_forms_processing; 
  3.  
  4. $field_results = ninja_forms_get_fields_by_form_id( $form_id ); 
  5.  
  6. foreach( $field_results as $field_row ) { 
  7.  
  8. $field_id = $field_row['id']; 
  9.  
  10. if ( isset ( $field_row['type'] ) ) { 
  11. $field_type = $field_row['type']; 
  12. } else { 
  13. $field_type = ''; 
  14.  
  15. $field_data = $field_row['data']; 
  16. $field_data = apply_filters( 'ninja_forms_field', $field_data, $field_id ); 
  17. $calc_listen = ''; 
  18.  
  19. $sub_total = false; 
  20. $tax = false; 
  21. foreach ( $field_results as $field ) { 
  22.  
  23. $data = $field['data']; 
  24.  
  25. if ( isset ( $field['type'] ) ) { 
  26. $field_type = $field['type']; 
  27. } else { 
  28. $field_type = ''; 
  29.  
  30. // Check for advanced calculation fields that reference this field. If we find one, and use_calc_adv is set to 1, add a special class to this field. 
  31. if ( $field_type == '_calc' ) { 
  32.  
  33. // Check to see if this is a sub_total calculation 
  34. if ( isset ( $data['calc_method'] ) ) { 
  35. $calc_method = $data['calc_method']; 
  36. } else { 
  37. $calc_method = 'auto'; 
  38.  
  39. switch ( $calc_method ) { 
  40. case 'auto': 
  41. if ( isset ( $field_data['calc_auto_include'] ) AND $field_data['calc_auto_include'] == 1 ) { 
  42. $calc_listen = 'ninja-forms-field-calc-listen ninja-forms-field-calc-auto'; 
  43. break; 
  44. case 'fields': 
  45. foreach ( $data['calc'] as $calc ) { 
  46. if ( $calc['field'] == $field_id ) { 
  47. if ( $calc_listen == '' ) { 
  48. $calc_listen = 'ninja-forms-field-calc-listen'; 
  49. break; 
  50. break; 
  51. case 'eq': 
  52. $eq = $data['calc_eq']; 
  53. if (preg_match("/\bfield_".$field_id."\b/i", $eq ) ) { 
  54. if ( $calc_listen == '' ) { 
  55. $calc_listen = 'ninja-forms-field-calc-listen'; 
  56. break; 
  57. break; 
  58.  
  59. if ( isset ( $field_data['payment_sub_total'] ) AND $field_data['payment_sub_total'] == 1 ) { 
  60. if ( $calc_listen == '' ) { 
  61. $calc_listen = 'ninja-forms-field-calc-listen'; 
  62.  
  63. // Check to see if this is a tax field; 
  64. if ( $field_type == '_tax' ) { 
  65. if ( $calc_listen == '' ) { 
  66. $calc_listen = 'ninja-forms-field-calc-listen'; 
  67.  
  68. if ( isset ( $ninja_forms_loading ) ) { 
  69. $field_class = $ninja_forms_loading->get_field_setting( $field_id, 'field_class' ); 
  70. $field_class .= ' '.$calc_listen; 
  71. $ninja_forms_loading->update_field_setting( $field_id, 'field_class', $field_class ); 
  72. } else { 
  73. $field_class = $ninja_forms_processing->get_field_setting( $field_id, 'field_class' ); 
  74. $field_class .= ' '.$calc_listen; 
  75. $ninja_forms_processing->update_field_setting( $field_id, 'field_class', $field_class );