LLMS_Question_Choice::set( string $key, mixed $val )

Set a piece of data by key.


Parameters Parameters

$key

(string) (Required) Name of the key to set.

$val

(mixed) (Required) Value to set.


Top ↑

Return Return

(self)


Top ↑

Source Source

File: includes/models/model.llms.question.choice.php

	public function set( $key, $val ) {

		// Don't set the ID.
		if ( 'id' === $key ) {
			return $this;
		}

		switch ( $key ) {

			case 'choice_type':
				if ( ! in_array( $val, array( 'text', 'image' ) ) ) {
					$val = 'text';
				}
				break;

			case 'correct':
				$val = filter_var( $val, FILTER_VALIDATE_BOOLEAN );
				break;

			case 'marker':
				$type = $this->get_question()->get_question_type();
				if ( is_array( $type['choices'] ?? false ) ) {
					$markers = $type['choices']['markers'];
					if ( ! in_array( $val, $markers ) ) {
						$val = $markers[0];
					}
				}
				break;

			case 'choice':
			default:
				if ( is_array( $val ) ) {
					$val = array_map( 'sanitize_text_field', $val );
				} else {
					$val = wp_kses_post( $val );
				}
				break;

		}

		$this->data[ $key ] = $val;
		return $this;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.4.1 Check $type['choices'] is an array before trying to access it as such.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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