LLMS_REST_Courses_Controller::prepare_links( LLMS_Course $course, WP_REST_Request $request )

Prepare links for the request.


Parameters Parameters

$course

(LLMS_Course) (Required) LLMS Course.

$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-courses-controller.php

	}

	/**
	 * Prepare links for the request.
	 *
	 * @since 1.0.0-beta.1
	 * @since 1.0.0-beta.9 Added `llms_rest_course_links` filter hook.
	 * @since 1.0.0-beta.14 Added $request parameter.
	 * @since 1.0.0-beta.18 Fixed access plans link.
	 *
	 * @param LLMS_Course     $course  LLMS Course.
	 * @param WP_REST_Request $request Request object.
	 * @return array Links for the given object.
	 */
	protected function prepare_links( $course, $request ) {

		$links     = parent::prepare_links( $course, $request );
		$course_id = $course->get( 'id' );

		$course_links = array();

		// Access plans.
		$course_links['access_plans'] = array(
			'href' => add_query_arg(
				'post_id',
				$course_id,
				rest_url( sprintf( '%s/%s', 'llms/v1', 'access-plans' ) )
			),
		);

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

		// Instructors.
		$course_links['instructors'] = array(
			'href' => add_query_arg(
				'post',
				$course_id,
				rest_url( sprintf( '%s/%s', 'llms/v1', 'instructors' ) )
			),
		);

		// Prerequisite.
		$prerequisite = $course->get_prerequisite_id();
		if ( ! empty( $prerequisite ) ) {
			$course_links['prerequisites'][] = array(
				'type' => $this->post_type,
				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $prerequisite ) ),
			);
		}

		// Prerequisite track.
		$prerequisite_track = $course->get_prerequisite_id( 'course_track' );
		if ( ! empty( $prerequisite_track ) ) {
			$course_links['prerequisites'][] = array(
				'type' => 'track',
				'href' => rest_url( sprintf( 'wp/v2/%s/%d', 'course_track', $prerequisite_track ) ),
			);
		}

		// Students.
		$course_links['students'] = array(
			'href' => add_query_arg(
				'enrolled_in',
				$course_id,
				rest_url( sprintf( '%s/%s', 'llms/v1', 'students' ) )
			),


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.9 Added llms_rest_course_links filter hook.
1.0.0-beta.18 Fixed access plans link.
1.0.0-beta.14 Added $request parameter.
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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