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

793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
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.