ninja_forms_get_field_wrap_class

The next two functions are used to get CSS class names based upon field settings.

Description

ninja_forms_get_field_wrap_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_wrap_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_wrap_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_wrap_class( $field_id, $form_id = '' ) { 
  2. global $ninja_forms_loading, $ninja_forms_processing; 
  3. $field_wrap_class = 'field-wrap'; 
  4.  
  5. if ( '' == $form_id ) { 
  6. $field = ninja_forms_get_field_by_id( $field_id ); 
  7. $form_id = $field['form_id']; 
  8.  
  9. if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { 
  10. $field_row = $ninja_forms_loading->get_field_settings( $field_id ); 
  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.  
  14. $form_id = $field_row['form_id']; 
  15. $data = $field_row['data']; 
  16.  
  17. if ( isset ( $field_row['type'] ) ) { 
  18. $type_slug = $field_row['type']; 
  19. } else { 
  20. $type_slug = ''; 
  21.  
  22. if(strpos($type_slug, "_") === 0) { 
  23. $type_slug = substr($type_slug, 1); 
  24.  
  25. $field_wrap_class .= " ".$type_slug."-wrap"; 
  26. if(isset($data['label_pos'])) { 
  27. $label_pos = $data['label_pos']; 
  28. }else{ 
  29. $label_pos = 'above'; 
  30. $field_wrap_class .= " label-".$label_pos; 
  31.  
  32. $x = 0; 
  33. $custom_class = ''; 
  34.  
  35. if(isset($data['class']) AND !empty($data['class'])) { 
  36. $class_array = explode(", ", $data['class']); 
  37. foreach($class_array as $class) { 
  38. $custom_class .= $class; 
  39. if($x != (count($class_array) - 1)) { 
  40. $custom_class .= " "; 
  41. $x++; 
  42.  
  43. if($custom_class != '') { 
  44. $custom_class = str_replace( ' ', '-wrap ', $custom_class ); 
  45. $field_wrap_class .= ' '.$custom_class.'-wrap'; 
  46.  
  47. if( is_object( $ninja_forms_processing) AND is_array($ninja_forms_processing->get_errors_by_location($field_id))) { 
  48. foreach($ninja_forms_processing->get_errors_by_location($field_id) as $error) { 
  49. $field_wrap_class .= ' ninja-forms-error'; 
  50. break; 
  51. return apply_filters( 'ninja_forms_display_field_wrap_class', $field_wrap_class, $field_id, $field_row );