= 1 && $count <= 6 ? $count : 6; $attr['multiple'] = true; } $attr['type'] = 'select'; $options = $attr; unset( $attr['options'] ); unset( $attr['value'] ); unset( $attr['show_option_none'] ); return sprintf( '%s%s%s', $this->label(), HTML\get_attr( 'input', $attr ), $this->render_options( $options ), $this->description() ); } protected function render_options( array $attr ) { 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 ) { $html .= sprintf( '%s', HTML\get_attr( 'option', [ 'value' => $value, 'selected' => $this->is_selected( $value, $attr['value'], $attr ), ] ), esc_html( $option ) ); } return $html; } /** * @param int|string $needle * @param int|string|array $haystack * @param array $attr * * @return bool|string */ protected function is_selected( $needle, $haystack, array $attr ) { if ( is_array( $haystack ) && in_array( $needle, $haystack, true ) || $needle == $haystack ) { return 'selected'; } return false; } protected function is_multiple(array $attr) { return isset( $attr['multiple'] ) || isset( $attr['attributes']['multiple'] ); } /** * Create the Field Select with Options Group * * @TODO * * @access public * @param array $key The key of field's array to create the HTML field. * @param string $out The HTML form output. * @return string Return the HTML Field Select with Options Group */ private function select_group(array $key, $out = '' ) { $out .= $this->label( $key['name'], $key['_id'] ); $out .= ''; if ( isset( $key['desc'] ) ) { $out .= $this->description( $key['desc'] ); } return $out; } }