LLMS_REST_Lessons_Controller::prepare_object_for_response( LLMS_Lesson $lesson, WP_REST_Request $request )
Prepare a single object output for response.
Parameters Parameters
- $lesson
-
(LLMS_Lesson) (Required) Lesson 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-lessons-controller.php
* public, points, quiz, drip_method, drip_days, drip_date, prerequisite, audio_embed, video_embed. * Added `llms_rest_prepare_lesson_object_response` filter hook. * * @param LLMS_Lesson $lesson Lesson object. * @param WP_REST_Request $request Full details about the request. * @return array */ protected function prepare_object_for_response( $lesson, $request ) { $data = parent::prepare_object_for_response( $lesson, $request ); // Audio Embed. $data['audio_embed'] = $lesson->get( 'audio_embed' ); // Video Embed. $data['video_embed'] = $lesson->get( 'video_embed' ); // Parent section. $data['parent_id'] = $lesson->get_parent_section(); // Parent course. $data['course_id'] = $lesson->get( 'parent_course' ); // Order. $data['order'] = $lesson->get( 'order' ); // Public. $data['public'] = $lesson->is_free(); // Points. $data['points'] = $lesson->get( 'points' ); // Quiz. $data['quiz']['enabled'] = llms_parse_bool( $lesson->get( 'quiz_enabled' ) ); $data['quiz']['id'] = absint( $lesson->get( 'quiz' ) ); $data['quiz']['progression'] = llms_parse_bool( $lesson->get( 'require_passing_grade' ) ) ? 'pass' : 'completed'; // Drip method. $data['drip_method'] = $lesson->get( 'drip_method' ); $data['drip_method'] = $data['drip_method'] ? $data['drip_method'] : 'none'; // Drip days. $data['drip_days'] = absint( $lesson->get( 'days_before_available' ) ); // Drip date. $date = $lesson->get( 'date_available' ); if ( $date ) { $time = $lesson->get( 'time_available' ); if ( ! $time ) { $time = '12:00 AM'; } $drip_date = date_i18n( 'Y-m-d H:i:s', strtotime( $date . ' ' . $time ) ); } else { $drip_date = ''; } $data['drip_date'] = $drip_date; // Prerequisite. $data['prerequisite'] = absint( $lesson->get_prerequisite() ); /** * Filters the lesson data for a response. * * @since 1.0.0-beta.7 *
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.7 | Added following properties to the response object: public, points, quiz, drip_method, drip_days, drip_date, prerequisite, audio_embed, video_embed. Added llms_rest_prepare_lesson_object_response filter hook. |
1.0.0-beta.23 | Replaced the call to the deprecated LLMS_Lesson::get_parent_course() method with LLMS_Lesson::get( 'parent_course' ) . |
1.0.0-beta.1 | Introduced. |