bp_activity_user_can_read( BP_Activity_Activity $activity, integer $user_id )
Can a user see a particular activity item?
Description
Parameters
- $activity
-
(Required) Activity object.
- $user_id
-
(Required) User ID.
Return
(boolean) True on success, false on failure.
Source
File: bp-activity/bp-activity-functions.php
function bp_activity_user_can_read( $activity, $user_id = 0 ) { $retval = true; // Fallback. if ( empty( $user_id ) ) { $user_id = bp_loggedin_user_id(); } // If activity is from a group, do extra cap checks. if ( bp_is_active( 'groups' ) && buddypress()->groups->id === $activity->component ) { // Check to see if the user has access to the activity's parent group. $group = groups_get_group( $activity->item_id ); if ( $group ) { // For logged-in user, we can check against the 'user_has_access' prop. if ( bp_loggedin_user_id() === $user_id ) { $retval = $group->user_has_access; // Manually check status. } elseif ( 'private' === $group->status || 'hidden' === $group->status ) { // Only group members that are not banned can view. if ( ! groups_is_user_member( $user_id, $activity->item_id ) || groups_is_user_banned( $user_id, $activity->item_id ) ) { $retval = false; } } } } // Spammed items are not visible to the public. if ( $activity->is_spam ) { $retval = false; } // Site moderators can view anything. if ( bp_current_user_can( 'bp_moderate' ) ) { $retval = true; } /** * Filters whether the current user has access to an activity item. * * @since BuddyPress 3.0.0 * * @param bool $retval Return value. * @param int $user_id Current user ID. * @param BP_Activity_Activity $activity Activity object. */ return apply_filters( 'bp_activity_user_can_read', $retval, $user_id, $activity ); }
Changelog
Version | Description |
---|---|
BuddyPress 3.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.