bp_media_update_media_meta( $content,  $user_id,  $activity_id )

Update media for activity

Description

Parameters

$content

(Required)

$user_id

(Required)

$activity_id

(Required)

Return

(bool)

Source

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

function bp_media_update_media_meta( $content, $user_id, $activity_id ) {

	if ( ! isset( $_POST['media'] ) || empty( $_POST['media'] ) ) {
		return false;
	}

	$media_list = $_POST['media'];

	if ( ! empty( $media_list ) ) {
		$media_ids = array();
		foreach ( $media_list as $media_index => $media ) {

			// remove actions to avoid infinity loop
			remove_action( 'bp_activity_posted_update', 'bp_media_update_media_meta', 10, 3 );
			remove_action( 'bp_groups_posted_update', 'bp_media_groups_update_media_meta', 10, 4 );

			// make an activity for the media
			$a_id = bp_activity_post_update( array( 'hide_sitewide' => true, 'privacy' => 'media' ) );

			if ( $a_id ) {
				// update activity meta
				bp_activity_update_meta( $a_id, 'bp_media_activity', '1' );
			}

			add_action( 'bp_activity_posted_update', 'bp_media_update_media_meta', 10, 3 );
			add_action( 'bp_groups_posted_update', 'bp_media_groups_update_media_meta', 10, 4 );

			$title         = ! empty( $media['name'] ) ? $media['name'] : ' ';
			$album_id      = ! empty( $media['album_id'] ) ? $media['album_id'] : 0;
			$privacy       = ! empty( $media['privacy'] ) ? $media['privacy'] : 'public';
			$attachment_id = ! empty( $media['id'] ) ? $media['id'] : 0;
			$menu_order    = ! empty( $media['menu_order'] ) ? $media['menu_order'] : $media_index;

			$media_id = bp_media_add(
				array(
					'title'         => $title,
					'album_id'      => $album_id,
					'activity_id'   => $a_id,
					'privacy'       => $privacy,
					'attachment_id' => $attachment_id,
					'menu_order'    => $menu_order,
				)
			);

			if ( $media_id ) {
				$media_ids[] = $media_id;

				//save media is saved in attahchment
				update_post_meta( $attachment_id, 'bp_media_saved', true );

				//save media meta for activity
				if ( ! empty( $activity_id ) && ! empty( $attachment_id ) ) {
					update_post_meta( $attachment_id, 'bp_media_parent_activity_id', $activity_id );
					update_post_meta( $attachment_id, 'bp_media_activity_id', $a_id );
				}
			}
		}

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

		//save media meta for activity
		if ( ! empty( $activity_id ) ) {
			bp_activity_update_meta( $activity_id, 'bp_media_ids', $media_ids );
		}
	}
}

Changelog

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