LLMS_Generator_Courses::create_course( array $raw )

Create a new course


Description Description


Parameters Parameters

$raw

(array) (Required) Raw course data.


Top ↑

Return Return

(int)


Top ↑

Source Source

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

	protected function create_course( $raw ) {

		/**
		 * Filter raw course import data prior to generation
		 *
		 * @since 3.30.2
		 *
		 * @param array          $raw       Raw course data array.
		 * @param LLMS_Generator $generator Generator instance.
		 */
		$raw = apply_filters( 'llms_generator_before_new_course', $raw, $this );

		// Create the course.
		$course = $this->create_post( 'course', $raw, get_current_user_id() );

		// Add terms to our course.
		$terms = array();
		if ( isset( $raw['difficulty'] ) ) {
			$terms['difficulty'] = array( $raw['difficulty'] );
		}
		foreach ( array( 'categories', 'tags', 'tracks' ) as $tax ) {
			if ( isset( $raw[ $tax ] ) ) {
				$terms[ $tax ] = $raw[ $tax ];
			}
		}
		$this->add_course_terms( $course->get( 'id' ), $terms );

		// Create all access plans.
		if ( isset( $raw['access_plans'] ) ) {
			foreach ( $raw['access_plans'] as $plan ) {
				$this->create_access_plan( $plan, $course->get( 'id' ), $course->get( 'author' ) );
			}
		}

		// Create all sections.
		if ( isset( $raw['sections'] ) ) {
			foreach ( $raw['sections'] as $order => $section ) {
				$this->create_section( $section, ++$order, $course->get( 'id' ), $course->get( 'author' ) );
			}
		}

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

		return $course->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.