# learnpress/4.4.0/inc/question/class-lp-question-single-choice.php

LearnPress – WordPress LMS Plugin for Create and Sell Online Courses, version 4.4.0. 69 lines.

- Page: https://pluginprobe.com/plugins/learnpress/4.4.0/code/inc/question/class-lp-question-single-choice.php
- Raw: https://pluginprobe.com/plugins/learnpress/4.4.0/raw/inc/question/class-lp-question-single-choice.php
- Modified: 2024-08-10T07:01:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/learnpress/4.4.0/code/inc/question/class-lp-question-single-choice.php#L10-L20`.

```php
<?php
/**
 * LP_Question_Single_Choice
 *
 * @author  ThimPress
 * @package LearnPress/Templates
 * @version 3.0.0
 * @extends LP_Question
 */

/**
 * Prevent loading this file directly
 */
defined( 'ABSPATH' ) || exit();

if ( ! class_exists( 'LP_Question_Single_Choice' ) ) {

	/**
	 * Class LP_Question_Single_Choice
	 */
	class LP_Question_Single_Choice extends LP_Question {

		/**
		 * Type of this question.
		 *
		 * @var string
		 */
		protected $_question_type = 'single_choice';

		/**
		 * LP_Question_Single_Choice constructor.
		 *
		 * @param null $the_question
		 * @param null $args
		 *
		 * @throws Exception
		 */
		public function __construct( $the_question = null, $args = null ) {
			parent::__construct( $the_question, $args );

		}

		/**
		 * Check user answer.
		 *
		 * @param null $user_answer
		 *
		 * @return array
		 */
		public function check( $user_answer = null ) {
			$return  = parent::check();
			$answers = $this->get_answers();

			if ( $answers ) {
				foreach ( $answers as $key => $option ) {
					$data = $option->get_data();
					if ( ( $data['is_true'] == 'yes' ) && ( $this->is_selected_option( $data, $user_answer ) ) ) {
						$return['correct'] = true;
						$return['mark']    = floatval( $this->get_mark() );
						break;
					}
				}
			}

			return $return;
		}
	}
}

```
