bp_get_activity_show_filters

Get available filters depending on the scope.

Description

(string) bp_get_activity_show_filters( (string) $context = '' ); 

Returns (string)

HTML for

Parameters (1)

0. $context — Optional. (string) => ''
The current context. activity,, member., member_groups, group.

Usage

  1. if ( !function_exists( 'bp_get_activity_show_filters' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-template.php'; 
  3.  
  4. // The current context. 'activity', 'member', 
  5. // 'member_groups', 'group'. 
  6. $context = ''; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_get_activity_show_filters($context); 
  10.  

Defined (1)

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

/bp-activity/bp-activity-template.php  
  1. function bp_get_activity_show_filters( $context = '' ) { 
  2. // Set default context based on current page. 
  3. if ( empty( $context ) ) { 
  4.  
  5. // On member pages, default to 'member', unless this 
  6. // is a user's Groups activity. 
  7. if ( bp_is_user() ) { 
  8. if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) { 
  9. $context = 'member_groups'; 
  10. } else { 
  11. $context = 'member'; 
  12.  
  13. // On individual group pages, default to 'group'. 
  14. } elseif ( bp_is_active( 'groups' ) && bp_is_group() ) { 
  15. $context = 'group'; 
  16.  
  17. // 'activity' everywhere else. 
  18. } else { 
  19. $context = 'activity'; 
  20.  
  21. $filters = array(); 
  22.  
  23. // Walk through the registered actions, and prepare an the 
  24. // select box options. 
  25. foreach ( bp_activity_get_actions() as $actions ) { 
  26. foreach ( $actions as $action ) { 
  27. if ( ! in_array( $context, (array) $action['context'] ) ) { 
  28. continue; 
  29.  
  30. // Friends activity collapses two filters into one. 
  31. if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) { 
  32. $action['key'] = 'friendship_accepted, friendship_created'; 
  33.  
  34. $filters[ $action['key'] ] = $action['label']; 
  35.  
  36. /** 
  37. * Filters the options available in the activity filter dropdown. 
  38. * @since 2.2.0 
  39. * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name. 
  40. * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'. 
  41. */ 
  42. $filters = apply_filters( 'bp_get_activity_show_filters_options', $filters, $context ); 
  43.  
  44. // Build the options output. 
  45. $output = ''; 
  46.  
  47. if ( ! empty( $filters ) ) { 
  48. foreach ( $filters as $value => $filter ) { 
  49. $output .= '<option value="' . esc_attr( $value ) . '">' . esc_html( $filter ) . '</option>' . "\n"; 
  50.  
  51. /** 
  52. * Filters the HTML markup result for the activity filter dropdown. 
  53. * @since 2.1.0 
  54. * @param string $output HTML output for the activity filter dropdown. 
  55. * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name. 
  56. * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'. 
  57. */ 
  58. return apply_filters( 'bp_get_activity_show_filters', $output, $filters, $context );