LLMS_Generator_Courses::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 quiz. Default is null. When not supplied the fall back will be on the current user ID.

Default value: null


Top ↑

Return Return

(int)


Top ↑

Source Source

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

	protected function create_quiz( $raw, $fallback_author_id = null ) {

		/**
		 * Filter raw quiz import data prior to generation
		 *
		 * @since 3.30.2
		 *
		 * @param array          $raw                Raw quiz data array.
		 * @param int            $fallback_author_id Optional author ID to use as a fallback if no raw author data supplied for the quiz.
		 * @param LLMS_Generator $generator          Generator instance.
		 */
		$raw = apply_filters( 'llms_generator_before_new_quiz', $raw, $fallback_author_id, $this );

		$quiz = $this->create_post( 'quiz', $raw, $fallback_author_id );

		if ( isset( $raw['questions'] ) ) {
			$manager = $quiz->questions();
			foreach ( $raw['questions'] as $question ) {
				$this->create_question( $question, $manager, $quiz->get( 'author' ) );
			}
		}

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

		return $quiz->get( 'id' );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Sideload images attached to the post and use create_post() from abstract.
4.3.3 Use an empty string in favor of null for an empty post_content field.
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.