BP_REST_Media_Endpoint::bp_media_ids_update_rest_field_callback_messages( object $object, object $value, string $attribute )

The function to use to update the medias’s value of the messages REST Field.




(object) (Required) The BuddyPress component's object that was just created/updated during the request. (in this case the BP_Messages_Message object).


(object) (Required) The value of the REST Field to save.


(string) (Required) The REST Field key used into the REST response.




File: bp-media/classes/class-bp-rest-media-endpoint.php

	protected function bp_media_ids_update_rest_field_callback_messages( $object, $value, $attribute ) {

		if ( 'bp_media_ids' !== $attribute || empty( $object ) ) {
			$value->bp_media_ids = null;
			return $value;

		$message_id = $value->id;

		$medias = wp_parse_id_list( $object );
		if ( empty( $medias ) ) {
			$value->bp_media_ids = null;
			return $value;

		$args = array(
			'upload_ids' => $medias,
			'privacy'    => 'message',

		$medias_ids = $this->bp_rest_create_media( $args );

		if ( is_wp_error( $medias_ids ) ) {
			$value->bp_media_ids = $medias_ids;
			return $value;

		bp_messages_update_meta( $message_id, 'bp_media_ids', implode( ',', $medias_ids ) );


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.