BP_REST_Activity_Endpoint::prepare_links( BP_Activity_Activity $activity )

Prepare links for the request.


Parameters Parameters

$activity

(BP_Activity_Activity) (Required) Activity object.


Top ↑

Return Return

(array)


Source Source

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

	protected function prepare_links( $activity ) {
		$base = sprintf( '/%s/%s/', $this->namespace, $this->rest_base );
		$url  = $base . $activity->id;

		// Entity meta.
		$links = array(
			'self'       => array(
				'href' => rest_url( $url ),
			),
			'collection' => array(
				'href' => rest_url( $base ),
			),
			'user'       => array(
				'href'       => rest_url( bp_rest_get_user_url( $activity->user_id ) ),
				'embeddable' => true,
			),
		);

		if ( 'activity_comment' === $activity->type ) {
			$links['up'] = array(
				'href' => rest_url( $url ),
			);
		}

		if ( bp_activity_can_favorite() ) {
			$links['favorite'] = array(
				'href' => rest_url( $url . '/favorite' ),
			);
		}

		// Embed Group.
		if ( bp_is_active( 'groups' ) && 'groups' === $activity->component && ! empty( $activity->item_id ) ) {
			$links['group'] = array(
				'href'       => rest_url(
					sprintf(
						'/%s/%s/%d',
						$this->namespace,
						buddypress()->groups->id,
						absint( $activity->item_id )
					)
				),
				'embeddable' => true,
			);
		}

		// Embed Blog.
		if ( bp_is_active( 'blogs' ) && 'blogs' === $activity->component && ! empty( $activity->item_id ) ) {
			$links['blog'] = array(
				'href'       => rest_url(
					sprintf(
						'/%s/%s/%d',
						$this->namespace,
						buddypress()->blogs->id,
						absint( $activity->item_id )
					)
				),
				'embeddable' => true,
			);
		}

		/**
		 * Filter links prepared for the REST response.
		 *
		 * @since 5.0.0
		 *
		 * @param array                $links     The prepared links of the REST response.
		 * @param BP_Activity_Activity $activity  Activity object.
		 */
		return apply_filters( 'bp_rest_activity_prepare_links', $links, $activity );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.