LLMS_Generator_Courses::create_lesson( array $raw, int $order, int $section_id, int $course_id, int $fallback_author_id = null )

Create a new lesson


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 is null. When not supplied the fall back will be on the current user ID.

Default value: null


Top ↑

Return Return

(int)


Top ↑

Source Source

File: includes/class-llms-generator-courses.php

	protected function create_lesson( $raw, $order, $section_id, $course_id, $fallback_author_id = null ) {

		/**
		 * Filter raw lesson import data prior to generation
		 *
		 * @since 3.30.2
		 *
		 * @param array          $raw                Raw lesson data array.
		 * @param int            $order              Lesson order within the section (starts at 1).
		 * @param int            $section_id         WP Post ID of the lesson's parent section.
		 * @param int            $course_id          WP Post ID of the lesson's parent course.
		 * @param int            $fallback_author_id Optional author ID to use as a fallback if no raw author data supplied for the lesson.
		 * @param LLMS_Generator $generator          Generator instance.
		 */
		$raw = apply_filters( 'llms_generator_before_new_lesson', $raw, $order, $section_id, $course_id, $fallback_author_id, $this );

		// Force some data.
		$raw['parent_course']  = $course_id;
		$raw['parent_section'] = $section_id;
		$raw['order']          = $order;

		$raw_quiz = ! empty( $raw['quiz'] ) ? $raw['quiz'] : false;
		unset( $raw['quiz'] );

		$lesson = $this->create_post( 'lesson', $raw, $fallback_author_id );

		if ( $raw_quiz ) {
			$raw_quiz['lesson_id'] = $lesson->get( 'id' );
			$lesson->set( 'quiz', $this->create_quiz( $raw_quiz, $lesson->get( 'author' ) ) );
		}

		/**
		 * Action triggered immediately following generation of a new lesson
		 *
		 * @since 3.30.2
		 *
		 * @param LLMS_Lesson    $lesson    Generated lesson object.
		 * @param array          $raw       Original raw lesson data array.
		 * @param LLMS_Generator $generator Generator instance.
		 */
		do_action( 'llms_generator_new_lesson', $lesson, $raw, $this );

		return $lesson->get( 'id' );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Import images and reusable blocks found in the post's content and use create_post() from abstract.
4.3.3 Use an empty string in favor of null for empty post_content and post_excerpt fields.
3.30.2 Added hooks.
3.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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