LLMS_Form_Field::explode_options_to_fields( string $is_hidden = false )
Returns an array of form field objects from this checkbox or radio field’s options array.
Parameters Parameters
- $is_hidden
-
(string) (Optional) If true, returns only the checked fields and sets their type to 'hidden', else returns all options as
$this->settings['type']form fields.Default value: false
Return Return
(LLMS_Form_Field[])
Source Source
File: includes/forms/class-llms-form-field.php
public function explode_options_to_fields( $is_hidden = false ) {
$fields = array();
$value = ! empty( $this->settings['value'] ) || is_array( $this->settings['value'] )
? $this->settings['value']
: $this->settings['default'];
foreach ( $this->settings['options'] as $key => $val ) {
$name = $this->settings['name'];
$checked = $value === $key;
if ( 'checkbox' === $this->settings['type'] ) {
$name .= '[]';
$value = is_array( $value ) ? $value : array( $value );
$checked = in_array( $key, $value, true );
}
if ( $is_hidden && ! $checked ) {
continue;
}
$fields[] = new self(
array(
'data_store' => false,
'id' => sprintf( '%1$s--%2$s', $this->settings['id'], $key ),
'name' => $name,
'value' => $key,
'label' => $val,
'checked' => $checked,
'type' => $is_hidden ? 'hidden' : $this->settings['type'],
)
);
}
return $fields;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 6.2.0 | Introduced. |