bp_is_active

Check whether a given component (or feature of a component) is active.

Description

bp_is_active( (string) $component = '', (string) $feature = '' ); 

Parameters (2)

0. $component — Optional. (string) => ''
The component name.
1. $feature — Optional. (string) => ''
The feature name.

Usage

  1. if ( !function_exists( 'bp_is_active' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template.php'; 
  3.  
  4. // The component name. 
  5. $component = ''; 
  6.  
  7. // The feature name. 
  8. $feature = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_is_active($component, $feature); 
  12.  

Defined (1)

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

/bp-core/bp-core-template.php  
  1. function bp_is_active( $component = '', $feature = '' ) { 
  2. $retval = false; 
  3.  
  4. // Default to the current component if none is passed. 
  5. if ( empty( $component ) ) { 
  6. $component = bp_current_component(); 
  7.  
  8. // Is component in either the active or required components arrays. 
  9. if ( isset(buddypress)->active_components[ $component ] ) || isset(buddypress)->required_components[ $component ] ) ) { 
  10. $retval = true; 
  11.  
  12. // Is feature active? 
  13. if ( ! empty( $feature ) ) { 
  14. // The xProfile component is specific. 
  15. if ( 'xprofile' === $component ) { 
  16. $component = 'profile'; 
  17.  
  18. if ( empty(buddypress)->$component->features ) || false === in_array( $feature,buddypress)->$component->features, true ) ) { 
  19. $retval = false; 
  20.  
  21. /** 
  22. * Filters whether or not a given feature for a component is active. 
  23. * This is a variable filter that is based on the component and feature 
  24. * that you are checking of active status of. 
  25. * @since 2.3.0 
  26. * @param bool $retval 
  27. */ 
  28. $retval = apply_filters( "bp_is_{$component}_{$feature}_active", $retval ); 
  29.  
  30. /** 
  31. * Filters whether or not a given component has been activated by the admin. 
  32. * @since 2.1.0 
  33. * @param bool $retval Whether or not a given component has been activated by the admin. 
  34. * @param string $component Current component being checked. 
  35. */ 
  36. return apply_filters( 'bp_is_active', $retval, $component );