bp_visibility_is_activity_invisible

Check if the loggedin member can view the activity.

Description

([boolean]) bp_visibility_is_activity_invisible( ([Activity]) $activity, ([int]) $bp_loggedin_user_id, ([boolean]$is_super_admin) $is_super_admin ); 

Returns ([boolean])

Parameters (3)

0. $activity ([Activity])
The activity.
1. $bp_loggedin_user_id ([int])
The bp loggedin user id.
2. $is_super_admin ([boolean]$is_super_admin)
The is super admin.

Usage

  1. if ( !function_exists( 'bp_visibility_is_activity_invisible' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-activity-privacy/includes/bp-activity-privacy-filters.php'; 
  3.  
  4. // The activity. 
  5. $activity = null; 
  6.  
  7. // The bp loggedin user id. 
  8. $bp_loggedin_user_id = null; 
  9.  
  10. // The is super admin. 
  11. $is_super_admin = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_visibility_is_activity_invisible($activity, $bp_loggedin_user_id, $is_super_admin); 
  15.  

Defined (1)

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

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