bp_activity_user_can_read( BP_Activity_Activity $activity, integer $user_id )

Can a user see a particular activity item?


Parameters Parameters

$activity

(BP_Activity_Activity) (Required) Activity object.

$user_id

(integer) (Required) User ID.


Top ↑

Return Return

(boolean) True on success, false on failure.


Source 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 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 );
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.