LLMS_Generator_Courses::create_question( array $raw, obj $manager, int $author_id )
Creates a new question
Parameters Parameters
- $raw
-
(array) (Required) Raw question data.
- $manager
-
(obj) (Required) Question manager instance.
- $author_id
-
(int) (Optional) Author ID to use as a fallback if no raw author data supplied for the question. Default is
null.<br> When not supplied the fall back will be on the current user ID.
Return Return
(int)
Source Source
File: includes/class-llms-generator-courses.php
protected function create_question( $raw, $manager, $author_id ) {
/**
* Filter raw question import data prior to generation
*
* @since 3.30.2
*
* @param array $raw Raw quiz data array.
* @param obj $manager Question manager instance.
* @param int $author_id Optional author ID to use as a fallback if no raw author data supplied for the question.
* @param LLMS_Generator $generator Generator instance.
*/
$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 ) {
throw new Exception( esc_attr__( 'Error creating the question post object.', 'lifterlms' ), intval( self::ERROR_CREATE_POST ) );
}
$question = llms_get_post( $question_id );
$this->store_temp_id( $raw, $question );
if ( isset( $raw['choices'] ) ) {
foreach ( $raw['choices'] as $choice ) {
unset( $choice['question_id'] );
$question->create_choice( $this->maybe_sideload_choice_image( $choice, $question_id ) );
}
}
// Set all metadata.
foreach ( array_keys( $question->get_properties() ) as $key ) {
if ( isset( $raw[ $key ] ) ) {
$question->set( $key, $raw[ $key ] );
}
}
$this->sideload_images( $question, $raw );
/**
* Action triggered immediately following generation of a new question
*
* @since 3.30.2
*
* @param LLMS_Question $question Generated question object.
* @param array $raw Original raw question data array.
* @param obj $manager Question manager instance.
* @param LLMS_Generator $generator Generator instance.
*/
do_action( 'llms_generator_new_question', $question, $raw, $manager, $this );
return $question->get( 'id' );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Attempt to sideload images found in the imported post's content and image choices. |
| 3.30.2 | Added hooks. |
| 3.3.0 | Introduced. |