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
Return Return
(self)
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;
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.16.0 | Introduced. |