bp_media_attach_media_to_message( $message )

Attach media to the message object

Description

Parameters

$message

(Required)

Source

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

function bp_media_attach_media_to_message( &$message ) {

	if ( bp_is_messages_media_support_enabled() && ! empty( $message->id ) && ! empty( $_POST['media'] ) ) {
		$media_list = $_POST['media'];
		$media_ids = array();

		foreach ( $media_list as $media_index => $media ) {
			$title         = ! empty( $media['name'] ) ? $media['name'] : ' ';
			$attachment_id = ! empty( $media['id'] ) ? $media['id'] : 0;

			$media_id = bp_media_add(
				array(
					'title'         => $title,
					'privacy'       => 'message',
					'attachment_id' => $attachment_id,
				)
			);

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

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

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

		//save media meta for message
		bp_messages_update_meta( $message->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.