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;


Top ↑

Changelog Changelog

Changelog
Version Description
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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