Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Generator::create_lesson( array $raw, int $order, int $section_id, int $course_id, int $fallback_author_id = null )
Create a new lesson
Description Description
Parameters Parameters
- $raw
-
(array) (Required) raw lesson data
- $order
-
(int) (Required) lesson order within the section (starts at 1)
- $section_id
-
(int) (Required) WP Post ID of the lesson's parent section
- $course_id
-
(int) (Required) WP Post ID of the lesson's parent course
- $fallback_author_id
-
(int) (Optional) author ID to use as a fallback if no raw author data supplied for the lesson
Default value: null
Return Return
(mixed) lesson id or WP_Error
Source Source
File: includes/class.llms.generator.php
private function create_lesson( $raw, $order, $section_id, $course_id, $fallback_author_id = null ) { $raw = apply_filters( 'llms_generator_before_new_lesson', $raw, $order, $section_id, $course_id, $fallback_author_id, $this ); $author_id = $this->get_author_id_from_raw( $raw, $fallback_author_id ); if ( isset( $raw['author'] ) ) { unset( $raw['author'] ); } // insert the course $lesson = new LLMS_lesson( 'new', array( 'post_author' => $author_id, 'post_content' => isset( $raw['content'] ) ? $raw['content'] : null, 'post_date' => isset( $raw['date'] ) ? $this->format_date( $raw['date'] ) : null, 'post_excerpt' => isset( $raw['excerpt'] ) ? $raw['excerpt'] : null, 'post_modified' => isset( $raw['modified'] ) ? $this->format_date( $raw['modified'] ) : null, 'post_status' => isset( $raw['status'] ) ? $raw['status'] : $this->get_default_post_status(), 'post_title' => $raw['title'], ) ); if ( ! $lesson->get( 'id' ) ) { return $this->error->add( 'lesson_creation', __( 'Error creating lesson', 'lifterlms' ) ); } $this->increment( 'lessons' ); $this->record_generation( $lesson->get( 'id' ), 'lesson' ); // save the tempid $tempid = $this->store_temp_id( $raw, $lesson ); // set featured image if ( isset( $raw['featured_image'] ) ) { $this->set_featured_image( $raw['featured_image'], $lesson->get( 'id' ) ); } $lesson->set( 'parent_course', $course_id ); $lesson->set( 'parent_section', $section_id ); $lesson->set( 'order', $order ); // cant trust these if they exist if ( isset( $raw['parent_course'] ) ) { unset( $raw['parent_course'] ); } if ( isset( $raw['parent_section'] ) ) { unset( $raw['parent_section'] ); } if ( ! empty( $raw['quiz'] ) ) { $raw['quiz']['lesson_id'] = $lesson->get( 'id' ); $raw['quiz'] = $this->create_quiz( $raw['quiz'], $author_id ); } // set all metadata foreach ( array_keys( $lesson->get_properties() ) as $key ) { if ( isset( $raw[ $key ] ) ) { $lesson->set( $key, $raw[ $key ] ); } } // add custom meta $this->add_custom_values( $lesson->get( 'id' ), $raw ); do_action( 'llms_generator_new_lesson', $lesson, $raw, $this ); return $lesson->get( 'id' ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.30.2 | Added hooks. |
3.3.0 | Introduced. |