set( 'legend', $attr['legend'] ); unset( $attr['legend'] ); } return \sprintf( '
%s%s%s
', $this->legend(), $this->renderOptions( $attr ), $this->description() ); } protected function renderOptions( array $attr ) { if ( ! isset( $attr['options'] ) ) { $attr['options'] = []; } if ( isset( $attr['show_option_none'] ) ) { $none = \is_string( $attr['show_option_none'] ) ? $attr['show_option_none'] : __( 'None', 'italystrap' ) ; $attr['options'] = [ $none ] + $attr['options']; } $html = ''; foreach ( (array) $attr['options'] as $value => $option ) { $new_attr = \array_merge( $attr, [ 'id' => $attr['id'] . '_' . $value, 'value' => $value, 'checked' => $this->isChecked( $value, $attr['value'], $attr ), ] ); $this->set( 'label', $option ); $this->set( 'id', $new_attr['id'] ); unset( $new_attr['options'] ); $html .= \sprintf( '

%s

', HTML\get_attr( 'input', $new_attr ), $this->label() ); } return $html; } /** * @param int|string $needle * @param int|string|array $haystack * @param array $attr * * @return bool|string */ protected function isChecked( $needle, $haystack, array $attr ) { return $needle == $haystack; // if ( $needle == $haystack ) { // return 'checked'; // } // // return false; } }