LLMS_REST_Memberships_Controller::prepare_links( LLMS_Membership $membership, WP_REST_Request $request )

Prepare links for the request.


Parameters Parameters

$membership

(LLMS_Membership) (Required) LLMS Membership.

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(array) Links for the given object.


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/server/class-llms-rest-memberships-controller.php

	protected function prepare_links( $membership, $request ) {

		$links = parent::prepare_links( $membership, $request );
		unset( $links['content'] );
		$id = $membership->get( 'id' );

		// Access plans.
		$links['access_plans'] = array(
			'href' => add_query_arg(
				'post_id',
				$id,
				rest_url( sprintf( '%s/%s', $this->namespace, 'access-plans' ) )
			),
		);

		// Auto enrollment courses.
		$auto_enroll_courses = implode( ',', $membership->get_auto_enroll_courses() );
		if ( $auto_enroll_courses ) {
			$links['auto_enrollment_courses'] = array(
				'href' => add_query_arg(
					'include',
					$auto_enroll_courses,
					rest_url( sprintf( '%s/%s', $this->namespace, 'courses' ) )
				),
			);
		}

		// Enrollments.
		$links['enrollments'] = array(
			'href' => rest_url( sprintf( '/%s/%s/%d/%s', $this->namespace, $this->rest_base, $id, 'enrollments' ) ),
		);

		// Instructors.
		$links['instructors'] = array(
			'href' => add_query_arg(
				'post',
				$id,
				rest_url( sprintf( '%s/%s', $this->namespace, 'instructors' ) )
			),
		);

		// Students.
		$links['students'] = array(
			'href' => add_query_arg(
				'enrolled_in',
				$id,
				rest_url( sprintf( '%s/%s', $this->namespace, 'students' ) )
			),
		);

		/**
		 * Filters the membership's links.
		 *
		 * @since 1.0.0-beta.9
		 *
		 * @param array           $links      Links for the given membership.
		 * @param LLMS_Membership $membership LLMS Membership object.
		 */
		$links = apply_filters( 'llms_rest_membership_links', $links, $membership );

		return $links;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.9
1.0.0-beta.18 Fixed access plans link.
1.0.0-beta.14 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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