LLMS_REST_Courses_Controller::prepare_object_for_response( LLMS_Course $course, WP_REST_Request $request )
Prepare a single object output for response.
Parameters Parameters
- $course
-
(LLMS_Course) (Required) Course object.
- $request
-
(WP_REST_Request) (Required) Full details about the request.
Return Return
(array)
Source Source
File: libraries/lifterlms-rest/includes/server/class-llms-rest-courses-controller.php
/** * Prepare a single object output for response. * * @since 1.0.0-beta.1 * @since 1.0.0-beta.8 Fixed `sales_page_type` not set as `none` if course's `sales_page_content_type` property is empty. * Also Renamed `sales_page_page_type` and `sales_page_page_url` properties, respectively to `sales_page_type` and `sales_page_url` according to the specs. * Always return `sales_page_url` and `sales_page_page_id` when in `edit` context. * @since 1.0.0-beta.9 Fixed `sales_page_url` not returned in `edit` context. * Added `llms_rest_prepare_course_object_response` filter hook. * * @param LLMS_Course $course Course object. * @param WP_REST_Request $request Full details about the request. * @return array */ protected function prepare_object_for_response( $course, $request ) { $data = parent::prepare_object_for_response( $course, $request ); // Catalog visibility. $data['catalog_visibility'] = $course->get_product()->get_catalog_visibility(); // Categories. $data['categories'] = $course->get_categories( array( 'fields' => 'ids', ) ); // Tags. $data['tags'] = $course->get_tags( array( 'fields' => 'ids', ) ); // Difficulties. $difficulties = $course->get_difficulty( 'term_id' ); $difficulties = empty( $difficulties ) ? array() : array( $difficulties ); $data['difficulties'] = $difficulties; // Tracks. $data['tracks'] = $course->get_tracks( array( 'fields' => 'ids', ) ); // Instructors. $instructors = $course->get_instructors(); $instructors = empty( $instructors ) ? array() : wp_list_pluck( $instructors, 'id' ); $data['instructors'] = $instructors; // Audio Embed. $data['audio_embed'] = $course->get( 'audio_embed' ); // Video Embed. $data['video_embed'] = $course->get( 'video_embed' ); // Video tile. $data['video_tile'] = 'yes' === $course->get( 'tile_featured_video' ); // Capacity. $data['capacity_enabled'] = 'yes' === $course->get( 'enable_capacity' ); $data['capacity_limit'] = $course->get( 'capacity' ); $data['capacity_message'] = array( 'raw' => $course->get( 'capacity_message', $raw = true ), 'rendered' => do_shortcode( $course->get( 'capacity_message' ) ), ); // Prerequisite. $data['prerequisite'] = (int) $course->get_prerequisite_id(); // Prerequisite track. $data['prerequisite_track'] = (int) $course->get_prerequisite_id( 'course_track' ); // Length. $data['length'] = array( 'raw' => $course->get( 'length', $raw = true ), 'rendered' => do_shortcode( $course->get( 'length' ) ), ); // Restricted message. $data['restricted_message'] = array( 'raw' => $course->get( 'content_restricted_message', $raw = true ), 'rendered' => do_shortcode( $course->get( 'content_restricted_message' ) ), ); // Access open/closed. $data['access_opens_date'] = $course->get_date( 'start_date', 'Y-m-d H:i:s' ); $data['access_closes_date'] = $course->get_date( 'end_date', 'Y-m-d H:i:s' ); $data['access_opens_message'] = array( 'raw' => $course->get( 'course_opens_message', $raw = true ), 'rendered' => do_shortcode( $course->get( 'course_opens_message' ) ), ); $data['access_closes_message'] = array( 'raw' => $course->get( 'course_closed_message', $raw = true ), 'rendered' => do_shortcode( $course->get( 'course_closed_message' ) ), ); // Enrollment open/closed. $data['enrollment_opens_date'] = $course->get_date( 'enrollment_start_date', 'Y-m-d H:i:s' ); $data['enrollment_closes_date'] = $course->get_date( 'enrollment_end_date', 'Y-m-d H:i:s' ); $data['enrollment_opens_message'] = array( 'raw' => $course->get( 'enrollment_opens_message', $raw = true ), 'rendered' => do_shortcode( $course->get( 'enrollment_opens_message' ) ), ); $data['enrollment_closes_message'] = array( 'raw' => $course->get( 'enrollment_closed_message', $raw = true ), 'rendered' => do_shortcode( $course->get( 'enrollment_closed_message' ) ), ); // Sales page page type. $data['sales_page_type'] = $course->get( 'sales_page_content_type' ); $data['sales_page_type'] = $data['sales_page_type'] ? $data['sales_page_type'] : 'none'; // Sales page id. if ( 'page' === $data['sales_page_type'] || 'edit' === $request['context'] ) { $data['sales_page_page_id'] = $course->get( 'sales_page_content_page_id' ); } // Sales page url. if ( 'url' === $data['sales_page_type'] || 'edit' === $request['context'] ) { $data['sales_page_url'] = $course->get( 'sales_page_content_url' );
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.9 | Fixed sales_page_url not returned in edit context. Added llms_rest_prepare_course_object_response filter hook. |
1.0.0-beta.8 | Fixed sales_page_type not set as none if course's sales_page_content_type property is empty. Also Renamed sales_page_page_type and sales_page_page_url properties, respectively to sales_page_type and sales_page_url according to the specs. Always return sales_page_url and sales_page_page_id when in edit context. |
1.0.0-beta.1 | Introduced. |