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_course( array $raw )
Create a new course
Description Description
Parameters Parameters
- $raw
-
(array) (Required) raw course data
Return Return
(void|int)
Source Source
File: includes/class.llms.generator.php
private function create_course( $raw ) { $raw = apply_filters( 'llms_generator_before_new_course', $raw, $this ); $author_id = $this->get_author_id_from_raw( $raw ); if ( isset( $raw['author'] ) ) { unset( $raw['author'] ); } // insert the course $course = new LLMS_Course( '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' => apply_filters( 'llms_generator_course_status', $this->get_default_post_status(), $raw, $this ), 'post_title' => $raw['title'], ) ); if ( ! $course->get( 'id' ) ) { return $this->error->add( 'course_creation', __( 'Error creating course', 'lifterlms' ) ); } $this->increment( 'courses' ); $this->record_generation( $course->get( 'id' ), 'course' ); // save the tempid $tempid = $this->store_temp_id( $raw, $course ); // set all metadata foreach ( array_keys( $course->get_properties() ) as $key ) { if ( isset( $raw[ $key ] ) ) { $course->set( $key, $raw[ $key ] ); } } // add custom meta $this->add_custom_values( $course->get( 'id' ), $raw ); // set featured image if ( isset( $raw['featured_image'] ) ) { $this->set_featured_image( $raw['featured_image'], $course->get( 'id' ) ); } // add terms to our course $terms = array(); if ( isset( $raw['difficulty'] ) ) { $terms['difficulty'] = array( $raw['difficulty'] ); } foreach ( array( 'categories', 'tags', 'tracks' ) as $t ) { if ( isset( $raw[ $t ] ) ) { $terms[ $t ] = $raw[ $t ]; } } $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' ), $author_id ); } } // create all sections if ( isset( $raw['sections'] ) ) { foreach ( $raw['sections'] as $order => $section ) { $this->create_section( $section, $order + 1, $course->get( 'id' ), $author_id ); } } do_action( 'llms_generator_new_course', $course, $raw, $this ); return $course->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. |