LLMS_Metabox_Select_Field::output()
Outputs the Html for the given field.
Return Return
(void)
Source Source
File: includes/admin/post-types/meta-boxes/fields/llms.class.meta.box.select.php
public function output() {
global $post;
parent::output();
$name = $this->field['id'];
$allow_null = ( isset( $this->field['allow_null'] ) ) ? $this->field['allow_null'] : true;
if ( array_key_exists( 'multi', $this->field ) ) {
$name .= '[]';
}
$selected = $this->meta;
if ( array_key_exists( 'selected', $this->field ) ) {
$selected = $this->field['selected'];
}
$attrs = isset( $this->field['data_attributes'] ) ? $this->field['data_attributes'] : array();
?>
<select
<?php echo isset( $this->field['is_controller'] ) ? 'data-is-controller="true"' : ''; ?>
id="<?php echo esc_attr( $this->field['id'] ); ?>"
name="<?php echo esc_attr( $name ); ?>"
<?php if ( ! empty( $this->field['required'] ) && ! $allow_null ) : ?>
required="required"
<?php endif; ?>
class="<?php echo esc_attr( $this->field['class'] ); ?>"
<?php if ( array_key_exists( 'multi', $this->field ) && $this->field['multi'] ) : ?>
multiple="multiple"
<?php endif; ?>
<?php
foreach ( $attrs as $attr => $attr_val ) {
echo ' data-' . esc_attr( $attr ) . '="' . esc_attr( $attr_val ) . '"'; }
?>
>
<?php if ( $allow_null ) : ?>
<option value="">None</option>
<?php endif; ?>
<?php if ( isset( $this->field['value'] ) ) : ?>
<?php
foreach ( $this->field['value'] as $key => $option ) :
$is_selected = false;
if ( is_array( $selected ) ) {
if ( in_array( $option['key'], $selected ) ) {
$is_selected = true;
}
} elseif ( isset( $option['key'] ) && $option['key'] == $selected ) {
$is_selected = true;
} elseif ( $key === $selected ) {
$is_selected = true;
}
?>
<option value="<?php echo isset( $option['key'] ) ? esc_attr( $option['key'] ) : esc_attr( $key ); ?>"<?php echo ( $is_selected ? ' selected="selected"' : '' ); ?>><?php echo isset( $option['title'] ) ? esc_html( $option['title'] ) : esc_html( $option ); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<?php
parent::close_output();
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 6.0.0 | Added required attribute when required :D. |
| 3.1.0 | Allow regular key=>val arrays to be passed. |
| 1.0.0 | Introduced. |