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

	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.