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

2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
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.