LLMS_Post_Handler::create_lesson( [int] $course_id,  $section_id, string $title = '', string $excerpt = '' )

Creates a new Lesson


Description Description


Parameters Parameters

$course_id

([int]) (Required) [the parent course id]

$title

(string) (Optional) [optional: a title for the lesson]

Default value: ''

$excerpt

(string) (Optional) [optional: a desc for the lesson]

Default value: ''


Top ↑

Return Return

([int]) [post id of lesson]


Top ↑

Source Source

File: includes/class.llms.post.handler.php

	public static function create_lesson( $course_id, $section_id, $title = '', $excerpt = '' ) {

		//no course id or section id? no new lesson!
		if ( ! isset( $course_id ) || ! isset( $course_id ) ) {
			return;
		}

		//set the lesson_order variable
		//get the count of lessons in the section
		$section = new LLMS_Section( $section_id );
		$lesson_order = $section->get_next_available_lesson_order();

		$title = isset( $title ) ? $title : 'New Lesson';

		$post_id = self::create( 'lesson', $title, $excerpt );

		//if post created set parent section, parent course and order determined above
		if ( $post_id ) {
			update_post_meta( $post_id, '_llms_order', $lesson_order );

			$lesson = new LLMS_Lesson( $post_id );
			$updated_parent_section = $lesson->set_parent_section( $section_id );
			$updated_parent_course = $lesson->set_parent_course( $course_id );

		}

		return $post_id;
	}


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: