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_Admin_Builder::update_quiz( array $quiz_data, LLMS_Lesson $lesson )

Update quizzes during heartbeats


Parameters Parameters

$quiz_data

(array) (Required) Array of quiz updates.

$lesson

(LLMS_Lesson) (Required) Instance of the parent LLMS_Lesson.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/class.llms.admin.builder.php

					}
				} elseif ( $questions ) {

					$ret['questions'] = self::update_questions( $questions, $question );

				}
			}

			array_push( $res, $ret );

		}

		return $res;

	}

	/**
	 * Update quizzes during heartbeats
	 *
	 * @since 3.16.0
	 * @since 3.17.6 Unknown.
	 *
	 * @param array       $quiz_data Array of quiz updates.
	 * @param LLMS_Lesson $lesson    Instance of the parent LLMS_Lesson.
	 * @return array
	 */
	private static function update_quiz( $quiz_data, $lesson ) {

		$res = array_merge(
			$quiz_data,
			array(
				'orig_id' => $quiz_data['id'],
			)
		);

		// Create a quiz.
		if ( self::is_temp_id( $quiz_data['id'] ) ) {

			$quiz = new LLMS_Quiz( 'new' );

			// Update existing quiz.
		} else {

			$quiz = llms_get_post( $quiz_data['id'] );

		}

		$lesson->set( 'quiz', $quiz->get( 'id' ) );
		$lesson->set( 'quiz_enabled', 'yes' );

		// We don't have a proper quiz to work with...
		if ( empty( $quiz ) || ! is_a( $quiz, 'LLMS_Quiz' ) ) {

			// Translators: %s = Quiz post id.
			$res['error'] = sprintf( esc_html__( 'Unable to update quiz "%s". Invalid quiz ID.', 'lifterlms' ), $quiz_data['id'] );

		} else {

			// Return the real ID (important when creating a new quiz).
			$res['id'] = $quiz->get( 'id' );

			/**
			 * If the parent lesson was just created the lesson will have a temp id
			 * replace it with the newly created lessons's real ID.
			 */
			if ( ! isset( $quiz_data['lesson_id'] ) || self::is_temp_id( $quiz_data['lesson_id'] ) ) {
				$quiz_data['lesson_id'] = $lesson->get( 'id' );
			}

			$properties = array_merge(
				array_keys( $quiz->get_properties() ),


Top ↑

Changelog Changelog

Changelog
Version Description
3.17.6 Unknown.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.