ninja_forms_get_field_class

The Ninja Forms ninja forms get field class function.

Description

ninja_forms_get_field_class( $field_id, (string) $form_id = '' ); 

Parameters (2)

0. $field_id
The field id.
1. $form_id — Optional. (string) => ''
The form id.

Usage

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

Defined (1)

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

/deprecated/includes/display/fields/display-fields.php  
  1. function ninja_forms_get_field_class( $field_id, $form_id = '' ) { 
  2. global $ninja_forms_loading, $ninja_forms_processing; 
  3.  
  4. if ( '' == $form_id ) { 
  5. $field = ninja_forms_get_field_by_id( $field_id ); 
  6. $form_id = $field['form_id']; 
  7.  
  8. if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { 
  9. $field_row = $ninja_forms_loading->get_field_settings( $field_id ); 
  10. $field_class = $ninja_forms_loading->get_field_setting( $field_id, 'field_class' ); 
  11. } else if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) { 
  12. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  13. $field_class = $ninja_forms_processing->get_field_setting( $field_id, 'field_class' ); 
  14.  
  15. $field_data = $field_row['data']; 
  16. $field_data = apply_filters( 'ninja_forms_field', $field_data, $field_id ); 
  17.  
  18. $field_type = isset ( $field_row['type'] ) ? $field_row['type'] : ''; 
  19.  
  20. $x = 0; 
  21. $custom_class = ''; 
  22.  
  23. if ( isset( $field_data['class'] ) AND !empty ( $field_data['class'] ) ) { 
  24. $class_array = explode(", ", $field_data['class']); 
  25. foreach($class_array as $class) { 
  26. $custom_class .= $class; 
  27. if($x != (count($class_array) - 1)) { 
  28. $custom_class .= " "; 
  29. $x++; 
  30.  
  31. $req_class = ''; 
  32. if(isset($field_data['req']) AND $field_data['req'] == 1) { 
  33. $req_class = 'ninja-forms-req'; 
  34.  
  35. // Check to see if we are dealing with a field that has the user_info_field_group set. 
  36. if ( isset ( $field_data['user_info_field_group_name'] ) and $field_data['user_info_field_group_name'] != '' ) { 
  37. $user_info_group_class = $field_data['user_info_field_group_name'].'-address'; 
  38. } else { 
  39. $user_info_group_class = ''; 
  40.  
  41. $address_class = ''; 
  42. // Check to see if we are dealing with an address field. 
  43. if ( isset ( $field_data['user_address_1'] ) and $field_data['user_address_1'] == 1 ) { 
  44. $address_class = 'address address1'; 
  45. }  
  46.  
  47. if ( isset ( $field_data['user_address_2'] ) and $field_data['user_address_2'] == 1 ) { 
  48. $address_class = 'address address2'; 
  49. }  
  50.  
  51. if ( isset ( $field_data['user_city'] ) and $field_data['user_city'] == 1 ) { 
  52. $address_class = 'address city'; 
  53. }  
  54.  
  55. if ( isset ( $field_data['user_state'] ) and $field_data['user_state'] == 1 ) { 
  56. $address_class = 'address state'; 
  57.  
  58. if ( isset ( $field_data['user_zip'] ) and $field_data['user_zip'] == 1 ) { 
  59. $address_class = 'address zip'; 
  60.  
  61. if ( '_country' == $field_type ) { 
  62. $address_class = 'address country'; 
  63.  
  64. if($req_class != '') { 
  65. $field_class .= " ".$req_class; 
  66.  
  67. if($custom_class != '') { 
  68. $field_class .= " ".$custom_class; 
  69.  
  70. if ( $user_info_group_class != '' ) { 
  71. $field_class .= " ".$user_info_group_class; 
  72.  
  73. if ( $address_class != '' ) { 
  74. $field_class .= " ".$address_class; 
  75.  
  76. if ( isset ( $field_data['input_limit'] ) and $field_data['input_limit'] != '' ) { 
  77. $field_class .= " input-limit"; 
  78.  
  79. return apply_filters( 'ninja_forms_display_field_class', $field_class, $field_id, $field_row );