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

1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
}
 
/**
 * 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.