bp_get_field_css_class

Return the class attribute for a field.

Description

(string) bp_get_field_css_class( (bool) $class = false ); 

Returns (string)

Parameters (1)

0. $class — Optional. (bool) => false
Extra classes to append to class attribute.

Usage

  1. if ( !function_exists( 'bp_get_field_css_class' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-xprofile/bp-xprofile-template.php'; 
  3.  
  4. // Extra classes to append to class attribute. 
  5. $class = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_field_css_class($class); 
  9.  

Defined (1)

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

/bp-xprofile/bp-xprofile-template.php  
  1. function bp_get_field_css_class( $class = false ) { 
  2. global $profile_template; 
  3.  
  4. $css_classes = array(); 
  5.  
  6. if ( ! empty( $class ) ) { 
  7. if ( ! is_array( $class ) ) { 
  8. $class = preg_split( '#\s+#', $class ); 
  9. $css_classes = array_map( 'sanitize_html_class', $class ); 
  10.  
  11. // Set a class with the field ID. 
  12. $css_classes[] = 'field_' . $profile_template->field->id; 
  13.  
  14. // Set a class with the field name (sanitized). 
  15. $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); 
  16.  
  17. // Set a class indicating whether the field is required or optional. 
  18. if ( ! empty( $profile_template->field->is_required ) ) { 
  19. $css_classes[] = 'required-field'; 
  20. } else { 
  21. $css_classes[] = 'optional-field'; 
  22.  
  23. // Add the field visibility level. 
  24. $css_classes[] = 'visibility-' . esc_attr( bp_get_the_profile_field_visibility_level() ); 
  25.  
  26. if ( $profile_template->current_field % 2 == 1 ) { 
  27. $css_classes[] = 'alt'; 
  28.  
  29. $css_classes[] = 'field_type_' . sanitize_title( $profile_template->field->type ); 
  30.  
  31. /** 
  32. * Filters the field classes to be applied to a field. 
  33. * @since 1.1.0 
  34. * @param array $css_classes Array of classes to be applied to field. Passed by reference. 
  35. */ 
  36. $css_classes = apply_filters_ref_array( 'bp_field_css_classes', array( &$css_classes ) ); 
  37.  
  38. /** 
  39. * Filters the class HTML attribute to be used on a field. 
  40. * @since 1.1.0 
  41. * @param string $value class HTML attribute with imploded classes. 
  42. */ 
  43. return apply_filters( 'bp_get_field_css_class', ' class="' . implode( ' ', $css_classes ) . '"' );