BP_REST_Activity_Endpoint::prepare_links( BP_Activity_Activity $activity )

Prepare links for the request.


Description Description


Parameters Parameters

$activity

(Required) Activity object.


Top ↑

Return Return

(array)


Top ↑

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' ),
			);
		}

		if ( bp_is_active( 'groups' ) && 'groups' === $activity->component && ! empty( $activity->item_id ) ) {
			$group = groups_get_group( $activity->item_id );

			$links['group'] = array(
				'href'       => bp_get_group_permalink( $group ),
				'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.