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_question( array $raw,  $manager, int $author_id )

Creates a new question


Description Description


Parameters Parameters

$raw

(array) (Required) raw question data

$author_id

(int) (Optional) author ID to use as a fallback if no raw author data supplied for the lesson


Top ↑

Return Return

(int) WP Post ID of the question


Top ↑

Source Source

File: includes/class.llms.generator.php

	private function create_question( $raw, $manager, $author_id ) {

		$raw = apply_filters( 'llms_generator_before_new_question', $raw, $manager, $author_id, $this );

		unset( $raw['parent_id'] );

		$question_id = $manager->create_question( array_merge( array(
			'post_status' => 'publish',
			'post_author' => $author_id,
		), $raw ) );

		if ( ! $question_id ) {
			return $this->error->add( 'question_creation', __( 'Error creating question', 'lifterlms' ) );
		}

		$this->increment( 'questions' );

		$question = llms_get_post( $question_id );

		if ( isset( $raw['choices'] ) ) {
			foreach ( $raw['choices'] as $choice ) {
				unset( $choice['question_id'] );
				$question->create_choice( $choice );
			}
		}

		// set all metadata
		foreach ( array_keys( $question->get_properties() ) as $key ) {
			if ( isset( $raw[ $key ] ) ) {
				$question->set( $key, $raw[ $key ] );
			}
		}

		do_action( 'llms_generator_new_question', $question, $raw, $manager, $this );

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

	}

Top ↑

Changelog Changelog

Changelog
Version Description
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.





Permalink: