bp_activity_create_parent_media_activity( $media_ids )

Create main activity for the media uploaded and saved.

Description

Parameters

$media_ids

(Required)

Return

(mixed)

Source

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

function bp_activity_create_parent_media_activity( $media_ids ) {
	global $bp_media_upload_count;

	if ( ! empty( $media_ids ) && ! isset( $_POST['bp_activity_update'] ) ) {

		$added_media_ids = $media_ids;
		$content         = false;

		if ( ! empty( $_POST['content'] ) ) {

			/**
			 * Filters the content provided in the activity input field.
			 *
			 * @param string $value Activity message being posted.
			 *
			 * @since BuddyPress 1.2.0
			 *
			 */
			$content = apply_filters( 'bp_activity_post_update_content', $_POST['content'] );
		}

		$group_id = FILTER_INPUT( INPUT_POST, 'group_id', FILTER_SANITIZE_NUMBER_INT );
		$album_id = false;

		if ( bp_is_active( 'groups' ) && ! empty( $group_id ) && $group_id > 0 ) {
			$activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $group_id ) );
		} else {
			$activity_id = bp_activity_post_update( array( 'content' => $content ) );
		}

		//save media meta for activity
		if ( ! empty( $activity_id ) ) {
			$privacy = 'public';

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

				// get one of the media's privacy for the activity privacy
				$privacy = $media->privacy;

				// get media album id
				if ( ! empty( $media->album_id ) ) {
					$album_id = $media->album_id;
				}

				if ( 1 === $bp_media_upload_count ) {
					//save media activity id in media
					$media->activity_id = $activity_id;
					$media->save();
				}

				//save parent activity id in attachment meta
				update_post_meta( $media->attachment_id, 'bp_media_parent_activity_id', $activity_id );
			}

			bp_activity_update_meta( $activity_id, 'bp_media_ids', implode( ',', $added_media_ids ) );

			// if media is from album then save album id in activity media
			if ( ! empty( $album_id ) ) {
				bp_activity_update_meta( $activity_id, 'bp_media_album_activity', $album_id );
			}

			if ( empty( $group_id ) ) {
				$main_activity = new BP_Activity_Activity( $activity_id );
				if ( ! empty( $main_activity ) ) {
					$main_activity->privacy = $privacy;
					$main_activity->save();
				}
			}
		}
	}

	return $media_ids;
}

Changelog

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