LLMS_Form_Field::prepare_options( array $raw )
Prepare the fields options.
Description Description
Allows options to be setup as an associative array of key/value pairs or an array of associative arrays each with a "label" and "key" property. The "key" property may be omitted, in which case the "label" will be duplicated as the option’s "value".
Parameters Parameters
- $raw
-
(array) (Required) Raw field data.
Return Return
(array)
Source Source
File: includes/forms/class-llms-form-field.php
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | protected function prepare_options( $raw ) { $prepared = array (); foreach ( $raw as $key => $val ) { if ( is_array ( $val ) ) { // Option group. if ( isset( $val [ 'options' ] ) ) { $prepared [ $key ] = array ( 'label' => isset( $val [ 'label' ] ) ? $val [ 'label' ] : $key , 'options' => $this ->prepare_options( $val [ 'options' ] ), ); // From block editor options array. } elseif ( isset( $val [ 'text' ] ) ) { $item_key = isset( $val [ 'key' ] ) ? $val [ 'key' ] : $val [ 'text' ]; $prepared [ $item_key ] = $val [ 'text' ]; if ( isset( $val [ 'default' ] ) && llms_parse_bool( $val [ 'default' ] ) ) { if ( 'checkbox' === $this ->settings[ 'type' ] ) { // Account for multiple defaults. $this ->settings[ 'default' ] = is_array ( $this ->settings[ 'default' ] ) ? $this ->settings[ 'default' ] : array (); $this ->settings[ 'default' ][] = $item_key ; } else { $this ->settings[ 'default' ] = $item_key ; } } } // Flat array of $key=>$val. } else { $prepared [ $key ] = $val ; } } // Add a placeholder. if ( $this ->settings[ 'placeholder' ] ) { $this ->settings[ 'default' ] = '' ; $prepared = array_merge ( array ( '' => $this ->settings[ 'placeholder' ] ), $prepared ); } return $prepared ; } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |