BP_REST_Media_Endpoint::bbp_media_get_rest_field_callback( array $post, string $attribute )

The function to use to get medias of the topic REST Field.

Description

Parameters

$post

(Required) WP_Post object as array.

$attribute

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

Return

(string) The value of the REST Field to include into the REST response.

Source

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

	protected function bbp_media_get_rest_field_callback( $post, $attribute ) {

		$p_id = $post['id'];

		if ( empty( $p_id ) ) {
			return;
		}

		$media_ids = get_post_meta( $p_id, 'bp_media_ids', true );
		$media_ids = trim( $media_ids );
		$media_ids = explode( ',', $media_ids );

		if ( empty( $media_ids ) ) {
			return;
		}

		$medias = $this->assemble_response_data( array( 'media_ids' => $media_ids ) );

		if ( empty( $medias['medias'] ) ) {
			return;
		}

		$retval = array();
		foreach ( $medias['medias'] as $media ) {
			$retval[] = array(
				'id'    => $media->id,
				'full'  => wp_get_attachment_image_url( $media->attachment_id, 'full' ),
				'thumb' => wp_get_attachment_image_url( $media->attachment_id, 'bp-media-thumbnail' ),
			);
		}

		return $retval;
	}

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.