bp_visibility_activity_filter

The BuddyPress Activity Privacy bp visibility activity filter function.

Description

bp_visibility_activity_filter( ([type]) $has_activities, ([type]) $activities ); 

Parameters (2)

0. $has_activities ([type])
The has activities.
1. $activities ([type])
The activities.

Usage

  1. if ( !function_exists( 'bp_visibility_activity_filter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-activity-privacy/includes/bp-activity-privacy-filters.php'; 
  3.  
  4. // The has activities. 
  5. $has_activities = null; 
  6.  
  7. // The activities. 
  8. $activities = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_visibility_activity_filter($has_activities, $activities); 
  12.  

Defined (1)

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

/includes/bp-activity-privacy-filters.php  
  1. function bp_visibility_activity_filter( $has_activities, $activities ) { 
  2. global $bp; 
  3.  
  4. $is_super_admin = is_super_admin(); 
  5. $bp_displayed_user_id = bp_displayed_user_id(); 
  6. $bp_loggedin_user_id = bp_loggedin_user_id(); 
  7.  
  8. foreach ( $activities->activities as $key => $activity ) { 
  9.  
  10. /** 
  11. if( $bp_loggedin_user_id == $activity->user_id )  
  12. continue; 
  13.   
  14. $visibility = bp_activity_get_meta( $activity->id, 'activity-privacy' ); 
  15. $remove_from_stream = false; 
  16.  
  17.   
  18. switch ( $visibility ) { 
  19. //Logged in users 
  20. case 'loggedin' : 
  21. if( !$bp_loggedin_user_id ) 
  22. $remove_from_stream = true; 
  23. break; 
  24.   
  25. //My friends  
  26. case 'friends' : 
  27. if ( bp_is_active( 'friends' ) ) { 
  28. $is_friend = friends_check_friendship( $bp_loggedin_user_id, $activity->user_id ); 
  29. if( !$is_friend ) 
  30. $remove_from_stream = true; 
  31. break;  
  32.   
  33. //@Mentioned Only  
  34. case 'mentionedonly' : 
  35. $usernames = bp_activity_find_mentions( $activity->content ); 
  36. $is_mentioned = array_key_exists( $bp_loggedin_user_id, (array)$usernames ); 
  37.   
  38. if( !$is_mentioned ) 
  39. $remove_from_stream = true; 
  40. break;  
  41.   
  42. //My friends in the group  
  43. case 'groupfriends' : 
  44. if ( bp_is_active( 'friends' ) ) { 
  45. $is_friend = friends_check_friendship( $bp_loggedin_user_id, $activity->user_id ); 
  46. } else  
  47. $is_friend = true; 
  48.   
  49. if ( bp_is_active( 'groups' ) ) {  
  50. $group_is_user_member = groups_is_user_member( $bp_loggedin_user_id, $activity->item_id ); 
  51. } else  
  52. return true; 
  53.   
  54. if( !$is_friend || !$group_is_user_member) 
  55. $remove_from_stream = true; 
  56. break;  
  57.   
  58. //Only group members  
  59. case 'grouponly' : 
  60. $group_is_user_member = groups_is_user_member( $bp_loggedin_user_id, $activity->item_id ); 
  61. if( !$group_is_user_member ) 
  62. $remove_from_stream = true; 
  63. break;  
  64.   
  65. //Only group moderators  
  66. case 'groupmoderators' : 
  67. $group_is_user_mod = groups_is_user_mod( $bp_loggedin_user_id, $activity->item_id ); 
  68. if( !$group_is_user_mod ) 
  69. $remove_from_stream = true; 
  70. break;  
  71.   
  72. //Only group admins  
  73. case 'groupadmins' : 
  74. $group_is_user_admin = groups_is_user_admin( $bp_loggedin_user_id, $activity->item_id ); 
  75. if( !$group_is_user_admin ) 
  76. $remove_from_stream = true; 
  77. break;  
  78.   
  79. //Only Admins  
  80. case 'adminsonly' : 
  81. if( !$is_super_admin ) 
  82. $remove_from_stream = true; 
  83. break;  
  84.   
  85. //Only Me  
  86. case 'onlyme' : 
  87. if( $bp_loggedin_user_id != $activity->user_id ) 
  88. $remove_from_stream = true; 
  89. break;  
  90.   
  91. default: 
  92. //public  
  93. break; 
  94.   
  95. // mentioned members can always see the acitivity whatever the privacy level 
  96. if ( $visibility != 'mentionedonly' && $bp_loggedin_user_id && $remove_from_stream ) { 
  97. $usernames = bp_activity_find_mentions( $activity->content ); 
  98. $is_mentioned = array_key_exists( $bp_loggedin_user_id, (array)$usernames ); 
  99. if( $is_mentioned ) { 
  100. $remove_from_stream = false; 
  101.  
  102. $remove_from_stream = apply_filters( 'bp_more_visibility_activity_filter', $remove_from_stream, $visibility, $activity); 
  103. */ 
  104.  
  105. $remove_from_stream = bp_visibility_is_activity_invisible( $activity, $bp_loggedin_user_id, $is_super_admin ); 
  106.  
  107. if ( $remove_from_stream && isset( $activities->activity_count ) ) { 
  108. $activities->activity_count = $activities->activity_count - 1; 
  109. unset( $activities->activities[$key] ); 
  110.  
  111. $activities_new = array_values( $activities->activities ); 
  112. $activities->activities = $activities_new; 
  113.  
  114. return $has_activities;