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_quiz( array $raw, int $fallback_author_id = null )
Creates a new quiz Creates all questions within the quiz as well
Description Description
Parameters Parameters
- $raw
-
(array) (Required) raw quiz data
- $fallback_author_id
-
(int) (Optional) author ID to use as a fallback if no raw author data supplied for the lesson
Default value: null
Return Return
(int) WP Post ID of the Quiz
Source Source
File: includes/class.llms.generator.php
private function create_quiz( $raw, $fallback_author_id = null ) { $raw = apply_filters( 'llms_generator_before_new_quiz', $raw, $fallback_author_id, $this ); $author_id = $this->get_author_id_from_raw( $raw, $fallback_author_id ); if ( isset( $raw['author'] ) ) { unset( $raw['author'] ); } // insert the course $quiz = new LLMS_Quiz( '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_modified' => isset( $raw['modified'] ) ? $this->format_date( $raw['modified'] ) : null, 'post_status' => isset( $raw['status'] ) ? $raw['status'] : $this->get_default_post_status(), 'post_title' => $raw['title'], ) ); if ( ! $quiz->get( 'id' ) ) { return $this->error->add( 'quiz_creation', __( 'Error creating quiz', 'lifterlms' ) ); } $this->increment( 'quizzes' ); // set all metadata foreach ( array_keys( $quiz->get_properties() ) as $key ) { if ( isset( $raw[ $key ] ) ) { $quiz->set( $key, $raw[ $key ] ); } } if ( isset( $raw['questions'] ) ) { $manager = $quiz->questions(); foreach ( $raw['questions'] as $question ) { $this->create_question( $question, $manager, $author_id ); } } // add custom meta $this->add_custom_values( $quiz->get( 'id' ), $raw ); do_action( 'llms_generator_new_quiz', $quiz, $raw, $this ); return $quiz->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. |
User Contributed Notes User Contributed Notes
Permalink: