bp_media_get_edit_activity_data( $activity )

Adds activity media data for the edit activity

Description

Parameters

$activity

(Required)

Return

(array) $activity Returns the activity with media if media saved otherwise no media.

Source

File: bp-media/bp-media-filters.php

function bp_media_get_edit_activity_data( $activity ) {

	if ( ! empty( $activity['id'] ) ) {

		$can_edit_privacy = true;

		if ( bp_activity_user_can_edit() ) {

			$privacy                   = $activity['privacy'];
			$media_activity            = ( 'media' === $privacy || ( isset( $_REQUEST['action'] ) && 'media_get_activity' === $_REQUEST['action'] ) );
			$document_activity         = ( 'document' === $privacy || ( isset( $_REQUEST['action'] ) && 'document_get_activity' === $_REQUEST['action'] ) );
			$parent_activity_id        = false;
			$parent_activity_permalink = false;
			$album_id                  = false;
			$album_url                 = '';
			$folder_id                 = false;
			$folder_url                = '';

			// Get media privacy to show.
			if ( bp_is_active( 'media' ) ) {
				if ( $media_activity ) {
					$media_id = BP_Media::get_activity_media_id( $activity['id'] );
					$media    = new BP_Media( $media_id );

					if ( ! empty( $media ) ) {
						$album_id = $media->album_id;
						if ( ! empty( $album_id ) ) {
							$album     = new BP_Media_Album( $album_id );
							$album_url = trailingslashit( bp_core_get_user_domain( $album->user_id ) . bp_get_media_slug() . '/albums/' . $album_id );
						} else {
							$parent_activity_id        = get_post_meta( $media->attachment_id, 'bp_media_parent_activity_id', true );
							$parent_activity_permalink = bp_activity_get_permalink( $parent_activity_id );
						}
					}
				}

				if ( $document_activity ) {
					$document_id = BP_Document::get_activity_document_id( $activity['id'] );
					$document    = new BP_Document( $document_id );
					if ( ! empty( $document ) ) {
						$folder_id = $document->folder_id;

						if ( ! empty( $folder_id ) ) {
							$folder_id  = bp_document_get_root_parent_id( $folder_id );
							$folder     = new BP_Document_Folder( $folder_id );
							$folder_url = trailingslashit( bp_core_get_user_domain( $folder->user_id ) . bp_get_document_slug() . '/folders/' . $folder_id );
						} else {
							$parent_activity_id        = get_post_meta( $document->attachment_id, 'bp_document_parent_activity_id', true );
							$parent_activity_permalink = bp_activity_get_permalink( $parent_activity_id );
						}
					}
				}

				$activity_album_id = bp_activity_get_meta( $activity['id'], 'bp_media_album_activity', true );
				if ( ! empty( $activity_album_id ) ) {
					$album_id       = $activity_album_id;
					$album          = new BP_Media_Album( $album_id );
					$album_url      = trailingslashit( bp_core_get_user_domain( $album->user_id ) . bp_get_media_slug() . '/albums/' . $album_id );
					$media_activity = true;
				}

				$activity_folder_id = bp_activity_get_meta( $activity['id'], 'bp_document_folder_activity', true );
				if ( ! empty( $activity_folder_id ) ) {
					$folder_id         = $activity_folder_id;
					$folder_id         = bp_document_get_root_parent_id( $folder_id );
					$folder            = new BP_Document_Folder( $folder_id );
					$folder_url        = trailingslashit( bp_core_get_user_domain( $folder->user_id ) . bp_get_document_slug() . '/folders/' . $folder_id );
					$document_activity = true;
				}
			}

			if ( $media_activity && ( ( $parent_activity_id && $parent_activity_permalink ) || ( $album_id && ! empty( $album_url ) ) ) ) {
				$can_edit_privacy = false;
			} elseif ( $document_activity && ( ( $parent_activity_id && $parent_activity_permalink ) || ( $folder_id && ! empty( $folder_url ) ) ) ) {
				$can_edit_privacy = false;
			}

		}

		// Fetch media ids of activity.
		$media_ids = bp_activity_get_meta( $activity['id'], 'bp_media_ids', true );

		if ( ! empty( $media_ids ) ) {
			$activity['media'] = array();

			$media_ids = explode( ',', $media_ids );

			foreach( $media_ids as $media_id ) {
				$media = new BP_Media( $media_id );

				$activity['media'][] = array(
					'id'            => $media_id,
					'attachment_id' => $media->attachment_id,
					'thumb'         => wp_get_attachment_image_url( $media->attachment_id, 'bp-media-thumbnail' ),
					'url'           => wp_get_attachment_image_url( $media->attachment_id, 'full' ),
					'name'          => $media->title,
					'group_id'      => $media->group_id,
					'album_id'      => $media->album_id,
					'activity_id'   => $media->activity_id,
					'saved'         => true,
					'menu_order'    => $media->menu_order,
					'can_edit_privacy'      => $can_edit_privacy,
				);
			}
		}

		// Fetch document ids of activity.
		$document_ids = bp_activity_get_meta( $activity['id'], 'bp_document_ids', true );

		if ( ! empty( $document_ids ) ) {
			$activity['document'] = array();

			$document_ids = explode( ',', $document_ids );

			foreach( $document_ids as $document_id ) {
				$document = new BP_Document( $document_id );

				$activity['document'][] = array(
					'id'            => $document_id,
					'doc_id'        => $document->attachment_id,
					'name'          => $document->title,
					'group_id'      => $document->group_id,
					'folder_id'      => $document->folder_id,
					'activity_id'   => $document->activity_id,
					'type'          => 'document',
					'url'           => wp_get_attachment_url( $document->attachment_id ),
					'size'           => filesize( get_attached_file( ( $document->attachment_id ) ) ),
					'saved'         => true,
					'menu_order'    => $document->menu_order,
					'can_edit_privacy'      => $can_edit_privacy,
				);
			}
		}

		// Fetch gif data for the activity.
		$gif_data = bp_activity_get_meta( $activity['id'], '_gif_data', true );

		if ( ! empty( $gif_data ) ) {
			$gif_raw_data                        = (array) bp_activity_get_meta( $activity['id'], '_gif_raw_data', true );
			$gif_raw_data['bp_gif_current_data'] = '1';

			$activity['gif'] = $gif_raw_data;
		}
	}

	return $activity;
}

Changelog

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