BP_Document_Privacy::is_document_visible( bool $document_id = false )

Check if document is visible or not to the logged in user

Description

Parameters

$document_id

(bool) (Optional)

Default value: false

Return

(bool|mixed|WP_Error)

Source

File: bp-document/classes/class-bp-document-privacy.php

	public function is_document_visible( $document_id = false ) {
		$result = bp_document_get_specific( array( 'document_ids' => $document_id ) );

		if ( empty( $result['documents'] ) || empty( $result['documents'][0] ) ) {
			return new WP_Error( 'no_document', __( 'There is no document.', 'buddyboss' ), array( 'status' => 500 ) );
		}

		$document   = $result['documents'][0];
		$visibility = $document->privacy;
		$visible    = true;

		if ( bp_loggedin_user_id() != $document->user_id ) {

			switch ( $visibility ) {
				// Logged in users.
				case 'loggedin':
					if ( ! bp_loggedin_user_id() ) {
						$visible = false;
					}
					break;

				// My friends.
				case 'friends':
					if ( bp_is_active( 'friends' ) ) {
						$is_friend = friends_check_friendship( bp_loggedin_user_id(), $document->user_id );
						if ( ! $is_friend ) {
							$visible = false;
						}
					}
					break;

				// Only group members.
				case 'grouponly':
					if ( bp_is_active( 'groups' ) ) {
						$group_is_user_member = groups_is_user_member( bp_loggedin_user_id(), $document->activity_id );
						if ( ! $group_is_user_member ) {
							$visible = false;
						}
					}
					break;

				// Only Me.
				case 'onlyme':
					if ( bp_loggedin_user_id() != $document->user_id ) {
						$visible = false;
					}
					break;

				default:
					// public.
					break;
			}
		}

		if ( is_super_admin() ) {
			$visible = true;
		}

		return apply_filters( 'bp_document_is_document_visible', $visible, $visibility, $document_id );
	}

Changelog

Changelog
Version Description
BuddyBoss 1.4.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.