_bp_core_inject_bp_widget_css_class

Injects specific BuddyPress CSS classes into a widget sidebar.

Description

(array) _bp_core_inject_bp_widget_css_class( (array) $params ); 

Helps to standardize styling of BuddyPress widgets within a theme that does not use dynamic CSS classes in their widget sidebar's before_widget call.

Returns (array)

Parameters (1)

0. $params (array)
Current sidebar params.

Usage

  1. if ( !function_exists( '_bp_core_inject_bp_widget_css_class' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // Current sidebar params. 
  5. $params = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _bp_core_inject_bp_widget_css_class($params); 
  9.  

Defined (1)

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

/bp-core/bp-core-filters.php  
  1. function _bp_core_inject_bp_widget_css_class( $params ) { 
  2. global $wp_registered_widgets; 
  3.  
  4. $widget_id = $params[0]['widget_id']; 
  5.  
  6. // If callback isn't an array, bail. 
  7. if ( false === is_array( $wp_registered_widgets[ $widget_id ]['callback'] ) ) { 
  8. return $params; 
  9.  
  10. // If the current widget isn't a BuddyPress one, stop! 
  11. // We determine if a widget is a BuddyPress widget, if the widget class 
  12. // begins with 'bp_'. 
  13. if ( 0 !== strpos( $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base, 'bp_' ) ) { 
  14. return $params; 
  15.  
  16. // Dynamically add our widget CSS classes for BP widgets if not already there. 
  17. $classes = array(); 
  18.  
  19. // Try to find 'widget' CSS class. 
  20. if ( false === strpos( $params[0]['before_widget'], 'widget ' ) ) { 
  21. $classes[] = 'widget'; 
  22.  
  23. // Try to find buddypress CSS class. 
  24. if ( false === strpos( $params[0]['before_widget'], 'buddypress ) ) { 
  25. $classes[] = buddypress; 
  26.  
  27. // Stop if widget already has our CSS classes. 
  28. if ( empty( $classes ) ) { 
  29. return $params; 
  30.  
  31. // CSS injection time! 
  32. $params[0]['before_widget'] = str_replace( 'class="', 'class="' . implode( ' ', $classes ) . ' ', $params[0]['before_widget'] ); 
  33.  
  34. return $params;