BP_REST_Blogs_Endpoint::prepare_item_for_response( BP_Blogs_Blog $blog, WP_REST_Request $request )

Prepares blogs data for return as an object.

Description

Parameters

$blog

(Required) Blog object.

$request

(Required) Full details about the request.

Return

(WP_REST_Response)

Source

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

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
public function prepare_item_for_response( $blog, $request ) {
    $data = array(
        'id'            => $blog->blog_id,
        'user_id'       => $blog->admin_user_id,
        'name'          => $blog->name,
        'domain'        => $blog->domain,
        'path'          => $blog->path,
        'permalink'     => $this->get_blog_domain( $blog ),
        'description'   => stripslashes( $blog->description ),
        'last_activity' => bp_rest_prepare_date_response( $blog->last_activity ),
    );
 
    // Get item schema.
    $schema = $this->get_item_schema();
 
    // Blog Avatars.
    if ( ! empty( $schema['properties']['avatar_urls'] ) ) {
        $data['avatar_urls'] = array(
            'thumb' => bp_get_blog_avatar(
                array(
                    'type'          => 'thumb',
                    'blog_id'       => $blog->blog_id,
                    'admin_user_id' => $blog->admin_user_id,
                )
            ),
            'full'  => bp_get_blog_avatar(
                array(
                    'type'          => 'full',
                    'blog_id'       => $blog->blog_id,
                    'admin_user_id' => $blog->admin_user_id,
                )
            ),
        );
    }
 
    $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
    $data    = $this->add_additional_fields_to_object( $data, $request );
    $data    = $this->filter_response_by_context( $data, $context );
 
    $response = rest_ensure_response( $data );
    $response->add_links( $this->prepare_links( $blog ) );
 
    /**
     * Filter a blog returned from the API.
     *
     * @param WP_REST_Response $response Response generated by the request.
     * @param WP_REST_Request  $request  Request used to generate the response.
     * @param BP_Blogs_Blog    $blog     The blog object.
     *
     * @since 0.1.0
     */
    return apply_filters( 'bp_rest_blogs_prepare_value', $response, $request, $blog );
}

Changelog

Changelog
Version Description
0.1.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.