LLMS_Post_Handler::create_section( [int] $course_id, string $title = '' )

Creates a new Section


Description Description


Parameters Parameters

$course_id

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

$title

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

Default value: ''


Top ↑

Return Return

([int]) [post id of section]


Top ↑

Source Source

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

	public static function create_section( $course_id, $title = '' ) {

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

		//set the section_order variable
		//get the count of sections in the course and add 1
		$course = new LLMS_Course( $course_id );
		$sections = $course->get_sections( 'posts' );
		$section_order = count( $sections ) + 1;

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

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

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

			$section = new LLMS_Section( $post_id );
			$updated_parent_course = $section->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: